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

Semantic highlighting #92

Merged
merged 8 commits into from
Jan 10, 2025
Merged

Semantic highlighting #92

merged 8 commits into from
Jan 10, 2025

Conversation

bentsherman
Copy link
Member

@bentsherman bentsherman commented Jan 8, 2025

Close #8

Semantic tokens are used on top of the syntax highlighting, so the language server need only override tokens which aren't accurately described by the TextMate grammar.

The encoding of semantic tokens is described here

The first pass just tries to provide semantic token types for named symbols like variable/function names. Some things to improve:

  • support the semanticTokens/range LSP request (?)
  • support semantic token deltas on individual text edits (?)
  • add configuration option (is this needed on top of editor option?)
  • preserve CST token ranges in AST (e.g. parameter names)

@bentsherman
Copy link
Member Author

Example before/after with first pass:

Before:
image

After:
image

@bentsherman bentsherman marked this pull request as draft January 8, 2025 18:20
@bentsherman
Copy link
Member Author

bentsherman commented Jan 9, 2025

Second pass:

image

@bentsherman bentsherman marked this pull request as ready for review January 9, 2025 22:12
@bentsherman
Copy link
Member Author

I think this is good enough for a first implementation. It mainly distinguishes variables/properties from functions, and improves highlighting for string interpolations. In the config, it better distinguishes config settings from dynamic expressions and code.

  • It re-uses the textmate grammar's highlighting as much as possible in order to keep it lightweight. I also managed to get by with only a few extra bits of CST metadata for parameter name and include name/alias.

  • Performance impact seems pretty minimal, so I won't worry about making it opt-in right now. But it can be disabled in the settings.json:

    "[nextflow]": {
        "editor.semanticHighlighting.enabled": false
    }
  • LSP range request and deltas for text edits don't seem necessary right now. Will reconsider if performance becomes an issue.

  • Embedded script highlighting and the regex highlighting issue will be addressed separately.

@bentsherman bentsherman merged commit dd1e9b7 into main Jan 10, 2025
1 check passed
@bentsherman bentsherman deleted the semantic-higlighting branch January 10, 2025 19:36
@ewels
Copy link
Member

ewels commented Jan 13, 2025

Awesome! 👏🏻 🎉

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.

Semantic highlighting
2 participants