Skip to content

Latest commit

 

History

History
396 lines (264 loc) · 29.6 KB

LSPSupport.md

File metadata and controls

396 lines (264 loc) · 29.6 KB

LSP support

The current implementation of LSP4IJ does not yet fully adhere to the LSP (Language Server Protocol) specification. This section provides an overview of the supported LSP features for IntelliJ:

Base support

Current state of Base protocol support:

Text Document Synchronization

Current state of Text Document Synchronization support:

Notebooks are not supported.

Language Features

Current state of Language Features support:

Workspace Features

Current state of Workspace Features support:

Window Features

Current state of Window Features support

Implementation details

Progress support

$/progress is implemented with Background Tasks.

Here a sample with Eclipse JDT Language Server:

$/progress

Go to Definition

textDocument/definition is implemented via the
gotoDeclarationHandler extension point. As this extension point supports any language, it works out-of-the-box.

It is also called via Find Usages to show definitions.

References

The textDocument/references is consumed with:

  • the Navigate / LSP Reference(s) global menu.
  • or with the Go To/ LSP Reference(s) editor menu.

textDocument/references menu

This menu action either opens the reference in a popup or navigates to the reference if there are several references:

textDocument/implementation popup

textDocument/references is used too via Find Usages to show references.

Implementation

The textDocument/implementation is consumed with:

  • the Navigate / LSP Implementation(s) global menu.
  • or with the Go To/ LSP Implementation(s) editor menu.

textDocument/implementation menu

This menu action either opens the implementation in a popup or navigates to the implementation if there are several implementations:

textDocument/implementation popup

textDocument/implementation is too used via Find Usages to show implementations.

Type definition

The textDocument/typeDefinition is consumed with:

  • the Navigate / LSP Type Definition(s) global menu.
  • or with the Go To/ Type Definition(s) editor menu.

This menu action either opens the type definition in a popup or navigates to the type definition if there are several type definitions:

textDocument/typeDefinition is used too via Find Usages to show Type definitions.

Declaration

The textDocument/declaration is consumed with:

  • the Navigate / LSP Declaration(s) global menu.
  • or with the Go To/ Declaration(s) editor menu.

This menu action either opens the declaration in a popup or navigates to the declaration if there are several declarations:

textDocument/declaration is used too via Find Usages to show declarations.

Document Highlight

textDocument/documentHighlight is implemented via the highlightUsagesHandlerFactory extension point. As this extension point supports any language, it works out-of-the-box.

Here is an example with the Qute language server, highlighting item variables:

textDocument/documentHighlight

Document Link

