• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wurstscript / WurstScript / 259

27 Jun 2025 02:54PM UTC coverage: 62.224% (-0.007%) from 62.231%
259

push

circleci

Frotty
Allow game exe override

Supports specifying a specific file that will be run for the runmap commands, overriding other config

17261 of 27740 relevant lines covered (62.22%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/WurstCommands.java
1
package de.peeeq.wurstio.languageserver;
2

3
import com.google.common.base.Charsets;
4
import com.google.common.collect.ImmutableList;
5
import com.google.gson.JsonElement;
6
import com.google.gson.JsonObject;
7
import de.peeeq.wurstio.languageserver.requests.*;
8
import de.peeeq.wurstscript.WLogger;
9
import org.eclipse.lsp4j.ExecuteCommandParams;
10

11
import java.io.File;
12
import java.io.IOException;
13
import java.nio.file.Files;
14
import java.nio.file.Path;
15
import java.nio.file.Paths;
16
import java.util.List;
17
import java.util.Optional;
18
import java.util.concurrent.CompletableFuture;
19
import java.util.stream.Collectors;
20
import java.util.stream.Stream;
21

22
/**
23
 *
24
 */
25
public class WurstCommands {
×
26

27
    public static final String WURST_RESTART = "wurst.restart";
28
    public static final String WURST_CLEAN = "wurst.clean";
29
    public static final String WURST_STARTMAP = "wurst.startmap";
30
    public static final String WURST_HOTSTARTMAP = "wurst.hotstartmap";
31
    public static final String WURST_HOTRELOAD = "wurst.hotreload";
32
    public static final String WURST_BUILDMAP = "wurst.buildmap";
33
    public static final String WURST_STARTLAST = "wurst.startlast";
34
    public static final String WURST_TESTS = "wurst.tests";
35
    public static final String WURST_TESTS_FILE = "wurst.tests_file";
36
    public static final String WURST_TESTS_FUNC = "wurst.tests_func";
37
    public static final String WURST_PERFORM_CODE_ACTION = "wurst.perform_code_action";
38

39
    static List<String> providedCommands() {
40
        return List.of(
×
41
                WURST_CLEAN
42
        );
43
    }
44

45
    public static CompletableFuture<Object> execute(WurstLanguageServer server, ExecuteCommandParams params) {
46
        switch (params.getCommand()) {
×
47
            case WURST_CLEAN:
48
                return server.worker().handle(new CleanProject()).thenApply(x -> x);
×
49
            case WURST_STARTMAP:
50
                return startMap(server, params);
×
51
            case WURST_HOTSTARTMAP:
52
                return startMap(server, params, "-hotstart");
×
53
            case WURST_HOTRELOAD:
54
                return startMap(server, params, "-hotreload");
×
55
            case WURST_TESTS:
56
                return testMap(server, params);
×
57
            case WURST_PERFORM_CODE_ACTION:
58
                return server.worker().handle(new PerformCodeActionRequest(server, params));
×
59
            case WURST_BUILDMAP:
60
                return buildMap(server, params);
×
61
        }
62
        WLogger.info("unhandled command: " + params.getCommand());
×
63
        throw new RuntimeException("unhandled command: " + params.getCommand());
×
64
    }
65

66

67
    private static CompletableFuture<Object> testMap(WurstLanguageServer server, ExecuteCommandParams params) {
68
        JsonObject options = (JsonObject) params.getArguments().get(0);
×
69
        Optional<String> filename = getString(options, "filename");
×
70
        int line = options.has("line") ? options.get("line").getAsInt() : -1;
×
71
        int column = options.has("column") ? options.get("column").getAsInt() : -1;
×
72
        int testTimeout = options.has("testTimeout") ? options.get("testTimeout").getAsInt() : 20;
×
73
        Optional<String> testName = getString(options, "testName");
×
74

75
        return server.worker().handle(new RunTests(filename, line, column, testName, testTimeout));
×
76
    }
77

78
    private static CompletableFuture<Object> buildMap(WurstLanguageServer server, ExecuteCommandParams params) {
79
        WFile workspaceRoot = server.getRootUri();
×
80
        if (params.getArguments().isEmpty()) {
×
81
            throw new RuntimeException("Missing arguments");
×
82
        }
83
        JsonObject options = (JsonObject) params.getArguments().get(0);
×
84
        Optional<String> mapPath = getString(options, "mappath");
×
85
        Optional<String> wc3Path = getString(options, "wc3path");
×
86
        if (!mapPath.isPresent()) {
×
87
            throw new RuntimeException("No mappath given");
×
88
        }
89

90
        Optional<File> map = mapPath.map(File::new);
×
91
        List<String> compileArgs = getCompileArgs(workspaceRoot);
×
92
        return server.worker().handle(new BuildMap(server, workspaceRoot, wc3Path, map, compileArgs)).thenApply(x -> x);
×
93
    }
94

95
    private static CompletableFuture<Object> startMap(WurstLanguageServer server, ExecuteCommandParams params, String... additionalArgs) {
96
        WFile workspaceRoot = server.getRootUri();
×
97
        if (params.getArguments().isEmpty()) {
×
98
            throw new RuntimeException("Missing arguments");
×
99
        }
100
        JsonObject options = (JsonObject) params.getArguments().get(0);
×
101
        Optional<String> mapPath = getString(options,  "mappath");
×
102
        Optional<String> wc3Path = getString(options, "wc3path");
×
103
        Optional<String> gameExePath = getString(options, "gameExePath");
×
104

105
        Optional<File> map = mapPath.map(File::new);
×
106
        List<String> compileArgs = getCompileArgs(workspaceRoot, additionalArgs);
×
107
        return server.worker().handle(new RunMap(server, workspaceRoot, wc3Path, map, compileArgs, gameExePath)).thenApply(x -> x);
×
108
    }
109

110
    private static Optional<String> getString(JsonObject options, String key) {
111
        try {
112
            return Optional.ofNullable(options.get(key)).map(JsonElement::getAsString);
×
113
        } catch (ClassCastException | IllegalStateException e) {
×
114
            WLogger.warning("Invalid configuration", e);
×
115
            return Optional.empty();
×
116
        }
117
    }
118

119
    private static final List<String> defaultArgs = ImmutableList.of("-runcompiletimefunctions", "-injectobjects", "-stacktraces");
×
120

121
    public static List<String> getCompileArgs(WFile rootPath, String... additionalArgs) {
122
        try {
123
            Path configFile = Paths.get(rootPath.toString(), "wurst_run.args");
×
124
            if (Files.exists(configFile)) {
×
125
                try (Stream<String> lines = Files.lines(configFile)) {
×
126
                    return Stream.concat(
×
127
                        lines.filter(s -> s.startsWith("-")),
×
128
                        Stream.of(additionalArgs)
×
129
                    ).collect(Collectors.toList());
×
130
                }
131
            } else {
132

133
                String cfg = String.join("\n", defaultArgs) + "\n";
×
134
                Files.write(configFile, cfg.getBytes(Charsets.UTF_8));
×
135
                return defaultArgs;
×
136
            }
137
        } catch (IOException e) {
×
138
            throw new RuntimeException("Could not access wurst_run.args config file", e);
×
139
        }
140
    }
141

142
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc