generated from redhat-developer/new-project-template
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
565 additions
and
179 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,93 @@ | ||
# LSP server support | ||
|
||
The LSPCustomizedServerSupport API allows customizing the behavior of LSP features to customize: | ||
|
||
* [LSP completion support](#customize-lsp-completion-support) | ||
* [LSP diagnostic support](#customize-lsp-diagnostic-support) | ||
* [LSP formatting support](#customize-lsp-formatting-support) | ||
|
||
These custom supports are done: | ||
|
||
* by extending the default classes `LSPCustomized*Support` (e.g. creating a new class `MyLSPCustomizedFormattingSupport` that extends | ||
[LSPCustomizedFormattingSupport](https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/server/customization/LSPCustomizedFormattingSupport.java) to customize formatting support) | ||
and overriding some methods to customize the behavior. | ||
* registering your custom classes with `LanguageServerFactory#createServerSupport(@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.LSPCustomizedServerSupport; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MyLanguageServerFactory implements LanguageServerFactory { | ||
|
||
@Override | ||
public @NotNull LSPCustomizedServerSupport createServerSupport(@NotNull Project project) { | ||
return new LSPCustomizedServerSupport(project) | ||
.withCompletionSupport(new MyLSPCustomizedCompletionSupport()) // customize LSP completion support | ||
.withDiagnosticSupport(new MyLSPCustomizedDiagnosticSupport()) // customize LSP diagnostic support | ||
.withFormattingSupport(new MyLSPCustomizedFormattingSupport()); // customize LSP formatting support | ||
} | ||
} | ||
``` | ||
|
||
## Customize LSP completion support | ||
|
||
TODO | ||
|
||
## Customize LSP diagnostic support | ||
|
||
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.LSPCustomizedDiagnosticSupport; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class MyLSPCustomizedDiagnosticSupport extends LSPCustomizedDiagnosticSupport { | ||
|
||
@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 support | ||
|
||
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.LSPCustomizedFormattingSupport; | ||
import com.redhat.devtools.lsp4ij.client.features.LSPCustomizedServerSupport; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class MyLSPCustomizedFormattingSupport extends LSPCustomizedFormattingSupport { | ||
|
||
@Override | ||
public boolean canSupportFormatting(@NotNull PsiFile file, boolean hasCustomFormatter) { | ||
// By default, LSPCustomizedFormattingSupport 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
41 changes: 41 additions & 0 deletions
41
src/main/java/com/redhat/devtools/lsp4ij/client/features/AbstractLSPFeature.java
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,41 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.lsp4ij.client.features; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Abstract class for any LSP customization feature support. | ||
*/ | ||
@ApiStatus.Experimental | ||
public abstract class AbstractLSPFeature { | ||
|
||
private LSPServerFeatures serverSupport; | ||
|
||
/** | ||
* Returns the LSP server support. | ||
* | ||
* @return the LSP server support. | ||
*/ | ||
public @NotNull LSPServerFeatures getServerSupport() { | ||
return serverSupport; | ||
} | ||
|
||
/** | ||
* Set the LSP server support. | ||
* | ||
* @param serverSupport the LSP server support. | ||
*/ | ||
public void setServerSupport(@NotNull LSPServerFeatures serverSupport) { | ||
this.serverSupport = serverSupport; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/redhat/devtools/lsp4ij/client/features/LSPCompletionFeature.java
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,21 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, | ||
* and is available at https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package com.redhat.devtools.lsp4ij.client.features; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** | ||
* LSP customization completion support. | ||
*/ | ||
@ApiStatus.Experimental | ||
public class LSPCompletionFeature extends AbstractLSPFeature { | ||
|
||
} |
Oops, something went wrong.