textDocument/documentLink is implemented via:

  • an externalAnnotator extension point, to display a documentLink with an hyperlink renderer.
  • a gotoDeclarationHandler extension point, to open the file of the documentLink.`

As those extension points support any language, textDocument/documentLink works out-of-the-box.

Here is an example with the Qute language server, displaying an include template with an hyperlink renderer (Ctrl+Click opens the document link):

textDocument/documentLink

Hover

textDocument/hover is implemented with platform.backend.documentation.targetProvider extension point to support any language and textDocument/hover works out-of-the-box.

Here is an example with the Qute language server showing documentation while hovering over an include section:

textDocument/hover

CodeLens

textDocument/codeLens is implemented with the codeInsight.codeVisionProvider extension point. As LSP4IJ registers LSPCodeLensProvider for all languages associated with a language server, it works out-of-the-box.

Here is an example with the Qute language server, which shows REST services URL with codeLens:

textDocument/codeLens

InlayHint

textDocument/inlayHint is implemented with the codeInsight.inlayProvider extension point. LSP4IJ registers LSPInlayHintProvider for all languages associated with a language server with LSPInlayHintProvidersFactory, so it works out-of-the-box.

Here is an example with the Qute language server showing the parameter's Java type as inlay hint:

textDocument/inlayHint

DocumentColor

textDocument/documentColor is implemented with the codeInsight.inlayProvider extension point. LSP4IJ registers LSPColorProvider for all languages associated with a language server with LSPInlayHintProvidersFactory, so it works out-of-the-box.

Here is an example with the CSS language server showing the color's declaration with a colored square:

textDocument/documentColor

Completion Proposals

textDocument/completion is implemented with LSPCompletionContributor class declared with the completion.contributor extension point. As this extension point supports any language, it works out-of-the-box.

Here is an example with the Qute language server showing method completion:

textDocument/completion

Completion item resolve

The completionItem/resolve request is implemented to resolve:

  • the documentation property of a completionItem.

Here a sample with TypeScript Language Server completion item which resolves and shows documentation when the completion item is selected:

completionItem/resolve/documentation

  • the detail property of a completionItem.

Here a sample with TypeScript Language Server completion item which resolves and shows detail when the completion item is selected:

completionItem/resolve/detail

  • the additionalTextEdits property of a completionItem.

Signature Help

textDocument/signatureHelp is implemented with the codeInsight.parameterInfo extension point. By default, LSP4IJ registers the codeInsight.parameterInfo with LSPParameterInfoHandler class for TEXT and textmate languages:

<!-- LSP textDocument/signatureHelp -->
<codeInsight.parameterInfo
        id="LSPParameterInfoHandlerForTEXT"
        language="TEXT"
        implementationClass="com.redhat.devtools.lsp4ij.features.signatureHelp.LSPParameterInfoHandler"/>

<codeInsight.parameterInfo
id="LSPParameterInfoHandlerForTextMate"
language="textmate"
implementationClass="com.redhat.devtools.lsp4ij.features.signatureHelp.LSPParameterInfoHandler"/>

If you use another language, you will have to declare codeInsight.parameterInfo with your language.

Here is an example with the TypeScript Language Server showing signature help:

textDocument/signatureHelp

Folding range

textDocument/foldingRange is implemented with the lang.foldingBuilder extension point. By default, LSP4IJ registers the lang.foldingBuilder with LSPFoldingRangeBuilder class for TEXT and textmate languages:

<!-- LSP textDocument/folding -->
<lang.foldingBuilder id="LSPFoldingBuilderForText"
                     language="TEXT"
                     implementationClass="com.redhat.devtools.lsp4ij.features.foldingRange.LSPFoldingRangeBuilder"
                     order="first"/>

<lang.foldingBuilder id="LSPFoldingBuilderForTextMate"
                     language="textmate"
                     implementationClass="com.redhat.devtools.lsp4ij.features.foldingRange.LSPFoldingRangeBuilder"
                     order="first"/>

If you use another language, you will have to declare lang.foldingBuilder with your language.

Here is an example with the Go Language Server showing folding:

textDocument/foldingRange

Publish Diagnostics

textDocument/publishDiagnostics is implemented with an externalAnnotator extension point. As this extension point supports any language, it works out-of-the-box.

Here is an example with the Qute language server reporting errors:

textDocument/publishDiagnostics

Code Action

Here is an example featuring the Clojure LSP, which offers code actions:

  • Quickfix code action (at the top): This type of code action is facilitated by registering a quick fix within the IntelliJ annotation.
  • Other code actions such as refactoring (at the bottom): These kinds of code actions are handled using Intentions.

textDocument/codeAction

For the last type of code action, you can enable/disable them using the Intentions / Language Server preference setting.

Language Server Intentions

Rename

textDocument/rename is implemented with LSPRenameHandler class declared with the renameHandler extension point.

Here is an example with the TypeScript Language Server showing rename of function name:

textDocument/rename

Formatting

textDocument/formatting / textDocument/rangeFormatting are implemented with LSPFormattingOnlyService / LSPFormattingAndRangeBothService with the formattingService extension point.

Show Message

window/showMessage supports Markdown messages and clickable links.

Here is an example with Rust Analyzer reporting an error:

{
  "type": 1,
  "message": "Failed to discover workspace.\nConsider adding the `Cargo.toml` of the workspace to the [`linkedProjects`](https://rust-analyzer.github.io/manual.html#rust-analyzer.linkedProjects) setting.\n\nFailed to load workspaces."
}

is rendered as a Balloon notification:

window/showMessage

You can change the notification behavior of LSP/window/showMessage by using the standard UI Notifications preferences :

window/showMessage Notification

Show Message Request

window/showMessageRequest is supported.

Here is an example with Scala Language Server (MetaLS) reporting a message request:

{
  "actions": [
    {
      "title": "Create .scalafmt.conf"
    },
    {
      "title": "Run anyway"
    },
    {
      "title": "Not now"
    }
  ],
  "type": 1,
  "message": "No .scalafmt.conf file detected. How would you like to proceed:"
}

is rendered as a Sticky balloon notification:

window/showMessageRequest

You can change the notification behavior of LSP/window/showMessageRequest by using the standard UI Notifications preferences :

window/showMessageRequest Notification