redhat-developer / redhat-developer/lsp4ij

Ctrl+hover underline ignores LocationLink.originSelectionRange for TextMate-backed file types (whole document underlined)

Open
#1,612 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
344
Forks
113
Avg merge
5h 22m
Merged PRs (30d)
15

Description

LSP4IJ version: 0.20.1 (current latest)
IDE: IntelliJ Platform 2024.3 baseline (IntelliJ IDEA CE)
Client plugin setup: a thin LSP client plugin that registers a plain FileType (no com.intellij.lang.Language), TextMate-based highlighting, and maps documents to the server via <fileTypeMapping fileType="..." serverId="..." languageId="..."/>.

What happens

Ctrl/Cmd+hover over an identifier underlines the entire document instead of the identifier. Ctrl/Cmd+click navigation itself lands on the correct target — only the underlined span is wrong.

What the server sends

The client advertises textDocument.definition.linkSupport, and the server answers LocationLink with a precise originSelectionRange (the span the spec designates as "the underlined span for mouse interaction"). Trace from the LSP4IJ console:

[Trace] Sending request 'textDocument/definition - (498)'.
Params: { "textDocument": { "uri": "file:///.../check.pma" },
          "position": { "line": 11, "character": 18 } }

[Trace] Received response 'textDocument/definition - (498)' in 0ms.
Result: [
  {
    "originSelectionRange": { "start": { "line": 11, "character": 16 },
                              "end":   { "line": 11, "character": 20 } },
    "targetUri": "file:///.../check.pma",
    "targetRange":          { "start": { "line": 0, "character": 6 },
                              "end":   { "line": 0, "character": 10 } },
    "targetSelectionRange": { "start": { "line": 0, "character": 6 },
                              "end":   { "line": 0, "character": 10 } }
  }
]

The origin range covers exactly the 4-character identifier under the mouse.

Expected

The Ctrl+hover underline covers originSelectionRange (11:16–11:20 here), not the whole file. For contrast, VS Code's client renders the identical response with a word-precise underline.

Likely mechanism

For a file type backed only by TextMate (no registered Language), the PSI is a single plain-text element, so any element-range fallback degrades to the whole document. Since the LSP response already carries the correct span in originSelectionRange, using it for the underline would fix TextMate/plaintext-backed servers without any client-side lexing.

The server here is pmt lsp from https://github.com/mellonis/machine-toolchains — happy to provide more traces or test builds.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Ctrl/Cmd-hover definition-navigation path for LocationLink handling, then inspect how originSelectionRange is chosen for plain FileType/TextMate documents. Reproduce with the pmt lsp setup and verify that the underline uses the four-character range in the supplied trace rather than the whole document.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.