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

Allow limiting semantic token highlighting to identifiers #338

Closed
Vexu opened this issue Jun 1, 2021 · 2 comments
Closed

Allow limiting semantic token highlighting to identifiers #338

Vexu opened this issue Jun 1, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@Vexu
Copy link
Contributor

Vexu commented Jun 1, 2021

Semantic token highlighting is nice and all but using a syntax file like the one provided by vscode-zig gives much more control. Limiting semantic token highlighting to only identifiers gives the best of both worlds. I think the C/C++ language server does something similar since the result looks much more like my what I was able to achieve with a quick patch.

Zls master version
With patch applied
Quick patch to enable this behavior, not sure how correct this is
diff --git a/src/semantic_tokens.zig b/src/semantic_tokens.zig
index eae2a54..8c813f3 100644
--- a/src/semantic_tokens.zig
+++ b/src/semantic_tokens.zig
@@ -66,6 +66,18 @@ const Builder = struct {
     }
 
     fn add(self: *Builder, token: ast.TokenIndex, token_type: TokenType, token_modifiers: TokenModifiers) !void {
+        switch (token_type) {
+            .type,
+            .parameter,
+            .variable,
+            .enumMember,
+            .field,
+            .errorTag,
+            .function,
+            .label, => {},
+            else => return,
+        }
+
         const tree = self.handle.tree;
         const starts = tree.tokens.items(.start);
         const tags = tree.tokens.items(.tag);
@@ -159,6 +171,18 @@ const Builder = struct {
     }
 
     fn addDirect(self: *Builder, tok_type: TokenType, tok_mod: TokenModifiers, start: usize, length: usize) !void {
+        switch (tok_type) {
+            .type,
+            .parameter,
+            .variable,
+            .enumMember,
+            .field,
+            .errorTag,
+            .function,
+            .label, => {},
+            else => return,
+        }
+
         const delta = offsets.tokenRelativeLocation(
             self.handle.tree,
             self.previous_position,
@SuperAuguste
Copy link
Member

Quite the interesting idea, perhaps worthy of a configuration option :)

@Techatrix
Copy link
Member

implemented by #1064

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants