Skip to content

Commit

Permalink
Implemented PR review feedback suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
SCWells72 committed Dec 10, 2024
1 parent 7e6e64a commit 1a856ba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 53 deletions.
10 changes: 1 addition & 9 deletions docs/LSPApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1169,13 +1169,15 @@ public boolean isDidRenameFilesSupported(@NotNull PsiFile file) {
return fileOperationsManager.canDidRenameFiles(LSPIJUtils.toUri(file), file.isDirectory());
}

@NotNull
public LSPClientFeatures getClientFeatures() {
if (clientFeatures == null) {
clientFeatures = getOrCreateClientFeatures();
}
return clientFeatures;
}

@NotNull
private synchronized LSPClientFeatures getOrCreateClientFeatures() {
if (clientFeatures != null) {
return clientFeatures;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,26 +423,6 @@ public CompletableFuture<Set<LanguageServerDefinition>> 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<LanguageServerWrapper> getMatchedLanguageServerWrappersSync(@NotNull VirtualFile file) {
Set<LanguageServerWrapper> languageServerWrappers = new LinkedHashSet<>();
MatchedLanguageServerDefinitions matchedLanguageServerDefinitions = getMatchedLanguageServerDefinitions(file, project, false);
if (matchedLanguageServerDefinitions != null) {
Set<LanguageServerDefinition> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,21 +85,17 @@ private static void processExternalReferences(@NotNull PsiFile file,
return;
}

Project project = file.getProject();
Set<LanguageServerWrapper> 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<String> externalReferenceKeys = new HashSet<>();
PsiSearchHelper.getInstance(file.getProject()).processElementsWithWord(
PsiSearchHelper.getInstance(project).processElementsWithWord(
(element, offsetInElement) -> {
PsiReference originalReference = element.findReferenceAt(offsetInElement);
List<PsiReference> references = originalReference != null ?
Expand Down Expand Up @@ -146,19 +139,6 @@ private static void processExternalReferences(@NotNull PsiFile file,
);
}

private static boolean isCaseSensitive(@NotNull Set<LanguageServerWrapper> 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();
Expand Down

0 comments on commit 1a856ba

Please sign in to comment.