Skip to content

Commit

Permalink
perf: don't get document when file is opened
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 16, 2023
1 parent 2dd6d5a commit ad5ccc6
Showing 1 changed file with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
package com.redhat.devtools.intellij.lsp4ij;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.project.DumbService;
Expand Down Expand Up @@ -56,21 +54,18 @@ public void projectClosing(@NotNull Project project) {

@Override
public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) {
Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null) {
Project project = source.getProject();
boolean readAccessAllowed = ApplicationManager.getApplication().isReadAccessAllowed();
boolean dumb = DumbService.isDumb(project);
// As document matcher requires read action, we try to open the file in read action and when indexing is finishsed.
if (readAccessAllowed && !dumb) {
// No indexing and read action enabled
// --> force the start of all languages servers mapped with the given file immediately
connectToLanguageServer(file, project);
} else {
// Wait for indexing is finished and read action is enabled
// --> force the start of all languages servers mapped with the given file when indexing is finished and read action is allowed
new ConnectToLanguageServerCompletableFuture(file, project);
}
Project project = source.getProject();
boolean readAccessAllowed = ApplicationManager.getApplication().isReadAccessAllowed();
boolean dumb = DumbService.isDumb(project);
// As document matcher requires read action, we try to open the file in read action and when indexing is finishsed.
if (readAccessAllowed && !dumb) {
// No indexing and read action enabled
// --> force the start of all languages servers mapped with the given file immediately
connectToLanguageServer(file, project);
} else {
// Wait for indexing is finished and read action is enabled
// --> force the start of all languages servers mapped with the given file when indexing is finished and read action is allowed
new ConnectToLanguageServerCompletableFuture(file, project);
}
}

Expand Down

0 comments on commit ad5ccc6

Please sign in to comment.