Skip to content

feat: textDocument/highlight#1262

Open
shilangyu wants to merge 9 commits into
rocq-prover:mainfrom
shilangyu:mw/simple-highlight
Open

feat: textDocument/highlight#1262
shilangyu wants to merge 9 commits into
rocq-prover:mainfrom
shilangyu:mw/simple-highlight

Conversation

@shilangyu

Copy link
Copy Markdown
Contributor

This LSP request sends a cursor position and expects a list of ranges to be returned that should be highlighted. Usually, LSPs return highlights that correspond to the items semantically equal to the item at the cursor. VsCode sends the textDocument/highlight request every time the cursor moves. If an LSP does not implement this request, by default VsCode will highlight all words in the file that are the same as the word under the cursor. This PR improves on this default behavior by:

  1. Disabling this feature in irrelevant contexts (such as comments and string literals)
  2. Disabling this for keywords
  3. Taking into account Rocq's lexical analysis

I similarly disabled hover and jump to definition in irrelevant contexts (you were able to jump to definition/hover on things in prose of comments and string literals!).

Nr. 3 means that we now properly see e and e' as two different tokens. The default vscode behavior led to the very annoying highlight of unrelated identifiers:
image

Now, things are properly distinguished:

image

As future work, it would be better to extend highlight to actual semantic reasoning, not only syntactic.

@shilangyu

Copy link
Copy Markdown
Contributor Author

I don't understand what the CI error is

@gares

gares commented Jun 14, 2026

Copy link
Copy Markdown
Member

Failure seems unrelated

@gares

gares commented Jun 14, 2026

Copy link
Copy Markdown
Member

Thanks, it looks interesting.
I think there is still a flaw in the sense that let e := ... in let e := ... in e would not properly handle shadowing, but for that one needs a data that is not available yet, the so called glob_term.

I wonder if we could, one day, provide more info, like the type of the selected expression.

@shilangyu

Copy link
Copy Markdown
Contributor Author

Thank you for having a look!

I think there is still a flaw in the sense that let e := ... in let e := ... in e would not properly handle shadowing

Yeah, we could try to syntactically differentiate those two es, but that would replicate a lot of logic which would be better to get from some semantic information about these es anyway. I see the current implementation as an incremental improvement over VsCode's default behavior (which would fail here too).

the so called glob_term.

What is that and how would it improve the situation?

@gares

gares commented Jun 14, 2026

Copy link
Copy Markdown
Member

Rocq does a few passes on the ast, and glob_terms do most of the work about binders & co.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants