diff --git a/src/main/java/com/redhat/devtools/lsp4ij/LanguageServersRegistry.java b/src/main/java/com/redhat/devtools/lsp4ij/LanguageServersRegistry.java index 351d4de17..7b1996a19 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/LanguageServersRegistry.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/LanguageServersRegistry.java @@ -41,6 +41,7 @@ public abstract static class LanguageServerDefinition { enum Scope { project, application } + private static final int DEFAULT_LAST_DOCUMENTED_DISCONNECTED_TIMEOUT = 5; public final @Nonnull @@ -65,7 +66,7 @@ public LanguageServerDefinition(@Nonnull String id, @Nonnull String label, Strin 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.scope = scope == null || scope.isBlank() ? Scope.application : Scope.valueOf(scope); this.supportsLightEdit = supportsLightEdit; setEnabled(true); } @@ -271,7 +272,7 @@ private static class LanguageMapping { private final DocumentMatcher documentMatcher; - public LanguageMapping(@NotNull Language language, @Nullable String id, @Nullable String languageId, @NotNull DocumentMatcher documentMatcher) { + public LanguageMapping(@NotNull Language language, @Nullable String id, @Nullable String languageId, @NotNull DocumentMatcher documentMatcher) { this.language = language; this.id = id; this.languageId = languageId; @@ -290,5 +291,11 @@ public Set getAllDefinitions() { .collect(Collectors.toSet()); } + public boolean isLanguageSupported(@NotNull Language language) { + return connections + .stream() + .anyMatch(entry -> language.isKindOf(entry.getKey())); + } + } diff --git a/src/main/java/com/redhat/devtools/lsp4ij/AbstractLSPInlayProvider.java b/src/main/java/com/redhat/devtools/lsp4ij/operations/AbstractLSPInlayProvider.java similarity index 90% rename from src/main/java/com/redhat/devtools/lsp4ij/AbstractLSPInlayProvider.java rename to src/main/java/com/redhat/devtools/lsp4ij/operations/AbstractLSPInlayProvider.java index 9e7a676a0..f8b52840b 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/AbstractLSPInlayProvider.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/operations/AbstractLSPInlayProvider.java @@ -8,7 +8,7 @@ * Contributors: * Red Hat, Inc. - initial API and implementation ******************************************************************************/ -package com.redhat.devtools.lsp4ij; +package com.redhat.devtools.lsp4ij.operations; import com.intellij.codeInsight.hints.*; import com.intellij.codeInsight.hints.presentation.PresentationFactory; @@ -25,6 +25,8 @@ import com.intellij.psi.PsiFile; import com.intellij.ui.layout.LCFlags; import com.intellij.ui.layout.LayoutKt; +import com.redhat.devtools.lsp4ij.LSPIJUtils; +import com.redhat.devtools.lsp4ij.LanguageServersRegistry; import com.redhat.devtools.lsp4ij.commands.CommandExecutor; import com.redhat.devtools.lsp4ij.internal.CancellationSupport; import org.eclipse.lsp4j.Command; @@ -40,6 +42,15 @@ public abstract class AbstractLSPInlayProvider implements InlayHintsProvider cancellationSupportKey; protected AbstractLSPInlayProvider(Key cancellationSupportKey) { @@ -55,6 +66,11 @@ public final InlayHintsCollector getCollectorFor(@NotNull PsiFile psiFile, @NotNull Editor editor, @NotNull NoSettings o, @NotNull InlayHintsSink inlayHintsSink) { + + if (!LanguageServersRegistry.getInstance().isLanguageSupported(psiFile.getLanguage())) { + return EMPTY_INLAY_HINTS_COLLECTOR; + } + CancellationSupport previousCancellationSupport = editor.getUserData(cancellationSupportKey); if (previousCancellationSupport != null) { previousCancellationSupport.cancel(); @@ -147,7 +163,7 @@ public boolean isLanguageSupported(@NotNull Language language) { return true; } - protected void executeClientCommand(Component source, Command command) { + protected void executeClientCommand(@NotNull Component source, @NotNull Command command, @NotNull Project project) { if (command != null) { AnAction action = ActionManager.getInstance().getAction(command.getCommand()); if (action != null) { diff --git a/src/main/java/com/redhat/devtools/lsp4ij/operations/codelens/LSPCodelensInlayProvider.java b/src/main/java/com/redhat/devtools/lsp4ij/operations/codelens/LSPCodelensInlayProvider.java index 79a733056..398fad0a2 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/operations/codelens/LSPCodelensInlayProvider.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/operations/codelens/LSPCodelensInlayProvider.java @@ -21,7 +21,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; -import com.redhat.devtools.lsp4ij.AbstractLSPInlayProvider; +import com.redhat.devtools.lsp4ij.operations.AbstractLSPInlayProvider; import com.redhat.devtools.lsp4ij.LSPIJUtils; import com.redhat.devtools.lsp4ij.LanguageServiceAccessor; import com.redhat.devtools.lsp4ij.internal.CancellationSupport; @@ -148,10 +148,10 @@ private void executeClientCommand(LanguageServer languageServer, CodeLens codeLe Boolean.TRUE.equals(capabilities.getCodeLensProvider().getResolveProvider())) ) { languageServer.getTextDocumentService().resolveCodeLens(codeLens).thenAcceptAsync(resolvedCodeLens -> - executeClientCommand(source, resolvedCodeLens.getCommand()) + executeClientCommand(source, resolvedCodeLens.getCommand(), project) ); } else { - executeClientCommand(source, codeLens.getCommand()); + executeClientCommand(source, codeLens.getCommand(), project); } } diff --git a/src/main/java/com/redhat/devtools/lsp4ij/operations/completion/LSPCompletionContributor.java b/src/main/java/com/redhat/devtools/lsp4ij/operations/completion/LSPCompletionContributor.java index 8c31fcd19..c2dcae629 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/operations/completion/LSPCompletionContributor.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/operations/completion/LSPCompletionContributor.java @@ -26,6 +26,7 @@ import com.intellij.psi.PsiFile; import com.redhat.devtools.lsp4ij.LSPIJUtils; import com.redhat.devtools.lsp4ij.LanguageServerItem; +import com.redhat.devtools.lsp4ij.LanguageServersRegistry; import com.redhat.devtools.lsp4ij.LanguageServiceAccessor; import com.redhat.devtools.lsp4ij.internal.CancellationSupport; import com.redhat.devtools.lsp4ij.internal.StringUtils; @@ -56,6 +57,10 @@ public void fillCompletionVariants(@NotNull CompletionParameters parameters, @No return; } + if (!LanguageServersRegistry.getInstance().isLanguageSupported(psiFile.getLanguage())) { + return; + } + Editor editor = parameters.getEditor(); Document document = editor.getDocument(); Project project = psiFile.getProject(); diff --git a/src/main/java/com/redhat/devtools/lsp4ij/operations/diagnostics/LSPDiagnosticAnnotator.java b/src/main/java/com/redhat/devtools/lsp4ij/operations/diagnostics/LSPDiagnosticAnnotator.java index 09fd1ab27..1fea42d17 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/operations/diagnostics/LSPDiagnosticAnnotator.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/operations/diagnostics/LSPDiagnosticAnnotator.java @@ -25,6 +25,7 @@ import com.intellij.psi.PsiFile; import com.redhat.devtools.lsp4ij.LSPIJUtils; import com.redhat.devtools.lsp4ij.LSPVirtualFileData; +import com.redhat.devtools.lsp4ij.LanguageServersRegistry; import com.redhat.devtools.lsp4ij.LanguageServiceAccessor; import com.redhat.devtools.lsp4ij.operations.codeactions.LSPLazyCodeActionIntentionAction; import org.eclipse.lsp4j.Diagnostic; @@ -40,19 +41,25 @@ */ public class LSPDiagnosticAnnotator extends ExternalAnnotator { - @Nullable - @Override - public Boolean collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) { - return Boolean.TRUE; - } - - @Override - public @Nullable Boolean doAnnotate(Boolean unused) { + @Nullable + @Override + public Boolean collectInformation(@NotNull PsiFile file, @NotNull Editor editor, boolean hasErrors) { + if (!LanguageServersRegistry.getInstance().isLanguageSupported(file.getLanguage())) { + return Boolean.FALSE; + } return Boolean.TRUE; - } + } @Override - public void apply(@NotNull PsiFile file, Boolean unused, @NotNull AnnotationHolder holder) { + public @Nullable Boolean doAnnotate(Boolean result) { + return result; + } + + @Override + public void apply(@NotNull PsiFile file, Boolean applyAnnotator, @NotNull AnnotationHolder holder) { + if (!applyAnnotator) { + return; + } URI fileUri = LSPIJUtils.toUri(file); Document document = LSPIJUtils.getDocument(file.getVirtualFile()); diff --git a/src/main/java/com/redhat/devtools/lsp4ij/operations/documentLink/LSPDocumentLinkAnnotator.java b/src/main/java/com/redhat/devtools/lsp4ij/operations/documentLink/LSPDocumentLinkAnnotator.java index 9cc9f8a88..136e318fb 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/operations/documentLink/LSPDocumentLinkAnnotator.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/operations/documentLink/LSPDocumentLinkAnnotator.java @@ -26,10 +26,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; -import com.redhat.devtools.lsp4ij.LSPIJUtils; -import com.redhat.devtools.lsp4ij.LSPVirtualFileData; -import com.redhat.devtools.lsp4ij.LanguageServerWrapper; -import com.redhat.devtools.lsp4ij.LanguageServiceAccessor; +import com.redhat.devtools.lsp4ij.*; import com.redhat.devtools.lsp4ij.internal.CancellationSupport; import org.eclipse.lsp4j.DocumentLink; import org.eclipse.lsp4j.DocumentLinkParams; @@ -40,6 +37,7 @@ import java.net.URI; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.BlockingDeque; import java.util.concurrent.CompletableFuture; @@ -56,10 +54,13 @@ public class LSPDocumentLinkAnnotator extends ExternalAnnotator collectInformation(@NotNull PsiFile psiFile, @NotNull Editor editor, boolean hasErrors) { + if (!LanguageServersRegistry.getInstance().isLanguageSupported(psiFile.getLanguage())) { + return Collections.emptyList(); + } Document document = editor.getDocument(); VirtualFile file = LSPIJUtils.getFile(document); if (file == null) { - return null; + return Collections.emptyList(); } List datas = new ArrayList<>(); final CancellationSupport cancellationSupport = new CancellationSupport(); @@ -110,7 +111,7 @@ public List collectInformation(@NotNull PsiFile psiFile, @No } @Override - public void apply(@NotNull PsiFile file, List datas, @NotNull AnnotationHolder holder) { + public void apply(@NotNull PsiFile file, @NotNull List datas, @NotNull AnnotationHolder holder) { if (datas.isEmpty()) { return; } diff --git a/src/main/java/com/redhat/devtools/lsp4ij/operations/documentLink/LSPDocumentLinkGotoDeclarationHandler.java b/src/main/java/com/redhat/devtools/lsp4ij/operations/documentLink/LSPDocumentLinkGotoDeclarationHandler.java index e58109d95..e9ae891ab 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/operations/documentLink/LSPDocumentLinkGotoDeclarationHandler.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/operations/documentLink/LSPDocumentLinkGotoDeclarationHandler.java @@ -24,10 +24,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; -import com.redhat.devtools.lsp4ij.LSPIJUtils; -import com.redhat.devtools.lsp4ij.LSPVirtualFileData; -import com.redhat.devtools.lsp4ij.LanguageServerBundle; -import com.redhat.devtools.lsp4ij.LanguageServiceAccessor; +import com.redhat.devtools.lsp4ij.*; import org.eclipse.lsp4j.DocumentLink; import org.jetbrains.annotations.Nullable; @@ -35,6 +32,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; /** * {@link GotoDeclarationHandler} implementation used to open LSP document link with CTrl+Click. @@ -43,6 +41,9 @@ public class LSPDocumentLinkGotoDeclarationHandler implements GotoDeclarationHan @Override public PsiElement @Nullable [] getGotoDeclarationTargets(@Nullable PsiElement sourceElement, int offset, Editor editor) { + if (!LanguageServersRegistry.getInstance().isLanguageSupported(sourceElement.getLanguage())) { + return PsiElement.EMPTY_ARRAY; + } Document document = editor.getDocument(); VirtualFile file = LSPIJUtils.getFile(document); Module module = LSPIJUtils.getModule(file, sourceElement.getProject()); diff --git a/src/main/java/com/redhat/devtools/lsp4ij/operations/documentation/LSPDocumentationProvider.java b/src/main/java/com/redhat/devtools/lsp4ij/operations/documentation/LSPDocumentationProvider.java index 47d558ac6..19d3d1f67 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/operations/documentation/LSPDocumentationProvider.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/operations/documentation/LSPDocumentationProvider.java @@ -22,6 +22,7 @@ import com.intellij.psi.PsiManager; import com.intellij.util.io.URLUtil; import com.redhat.devtools.lsp4ij.LSPIJUtils; +import com.redhat.devtools.lsp4ij.LanguageServersRegistry; import com.redhat.devtools.lsp4ij.operations.completion.LSPCompletionProposal; import com.vladsch.flexmark.html.HtmlRenderer; import com.vladsch.flexmark.parser.Parser; @@ -30,6 +31,7 @@ import org.jetbrains.annotations.Nullable; import java.awt.*; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -68,6 +70,9 @@ public String getQuickNavigateInfo(PsiElement element, PsiElement originalElemen @Nullable @Override public String generateDoc(@NotNull PsiElement element, @Nullable PsiElement originalElement) { + if (!LanguageServersRegistry.getInstance().isLanguageSupported(originalElement.getLanguage())) { + return null; + } try { Project project = element.getProject(); if (project.isDisposed()) { diff --git a/src/main/java/com/redhat/devtools/lsp4ij/operations/highlight/LSPHighlightUsagesHandlerFactory.java b/src/main/java/com/redhat/devtools/lsp4ij/operations/highlight/LSPHighlightUsagesHandlerFactory.java index 6ef87c523..8e3e7cf53 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/operations/highlight/LSPHighlightUsagesHandlerFactory.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/operations/highlight/LSPHighlightUsagesHandlerFactory.java @@ -19,8 +19,10 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.redhat.devtools.lsp4ij.LSPIJUtils; +import com.redhat.devtools.lsp4ij.LanguageServersRegistry; import com.redhat.devtools.lsp4ij.LanguageServiceAccessor; import com.redhat.devtools.lsp4ij.internal.CancellationSupport; import org.eclipse.lsp4j.DocumentHighlight; @@ -45,6 +47,9 @@ public class LSPHighlightUsagesHandlerFactory implements HighlightUsagesHandlerF @Override public @Nullable HighlightUsagesHandlerBase createHighlightUsagesHandler(@NotNull Editor editor, @NotNull PsiFile file) { + if (!LanguageServersRegistry.getInstance().isLanguageSupported(file.getLanguage())) { + return null; + } List targets = getTargets(editor, file); return targets.isEmpty() ? null : new LSPHighlightUsagesHandler(editor, file, targets); } diff --git a/src/main/java/com/redhat/devtools/lsp4ij/operations/inlayhint/LSPInlayHintInlayProvider.java b/src/main/java/com/redhat/devtools/lsp4ij/operations/inlayhint/LSPInlayHintInlayProvider.java index 3e1cc5dd7..4ed993c13 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/operations/inlayhint/LSPInlayHintInlayProvider.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/operations/inlayhint/LSPInlayHintInlayProvider.java @@ -21,7 +21,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; -import com.redhat.devtools.lsp4ij.AbstractLSPInlayProvider; +import com.redhat.devtools.lsp4ij.operations.AbstractLSPInlayProvider; import com.redhat.devtools.lsp4ij.LSPIJUtils; import com.redhat.devtools.lsp4ij.LanguageServiceAccessor; import com.redhat.devtools.lsp4ij.internal.CancellationSupport; @@ -174,10 +174,10 @@ private void executeClientCommand( languageServer.getTextDocumentService() .resolveInlayHint(inlayHint) .thenAcceptAsync(resolvedInlayHint -> { - executeClientCommand(source, resolvedInlayHint.getLabel().getRight().get(index).getCommand()); + executeClientCommand(source, resolvedInlayHint.getLabel().getRight().get(index).getCommand(), project); }); } else { - executeClientCommand(source, inlayHint.getLabel().getRight().get(index).getCommand()); + executeClientCommand(source, inlayHint.getLabel().getRight().get(index).getCommand(), project); } } diff --git a/src/main/java/com/redhat/devtools/lsp4ij/operations/navigation/LSPGotoDeclarationHandler.java b/src/main/java/com/redhat/devtools/lsp4ij/operations/navigation/LSPGotoDeclarationHandler.java index 56021b3d3..49fb03074 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/operations/navigation/LSPGotoDeclarationHandler.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/operations/navigation/LSPGotoDeclarationHandler.java @@ -22,6 +22,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import com.redhat.devtools.lsp4ij.LSPIJUtils; +import com.redhat.devtools.lsp4ij.LanguageServersRegistry; import com.redhat.devtools.lsp4ij.LanguageServiceAccessor; import com.redhat.devtools.lsp4ij.internal.CancellationSupport; import com.redhat.devtools.lsp4ij.internal.CancellationUtil; @@ -45,6 +46,9 @@ public class LSPGotoDeclarationHandler implements GotoDeclarationHandler { @Nullable @Override public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement sourceElement, int offset, Editor editor) { + if (!LanguageServersRegistry.getInstance().isLanguageSupported(sourceElement.getLanguage())) { + return null; + } VirtualFile file = LSPIJUtils.getFile(sourceElement); if (file == null) { return PsiElement.EMPTY_ARRAY; diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 4179a9713..39a7e5c07 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,89 +1,155 @@ - com.redhat.devtools.lsp4ij + com.redhat.devtools.lsp4ij LSP4IJ - 1.0 - Red-Hat + 1.0 + Red-Hat - 0.0.1
  • Initial release
Learn more in the changelog. - ]]> -
- com.intellij.modules.platform - - com.intellij.modules.java - com.redhat.devtools.intellij.telemetry + ]]> + + com.intellij.modules.platform + + com.intellij.modules.java + com.redhat.devtools.intellij.telemetry - - + + - + - - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - + - + - +
\ No newline at end of file