Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language Server Syntax Highlights #1985

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

thecoolwinter
Copy link
Collaborator

@thecoolwinter thecoolwinter commented Feb 14, 2025

Description

Adds semantic token syntax highlighting to the code file view.

When an LSP is installed and configured for a language type, and has semantic highlights support, CodeEdit will install a new highlight provider on the source editor and begin processing syntax tokens for the file.

Token processing happens asynchronously, and does not replace tree-sitter highlights. This builds off recent work in the source editor to support a hierarchy of highlight providers. Language server highlights are slow but more accurate, so we process them slowly and apply them when they become available.

Details

  • Adds a new generic 'language server document' protocol that includes only what the language server code needs to know about a code document. This should solve the coupling issue we had with CodeFileDocument and the language server code. In the future, if we replace CodeFileDocument, it'll be a matter of conforming the new type to the protocol for it to work with the lsp code.
  • Reorganizes slightly to group lsp features into their own "Features" folder.
  • Adds a new SemanticTokenHighlightProvider type
    • Conforms to the HighlightProviding protocol.
    • Manages receiving edit notifications from the editor and forwards them to the language server service.
  • Adds a SemanticTokenMap type
    • Maps LSP semantic token data to a format CodeEdit can read.
    • Reads a LSP's capabilities to determine how to decode that data.
  • Adds SemanticTokenStorage
    • Provides an API for applying token deltas, and entire file token data.
    • Manages decoding, re-decoding (when dealing with deltas) and storing semantic tokens.
    • Provides an API for finding semantic tokens quickly.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

Screenshot 2025-02-14 at 10 20 09 AM

Live editing demo, note the highlights on the variable types and switch cases.

CodeEdit.mp4

@thecoolwinter thecoolwinter marked this pull request as ready for review March 15, 2025 14:38
@thecoolwinter thecoolwinter added the language server Issues or Pull Requests related to language servers. label Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request language server Issues or Pull Requests related to language servers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ Semantic Highlights
1 participant