Skip to content

Commit

Permalink
fix: disallow language servers in light edit mode
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Nov 6, 2023
1 parent 1a457e7 commit d663648
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ContentTypeToLanguageServerDefinition(@NotNull Language language,
}

public boolean match(VirtualFile file, Project project) {
return documentMatcher.match(file, project);
return getValue().supportsCurrentEditMode(project) && documentMatcher.match(file, project);
}

public boolean shouldBeMatchedAsynchronously(Project project) {
Expand All @@ -32,6 +32,9 @@ public boolean isEnabled() {
}

public @NotNull <R> CompletableFuture<Boolean> matchAsync(VirtualFile file, Project project) {
if (!getValue().supportsCurrentEditMode(project)) {
return CompletableFuture.completedFuture(false);
}
return documentMatcher.matchAsync(file, project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
package com.redhat.devtools.intellij.lsp4ij;

import com.intellij.icons.AllIcons;
import com.intellij.ide.lightEdit.LightEdit;
import com.intellij.lang.Language;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.redhat.devtools.intellij.lsp4ij.client.LanguageClientImpl;
import com.redhat.devtools.intellij.lsp4ij.server.StreamConnectionProvider;
import org.eclipse.lsp4j.jsonrpc.Launcher;
Expand Down Expand Up @@ -55,16 +54,19 @@ enum Scope {
public final int lastDocumentDisconnectedTimeout;
private boolean enabled;

public final boolean supportsLightEdit;

final @Nonnull Scope scope;

public LanguageServerDefinition(@Nonnull String id, @Nonnull String label, String description, boolean isSingleton, Integer lastDocumentDisconnectedTimeout, String scope) {
public LanguageServerDefinition(@Nonnull String id, @Nonnull String label, String description, boolean isSingleton, Integer lastDocumentDisconnectedTimeout, String scope, boolean supportsLightEdit) {
this.id = id;
this.label = label;
this.description = description;
this.isSingleton = isSingleton;
this.lastDocumentDisconnectedTimeout = lastDocumentDisconnectedTimeout != null && lastDocumentDisconnectedTimeout > 0 ? lastDocumentDisconnectedTimeout : DEFAULT_LAST_DOCUMENTED_DISCONNECTED_TIMEOUT;
this.languageIdMappings = new ConcurrentHashMap<>();
this.scope = scope == null || scope.isBlank()? Scope.application : Scope.valueOf(scope);
this.supportsLightEdit = supportsLightEdit;
setEnabled(true);
}

Expand Down Expand Up @@ -109,13 +111,17 @@ public Class<? extends LanguageServer> getServerInterface() {
public <S extends LanguageServer> Launcher.Builder<S> createLauncherBuilder() {
return new Launcher.Builder<>();
}

public boolean supportsCurrentEditMode(@NotNull Project project) {
return project != null && (supportsLightEdit || !LightEdit.owns(project));
}
}

static class ExtensionLanguageServerDefinition extends LanguageServerDefinition {
private final ServerExtensionPointBean extension;

public ExtensionLanguageServerDefinition(ServerExtensionPointBean element) {
super(element.id, element.label, element.description, element.singleton, element.lastDocumentDisconnectedTimeout, element.scope);
super(element.id, element.label, element.description, element.singleton, element.lastDocumentDisconnectedTimeout, element.scope, element.supportsLightEdit);
this.extension = element;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class ServerExtensionPointBean extends BaseKeyedLazyInstance<StreamConnec
@Attribute("singleton")
public boolean singleton;

@Attribute("supportsLightEdit")
public boolean supportsLightEdit;

@Attribute("lastDocumentDisconnectedTimeout")
public Integer lastDocumentDisconnectedTimeout;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
******************************************************************************/
package com.redhat.devtools.intellij.lsp4ij.internal;

import com.intellij.ide.lightEdit.LightEdit;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.progress.EmptyProgressIndicator;
Expand Down Expand Up @@ -74,8 +75,8 @@ public PromiseToCompletableFuture(@NotNull Function<ProgressIndicator, R> code,
}

protected void init() {
// if indexation is processing, we need to execute the promise in smart mode
var executeInSmartMode = DumbService.getInstance(project).isDumb();
// if indexation is processing and not in Light Edit mode, we need to execute the promise in smart mode
var executeInSmartMode = !LightEdit.owns(project) && DumbService.getInstance(project).isDumb();
var promise = nonBlockingReadActionPromise(executeInSmartMode);
bind(promise);
}
Expand Down

0 comments on commit d663648

Please sign in to comment.