Skip to content

Commit

Permalink
perf: Start language server only when indexation is finished
Browse files Browse the repository at this point in the history
Fixes #1075

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Aug 3, 2023
1 parent ac72102 commit cfa3f27
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.vfs.VirtualFile;
Expand All @@ -40,10 +42,25 @@ public void projectClosing(@NotNull Project project) {
public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null) {
// Force the start of all languages servers mapped with the given file
LanguageServiceAccessor.getInstance(source.getProject())
.getLanguageServers(document, capabilities -> true);
Project project = source.getProject();
if (DumbService.isDumb(project)) {
// Force the start of all languages servers mapped with the given file when indexation is finished
DumbService.getInstance(project).runWhenSmart(() -> {
startLanguageServer(source, document);
});
} else {
// Force the start of all languages servers mapped with the given file immediately
startLanguageServer(source, document);
}
}
}

private static void startLanguageServer(@NotNull FileEditorManager source, Document document) {
// Force the start of all languages servers mapped with the given file
// Server capabilities filter is set to null to avoid waiting
// for the start of the server when server capabilities are checked
LanguageServiceAccessor.getInstance(source.getProject())
.getLanguageServers(document, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
*/
public class LanguageServiceAccessor {
private static final Logger LOGGER = LoggerFactory.getLogger(LanguageServiceAccessor.class);

private final Project project;

public static LanguageServiceAccessor getInstance(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/**
* LSP completion contributor.
*/
public class LSPCompletionContributor extends CompletionContributor implements DumbAware {
public class LSPCompletionContributor extends CompletionContributor {
private static final Logger LOGGER = LoggerFactory.getLogger(LSPCompletionContributor.class);

@Override
Expand Down

0 comments on commit cfa3f27

Please sign in to comment.