Skip to content

Commit

Permalink
Improve marker resolution performance
Browse files Browse the repository at this point in the history
by not connecting the file where we retrieve marker information. That is
an unnecessary step which can be expensive (for example the Xtext
language server rebuilds the source) and causes timeouts on
checkMarkerResoultion
  • Loading branch information
rubenporras committed Jun 22, 2022
1 parent d942d41 commit 6738ee1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,20 @@ public boolean isActive() {

public static @NonNull List<CompletableFuture<LanguageServer>> getInitializedLanguageServers(@NonNull IFile file,
@Nullable Predicate<ServerCapabilities> request) throws IOException {
return getInitializedLanguageServers(file, request, true);
}

public static @NonNull List<CompletableFuture<LanguageServer>> getInitializedLanguageServers(@NonNull IFile file,
@Nullable Predicate<ServerCapabilities> request, boolean connectFile) throws IOException {
synchronized (startedServers) {
Collection<LanguageServerWrapper> wrappers = getLSWrappers(file, request);
return wrappers.stream().map(wrapper -> wrapper.getInitializedServer().thenApplyAsync(server -> {
try {
wrapper.connect(file, null);
if (connectFile) {
wrapper.connect(file, null);
} else {
wrapper.start();
}
} catch (IOException e) {
LanguageServerPlugin.logError(e);
}
Expand Down Expand Up @@ -229,9 +238,30 @@ public static CompletableFuture<LanguageServer> getInitializedLanguageServer(@No
@NonNull LanguageServerDefinition lsDefinition,
Predicate<ServerCapabilities> capabilitiesPredicate)
throws IOException {
return getInitializedLanguageServer(file, lsDefinition, capabilitiesPredicate, true);
}

/**
* Get the requested language server instance for the given file. Starts the language server if not already started.
* @param file
* @param lsDefinition
* @param capabilitiesPredicate a predicate to check capabilities
* @param connectFile if the file should be connected
* @return a LanguageServer for the given file, which is defined with provided server ID and conforms to specified request.
* If {@code capabilitesPredicate} does not test positive for the server's capabilities, {@code null} is returned.
*/
public static CompletableFuture<LanguageServer> getInitializedLanguageServer(@NonNull IFile file,
@NonNull LanguageServerDefinition lsDefinition,
Predicate<ServerCapabilities> capabilitiesPredicate,
boolean connectFile)
throws IOException {
LanguageServerWrapper wrapper = getLSWrapper(file.getProject(), lsDefinition, file.getFullPath());
if (capabilitiesComply(wrapper, capabilitiesPredicate)) {
wrapper.connect(file, null);
if (connectFile) {
wrapper.connect(file, null);
} else {
wrapper.start();
}
return wrapper.getInitializedServer();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private List<CompletableFuture<LanguageServer>> getLanguageServerFutures(@NonNul
CompletableFuture<LanguageServer> serverFuture = LanguageServiceAccessor
.getInitializedLanguageServer(file, definition,
serverCapabilities -> serverCapabilities == null
|| providesCodeActions(serverCapabilities));
|| providesCodeActions(serverCapabilities), false);
if (serverFuture != null) {
languageServerFutures.add(serverFuture);
}
Expand All @@ -174,7 +174,7 @@ private List<CompletableFuture<LanguageServer>> getLanguageServerFutures(@NonNul
return true;
}
return false;
}));
}, false));
}
return languageServerFutures;
}
Expand Down

0 comments on commit 6738ee1

Please sign in to comment.