From f4b8f7a469eaffad871931a300f47fd5f68d5f0a Mon Sep 17 00:00:00 2001 From: azerr Date: Thu, 3 Aug 2023 15:02:35 +0200 Subject: [PATCH] perf: Start language server only when indexation is finished Fixes #1075 Signed-off-by: azerr --- ...umentToLanguageServerSetupParticipant.java | 23 ++++++++++++++++--- .../lsp4ij/LanguageServiceAccessor.java | 2 ++ .../completion/LSPCompletionContributor.java | 2 +- .../quarkus/QuarkusProjectService.java | 9 ++++---- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/ConnectDocumentToLanguageServerSetupParticipant.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/ConnectDocumentToLanguageServerSetupParticipant.java index 1a6b16f8b..4530146b7 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/ConnectDocumentToLanguageServerSetupParticipant.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/ConnectDocumentToLanguageServerSetupParticipant.java @@ -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; @@ -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)) { + // If indexing is in progress, register a listener to execute the code when indexing is done + DumbService.getInstance(project).runWhenSmart(() -> { + // Force the start of all languages servers mapped with the given file + startLanguageServer(source, document); + }); + } else { + 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); + } + } diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java index a60d7fcfa..f63903ce8 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/LanguageServiceAccessor.java @@ -42,6 +42,8 @@ */ public class LanguageServiceAccessor { private static final Logger LOGGER = LoggerFactory.getLogger(LanguageServiceAccessor.class); + + public static final Predicate ANY_SERVER_CAPABILITIES = t-> true; private final Project project; public static LanguageServiceAccessor getInstance(Project project) { diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/completion/LSPCompletionContributor.java b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/completion/LSPCompletionContributor.java index c6152a87a..a9ff3ac97 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/completion/LSPCompletionContributor.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4ij/operations/completion/LSPCompletionContributor.java @@ -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 diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java index 234725a2a..2f9f749f8 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/QuarkusProjectService.java @@ -72,7 +72,8 @@ public QuarkusProjectService(Project project) { @Override public void moduleAdded(@NotNull Project project, @NotNull Module module) { - QuarkusModuleUtil.ensureQuarkusLibrary(module, new EmptyProgressIndicator()); + // TODO : manage Quarkus deployment + // QuarkusModuleUtil.ensureQuarkusLibrary(module, new EmptyProgressIndicator()); } public VirtualFile getSchema(Module module) { @@ -138,13 +139,13 @@ public void sourceFilesChanged(Set