Skip to content

Commit

Permalink
Fix deadlock in didChangeWorkspaceFolders
Browse files Browse the repository at this point in the history
Blocking on the future creating the progress token with the client means the
server can't actually receive the response from the client for that request.
Tests don't catch this because the mock client is called directly,
rather than through the server proxy.

I decided to just remove the progress token code for now so
didChangeWorkspaceFolders can work at all, rather than trying to make
the method work asynchronously, which is a larger lift considering it
mutates the server state. That change is coming though.
  • Loading branch information
milesziemer committed Sep 26, 2024
1 parent f7d843e commit 24a93bb
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions src/main/java/software/amazon/smithy/lsp/SmithyLanguageServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -84,7 +82,6 @@
import org.eclipse.lsp4j.Unregistration;
import org.eclipse.lsp4j.UnregistrationParams;
import org.eclipse.lsp4j.WorkDoneProgressBegin;
import org.eclipse.lsp4j.WorkDoneProgressCreateParams;
import org.eclipse.lsp4j.WorkDoneProgressEnd;
import org.eclipse.lsp4j.WorkspaceFolder;
import org.eclipse.lsp4j.WorkspaceFoldersOptions;
Expand Down Expand Up @@ -471,20 +468,6 @@ public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) {
public void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) {
LOGGER.finest("DidChangeWorkspaceFolders");

Either<String, Integer> progressToken = Either.forLeft(UUID.randomUUID().toString());
try {
client.createProgress(new WorkDoneProgressCreateParams(progressToken)).get();
} catch (ExecutionException | InterruptedException e) {
client.error(String.format("Unable to create work done progress token: %s", e.getMessage()));
progressToken = null;
}

if (progressToken != null) {
WorkDoneProgressBegin begin = new WorkDoneProgressBegin();
begin.setTitle("Updating workspace");
client.notifyProgress(new ProgressParams(progressToken, Either.forLeft(begin)));
}

for (WorkspaceFolder folder : params.getEvent().getAdded()) {
loadWorkspace(folder);
}
Expand All @@ -496,11 +479,6 @@ public void didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParams params) {
unregisterSmithyFileWatchers().thenRun(this::registerSmithyFileWatchers);
unregisterWorkspaceBuildFileWatchers().thenRun(this::registerWorkspaceBuildFileWatchers);
sendFileDiagnosticsForManagedDocuments();

if (progressToken != null) {
WorkDoneProgressEnd end = new WorkDoneProgressEnd();
client.notifyProgress(new ProgressParams(progressToken, Either.forLeft(end)));
}
}

private void loadWorkspace(WorkspaceFolder workspaceFolder) {
Expand Down

0 comments on commit 24a93bb

Please sign in to comment.