Skip to content

LSPClientFeatures support #1419

@angelozerr

Description

@angelozerr

As LSP4E seems very active, I would like to share a feature I’ve implemented in LSP4IJ that provides an extremely simple way to customize LSP server integration and to cleanly check server capabilities.

You can find the LSP client features API here:
https://github.com/redhat-developer/lsp4ij/blob/main/docs/LSPApi.md

This API is very powerful because it allows you to customize almost anything in a clean and structured way. For example, you can disable specific LSP features, override labels returned by the language server, etc.

If a plugin wants to integrate a language server that provides formatting and needs to expose custom UI preferences—for instance, to configure tabSize—it simply has to register a custom LSPClientFeatures with a custom LSPFormattingFeature and override getTabSize so that it retrieves the tab size from the plugin’s UI settings.

If the language server needs to support WSL, the plugin can override URI building to translate WSL paths and generate the correct URI expected by the server.

Each feature implements an isSupported(PsiFile file) method, which relies on server capabilities (both static and dynamic). The codebase is very clear: for example, if you want to see how codelens capability detection is implemented, you can look at LSPCodeLensFeature#isSupported. This method can be overridden if a plugin wants to provide UI settings to enable or disable codelens for a specific language server.

The isSupported method relies on capability registries such as:
https://github.com/redhat-developer/lsp4ij/blob/main/src/main/java/com/redhat/devtools/lsp4ij/server/capabilities/CodeLensCapabilityRegistry.java

These registries extend abstract classes that implement full capability checking according to the LSP specification (documentSelector, filters, etc.), for example:
https://github.com/redhat-developer/lsp4ij/blob/6f41f6d22a7146f31e0218cb459513abd5dc16d3/src/main/java/com/redhat/devtools/lsp4ij/server/capabilities/TextDocumentServerCapabilityRegistry.java#L134

If you like this design (many IntelliJ plugins appreciate this feature), I believe you could reuse a significant part of the code and adapt it for LSP4E.

I simply wanted to share this LSP client features mechanism from LSP4IJ.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions