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 f4b8f7a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 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)) {
// 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);
}

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

public static final Predicate<ServerCapabilities> ANY_SERVER_CAPABILITIES = t-> true;
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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -138,13 +139,13 @@ public void sourceFilesChanged(Set<com.intellij.openapi.util.Pair<VirtualFile, M
}

public void processModules(com.intellij.openapi.progress.ProgressIndicator progressIndicator) {
for (var module : ModuleManager.getInstance(project).getModules()) {
// TODO : manage Quarkus deployment
/*for (var module : ModuleManager.getInstance(project).getModules()) {
LOGGER.info("Calling ensure from processModules");
QuarkusModuleUtil.ensureQuarkusLibrary(module, progressIndicator);
}
}*/
}


@Override
public void dispose() {
connection.disconnect();
Expand Down

0 comments on commit f4b8f7a

Please sign in to comment.