Skip to content

Commit

Permalink
chore: bump to 0.7.0 + minor fix for LSP diagnostic feature
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Oct 4, 2024
1 parent 7ba6b28 commit 0dfc9fa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -701,3 +701,7 @@ but you can use your own provider with the `semanticTokensColorsProvider` extens

</extensions>
```

# Customize LSP features

If you need to customize LSP (completion, diagnostics, etc) features please read [LSP API](./LSPApi.md).
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginName=LSP4IJ
pluginRepositoryUrl=https://github.com/redhat-developer/lsp4ij
# SemVer format -> https://semver.org
# NO SPACES AROUND THE EQUALS SIGN!!
pluginVersion=0.6.1-SNAPSHOT
pluginVersion=0.7.0-SNAPSHOT
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild=232
#pluginUntilBuild=233.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@

/**
* LSP diagnostic feature.
* <p>
* The following code snippet demonstrates how to use this class to allow a language server to ignore some LSP diagnostic:
* <pre>{@code
* 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);
* }
* }
* }</pre>
* See the documentation of {@link #getHighlightSeverity(Diagnostic)} for more details.
* <p>
* Additional information is available on <a href="https://github.com/redhat-developer/lsp4ij/blob/main/docs/LSPApi.md#lsp-diagnostic-feature">GitHub</a>
*/
@ApiStatus.Experimental
public class LSPDiagnosticFeature extends AbstractLSPDocumentFeature {
Expand All @@ -51,7 +71,7 @@ public boolean isSupported(@NotNull PsiFile file) {
*/
public void createAnnotation(@NotNull Diagnostic diagnostic,
@NotNull Document document,
List<IntentionAction> fixes,
@NotNull List<IntentionAction> fixes,
@NotNull AnnotationHolder holder) {

// Get the text range from the given LSP diagnostic range.
Expand All @@ -78,7 +98,7 @@ public void createAnnotation(@NotNull Diagnostic diagnostic,
// Create IntelliJ Annotation from the given LSP diagnostic
AnnotationBuilder builder = holder
.newAnnotation(severity, message)
.tooltip(getToolTip(diagnostic))
.tooltip(getTooltip(diagnostic))
.range(range);
if (range.getStartOffset() == range.getEndOffset()) {
// Show the annotation at the end of line.
Expand Down Expand Up @@ -131,7 +151,7 @@ public String getMessage(@NotNull Diagnostic diagnostic) {
* @return the annotation tooltip from the given LSP diagnostic.
*/
@NotNull
public String getToolTip(@NotNull Diagnostic diagnostic) {
public String getTooltip(@NotNull Diagnostic diagnostic) {
// message
StringBuilder tooltip = new StringBuilder("<html>");
tooltip.append(StringUtil.escapeXmlEntities(diagnostic.getMessage()));
Expand Down Expand Up @@ -176,7 +196,7 @@ public String getToolTip(@NotNull Diagnostic diagnostic) {
}

@NotNull
private static String getFileName(Location location) {
private static String getFileName(@NotNull Location location) {
String fileUri = location.getUri();
int index = fileUri.lastIndexOf('/');
String fileName = fileUri.substring(index + 1);
Expand Down

0 comments on commit 0dfc9fa

Please sign in to comment.