Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ public void handleException(LanguageClient languageClient, Throwable err, Comple
return;
}
if (workDoneToken != null && !(err instanceof RequestFailedException rfe && rfe.getMessageType() == MessageType.Info)) {
// The requesting editor owns the failure notification for this progress operation.
resFut.completeExceptionally(err);
// The requesting editor owns the failure notification for this progress operation. lsp4j answers any
// other exception with "Internal error.", so a failure the request reports carries its own text.
resFut.completeExceptionally(err instanceof RequestFailedException failure
? new ResponseErrorException(new ResponseError(ResponseErrorCode.RequestFailed, failure.getMessage(), null))
: err);
} else if (err instanceof RequestFailedException rfe) {
languageClient.showMessage(new MessageParams(rfe.getMessageType(), rfe.getMessage()));
resFut.complete(new Object());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import org.eclipse.lsp4j.WorkDoneProgressBegin;
import org.eclipse.lsp4j.WorkDoneProgressReport;
import org.eclipse.lsp4j.WorkDoneProgressEnd;
import org.eclipse.lsp4j.jsonrpc.RemoteEndpoint;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
import org.eclipse.lsp4j.services.LanguageClient;
import org.testng.annotations.Test;

Expand All @@ -32,6 +34,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

import static org.testng.Assert.*;

Expand Down Expand Up @@ -117,18 +120,37 @@ public void tokenRequestsLetEditorPresentFailuresAndPreserveInformationalMessage
request.handleException(client, error, editor);
assertTrue(editor.isCompletedExceptionally());
assertEquals(messages.size(), 1, "the editor must receive only one failure notification");
assertEquals(responseErrorOf(editor).getMessage(), "Build failed",
"the editor must receive the failure's text, not lsp4j's \"Internal error.\"");

CompletableFuture<Object> warningFailure = new CompletableFuture<>();
request.handleException(client, new RequestFailedException(MessageType.Warning, "On-disk compilation failed"), warningFailure);
assertTrue(warningFailure.isCompletedExceptionally(), "a warning-level failure must not report a successful build");
assertEquals(messages.size(), 1, "the editor owns the failure notification");
assertEquals(responseErrorOf(warningFailure).getMessage(), "On-disk compilation failed");

String refusal = "The edit cannot be hot reloaded, rebuild and restart the map:\n function f: its parameters changed";
CompletableFuture<Object> refusedReload = new CompletableFuture<>();
request.handleException(client, new RequestFailedException(MessageType.Warning, refusal), refusedReload);
assertEquals(responseErrorOf(refusedReload).getMessage(), refusal, "every reason of a refused hot reload reaches the editor");
assertEquals(messages.size(), 1);

CompletableFuture<Object> cancelled = new CompletableFuture<>();
request.handleException(client, new RequestFailedException(MessageType.Info, "Run canceled."), cancelled);
assertFalse(cancelled.isCompletedExceptionally());
assertEquals(messages.get(1).getType(), MessageType.Info);
}

/** The error lsp4j sends the client for a request which completed with the future's failure. */
private static ResponseError responseErrorOf(CompletableFuture<Object> future) {
try {
future.join();
} catch (CompletionException e) {
return RemoteEndpoint.DEFAULT_EXCEPTION_HANDLER.apply(e.getCause());
}
throw new AssertionError("the request did not fail");
}

@Test
public void editorProgressUsesRequestTokenAndEndsOnlyOnce() throws Exception {
Path project = Files.createTempDirectory("wurst-lsp-progress");
Expand Down
14 changes: 11 additions & 3 deletions docs/LUA_HOT_RELOAD.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ Editor side (implemented, `LuaHotReloadSession`, `RunMap`):
2. `wurst.hotreload` sends `-hotreload`. For a Lua project, `RunMap` compiles the project, builds the next cumulative
payload against the saved baseline and writes payload n to `CustomMapData\Wurst\hotreload-<n>.pld`
(`customMapDataPath` in the configuration overrides the folder). A hot run deletes the files of earlier sessions. JHCR stays the path for Jass maps. A rejected edit fails the request
with the reasons. While a hot run is active, the VS Code extension sends it on every save of a Wurst file.
with the reasons as its error message; the VS Code extension shows the first line and writes the rest to its
output. While a hot run is active, the VS Code extension sends it on every save of a Wurst file.

Without the editor, a map built with `-build ... -luaHotReload` (with run arguments: `-luaHotReload` refuses `-inline`
and `-opt`) starts a session and takes payloads from the compiler's command line, which is how the in-game test drives
Expand Down Expand Up @@ -435,8 +436,15 @@ all of it the build, which #1553 made three times faster. The run found that a m
`InitBlizzard`, as Castle Fight's does, read no payload and said nothing (fixed in #1553); for that run the test set
`bj_isSinglePlayer` itself.

Not measured: whether the preload file's Lua section sees the map's globals (it does not need to); the editor's part
since 22 Oct (the suite builds from the command line); multiplayer, which is refused.
The fourteen phases then ran with the editor side driven through the language server, as on 22 Oct: all 68 checks
passed. A `wurst.hotreload` request took 4.0 to 14.2 s (the first the longest), where the command line's build took 17
to 21 s per phase, and the map applied each payload 5 to 17 s after asking for it. Without the game, the thirteen
payloads the two paths made were byte-identical, and both refused the field-type edit of phase 5 with the same
reasons. That refusal reached the editor as "Internal error.", its reasons only in the stack trace the error carried;
a map command's failure now carries its own text (`BuildDiagnosticsTests`).

Not measured: whether the preload file's Lua section sees the map's globals (it does not need to); multiplayer, which
is refused.

## Probe for other clients

Expand Down
Loading