From 1a856bac45f0a63d649c07a5d00ac987decf0e9c Mon Sep 17 00:00:00 2001 From: Scott Wells Date: Tue, 10 Dec 2024 09:04:24 -0600 Subject: [PATCH] Implemented PR review feedback suggestions. --- docs/LSPApi.md | 10 +------ .../lsp4ij/LanguageServerWrapper.java | 2 ++ .../lsp4ij/LanguageServiceAccessor.java | 20 ------------- .../usages/LSPExternalReferencesFinder.java | 28 +++---------------- 4 files changed, 7 insertions(+), 53 deletions(-) diff --git a/docs/LSPApi.md b/docs/LSPApi.md index af10b6905..69fc1d088 100644 --- a/docs/LSPApi.md +++ b/docs/LSPApi.md @@ -2,7 +2,6 @@ The [LSPClientFeatures](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/client/features/LSPClientFeatures.java) API allows you to customize the behavior of LSP features, including: -- [Client-only features](#client-only-features) - [LSP codeAction feature](#lsp-codeAction-feature) - [LSP codeLens feature](#lsp-codeLens-feature) - [LSP color feature](#lsp-color-feature) @@ -61,6 +60,7 @@ public class MyLanguageServerFactory implements LanguageServerFactory { | boolean keepServerAlive() | Returns `true` if the server is kept alive even if all files associated with the language server are closed and `false` otherwise. | `false` | | boolean canStopServerByUser() | Returns `true` if the user can stop the language server in LSP console from the context menu and `false` otherwise. | `true` | | boolean isEnabled(VirtualFile) | Returns `true` if the language server is enabled for the given file and `false` otherwise. | `true` | +| boolean isCaseSensitive(PsiFile file) | Returns `true` if the language grammar for the given file is case-sensitive and `false` otherwise. | `false` | ```java package my.language.server; @@ -164,14 +164,6 @@ public class MyLSPCodeLensFeature extends LSPCodeLensFeature { } ``` -## Client-only Features - -Client-only features are used to provide information to LSP4IJ that is not available from language servers but is required for proper integration of language server features into the IDE's corresponding features. - -| API | Description | Default Behaviour | -|---------------------------------------|--------------------------------------------------------------------------------------|----------------------------| -| boolean isCaseSensitive(PsiFile file) | Determines whether or not the language grammar for the given file is case-sensitive. | `false` (case-insensitive) | - ## LSP CodeAction Feature | API | Description | Default Behaviour | diff --git a/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java b/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java index 7f7bb30cf..8a073afa3 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/LanguageServerWrapper.java @@ -1169,6 +1169,7 @@ public boolean isDidRenameFilesSupported(@NotNull PsiFile file) { return fileOperationsManager.canDidRenameFiles(LSPIJUtils.toUri(file), file.isDirectory()); } + @NotNull public LSPClientFeatures getClientFeatures() { if (clientFeatures == null) { clientFeatures = getOrCreateClientFeatures(); @@ -1176,6 +1177,7 @@ public LSPClientFeatures getClientFeatures() { return clientFeatures; } + @NotNull private synchronized LSPClientFeatures getOrCreateClientFeatures() { if (clientFeatures != null) { return clientFeatures; diff --git a/src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java b/src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java index 591a75616..93e40a922 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/LanguageServiceAccessor.java @@ -423,26 +423,6 @@ public CompletableFuture> getAsyncMatched() { } } - /** - * Returns the language server wrappers for the specified file synchronously. - * - * @param file the file - * @return the language server wrappers that apply to the file - */ - @ApiStatus.Internal - @NotNull - public Set getMatchedLanguageServerWrappersSync(@NotNull VirtualFile file) { - Set languageServerWrappers = new LinkedHashSet<>(); - MatchedLanguageServerDefinitions matchedLanguageServerDefinitions = getMatchedLanguageServerDefinitions(file, project, false); - if (matchedLanguageServerDefinitions != null) { - Set languageServerDefinitions = matchedLanguageServerDefinitions.getMatched(); - for (LanguageServerDefinition languageServerDefinition : languageServerDefinitions) { - languageServerWrappers.add(new LanguageServerWrapper(project, languageServerDefinition)); - } - } - return languageServerWrappers; - } - /** * Returns the matched language server definitions for the given file. * diff --git a/src/main/java/com/redhat/devtools/lsp4ij/usages/LSPExternalReferencesFinder.java b/src/main/java/com/redhat/devtools/lsp4ij/usages/LSPExternalReferencesFinder.java index 274251d49..5766d361f 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/usages/LSPExternalReferencesFinder.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/usages/LSPExternalReferencesFinder.java @@ -28,11 +28,8 @@ import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.UsageSearchContext; import com.intellij.util.Processor; -import com.intellij.util.containers.ContainerUtil; import com.redhat.devtools.lsp4ij.LSPIJUtils; -import com.redhat.devtools.lsp4ij.LanguageServerWrapper; import com.redhat.devtools.lsp4ij.LanguageServiceAccessor; -import com.redhat.devtools.lsp4ij.client.features.LSPClientFeatures; import com.redhat.devtools.lsp4ij.features.LSPPsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -88,21 +85,17 @@ private static void processExternalReferences(@NotNull PsiFile file, return; } - Project project = file.getProject(); - Set languageServerWrappers = LanguageServiceAccessor.getInstance(project).getMatchedLanguageServerWrappersSync(virtualFile); - if (ContainerUtil.isEmpty(languageServerWrappers)) { - return; - } - // Determine whether or not to search/match in a case-sensitive manner based on client configuration - boolean caseSensitive = isCaseSensitive(languageServerWrappers, file); + Project project = file.getProject(); + boolean caseSensitive = LanguageServiceAccessor.getInstance(project) + .hasAny(file.getVirtualFile(), ls -> ls.getClientFeatures().isCaseSensitive(file)); if (progressIndicator != null) { progressIndicator.setText("Finding usages of '" + wordText + "'"); } Set externalReferenceKeys = new HashSet<>(); - PsiSearchHelper.getInstance(file.getProject()).processElementsWithWord( + PsiSearchHelper.getInstance(project).processElementsWithWord( (element, offsetInElement) -> { PsiReference originalReference = element.findReferenceAt(offsetInElement); List references = originalReference != null ? @@ -146,19 +139,6 @@ private static void processExternalReferences(@NotNull PsiFile file, ); } - private static boolean isCaseSensitive(@NotNull Set languageServerWrappers, @NotNull PsiFile psiFile) { - // If any supporting language server is case-sensitive, the search must be case-sensitive; it's better to - // miss changing things that should have been changed than to change things that should not - for (LanguageServerWrapper languageServerWrapper : languageServerWrappers) { - LSPClientFeatures clientFeatures = languageServerWrapper.getClientFeatures(); - if ((clientFeatures != null) && clientFeatures.isCaseSensitive(psiFile)) { - return true; - } - } - - return false; - } - @Nullable private static String getReferenceKey(@NotNull PsiReference reference) { PsiElement sourceElement = reference.getElement();