generated from redhat-developer/new-project-template
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
35 changed files
with
1,294 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# LSP client features | ||
|
||
The [LSPClientFeatures](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/client/features/LSPClientFeatures.java) API allows customizing the behavior of LSP features to customize: | ||
|
||
* [LSP completion feature](#customize-lsp-completion-feature) | ||
* [LSP diagnostic feature](#customize-lsp-diagnostic-feature) | ||
* [LSP formatting feature](#customize-lsp-formatting-feature) | ||
|
||
These custom supports are done: | ||
|
||
* by extending the default classes `LSP*Feature` (e.g. creating a new class `MyLSPFormattingFeature` that extends | ||
[LSPFormattingFeature](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/client/features/LSPFormattingFeature.java) to customize formatting support) | ||
and overriding some methods to customize the behavior. | ||
* registering your custom classes with `LanguageServerFactory#createClientFeatures(@NotNull Project)`: | ||
|
||
```java | ||
package my.language.server; | ||
|
||
import com.intellij.openapi.project.Project; | ||
import com.redhat.devtools.lsp4ij.LanguageServerFactory; | ||
import com.redhat.devtools.lsp4ij.client.features.LSPClientFeatures; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MyLanguageServerFactory implements LanguageServerFactory { | ||
|
||
@Override | ||
public @NotNull LSPClientFeatures createClientFeatures() { | ||
return new LSPClientFeatures() | ||
.setCompletionFeature(new MyLSPCompletionFeature()) // customize LSP completion feature | ||
.setDiagnosticFeature(new MyLSPDiagnosticFeature()) // customize LSP diagnostic feature | ||
.setFormattingFeature(new MyLSPFormattingFeature()); // customize LSP formatting feature | ||
} | ||
} | ||
``` | ||
|
||
## Customize LSP completion feature | ||
|
||
TODO | ||
|
||
## Customize LSP diagnostic feature | ||
|
||
Here is an example of code that avoids creating an IntelliJ annotation when the LSP diagnostic code is equal to `ignore`: | ||
|
||
```java | ||
package my.language.server; | ||
|
||
import com.intellij.lang.annotation.HighlightSeverity; | ||
import com.redhat.devtools.lsp4ij.client.features.LSPDiagnosticFeature; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class MyLSPDiagnosticFeature extends LSPDiagnosticFeature { | ||
|
||
@Override | ||
public @Nullable HighlightSeverity getHighlightSeverity(@NotNull Diagnostic diagnostic) { | ||
if (diagnostic.getCode() != null && | ||
diagnostic.getCode().isLeft() && | ||
"ignore".equals(diagnostic.getCode().getLeft())) { | ||
// return a null HighlightSeverity when LSP diagnostic code is equals | ||
// to 'ignore' to avoid creating an IntelliJ annotation | ||
return null; | ||
} | ||
return super.getHighlightSeverity(diagnostic); | ||
} | ||
|
||
} | ||
``` | ||
|
||
## Customize LSP formatting feature | ||
|
||
Here is an example of code that allows to execute the LSP formatter even if there is a specific formatter registered by an IntelliJ plugin | ||
|
||
TODO: revisit this API to manage range formatting too. | ||
|
||
```java | ||
package my.language.server; | ||
|
||
import com.intellij.psi.PsiFile; | ||
import com.redhat.devtools.lsp4ij.client.features.LSPFormattingFeature; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MyLSPFormattingFeature extends LSPFormattingFeature { | ||
|
||
@Override | ||
protected boolean isExistingFormatterOverrideable(@NotNull PsiFile file) { | ||
// By default, isExistingFormatterOverrideable return false if it has custom formatter with psi | ||
// returns true even if there is custom formatter | ||
return true; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.