From 6471db5274a7757973ffd334ce4f0b53d4ec2030 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Mon, 29 May 2023 01:12:16 +0300 Subject: [PATCH 1/2] exhaustively list semantic token types to exclude --- src/features/semantic_tokens.zig | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/features/semantic_tokens.zig b/src/features/semantic_tokens.zig index b79b090..292f8bd 100644 --- a/src/features/semantic_tokens.zig +++ b/src/features/semantic_tokens.zig @@ -120,15 +120,28 @@ const Builder = struct { if (loc.start < self.previous_source_index) return; switch (token_type) { .type, - .parameter, - .variable, .enumMember, .property, .errorTag, .function, - .label, + .namespace, + .@"struct", + .@"enum", + .@"union", + .@"opaque", => {}, - else => if (self.limited) return, + + .parameter, + .variable, + .keyword, + .comment, + .string, + .number, + .operator, + .builtin, + .label, + .keywordLiteral, + => if (self.limited) return, } const delta_text = self.handle.tree.source[self.previous_source_index..loc.start]; From cda0fd4386e222a11b2fb28c730be74b9d403e5b Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Mon, 29 May 2023 01:17:51 +0300 Subject: [PATCH 2/2] rewrite semantic token types union and opaque as type The default themes on vscode color these the same as all other identifiers. --- src/features/semantic_tokens.zig | 7 +++++-- tests/lsp_features/semantic_tokens.zig | 12 ++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/features/semantic_tokens.zig b/src/features/semantic_tokens.zig index 292f8bd..69671b4 100644 --- a/src/features/semantic_tokens.zig +++ b/src/features/semantic_tokens.zig @@ -115,9 +115,10 @@ const Builder = struct { } } - fn addDirect(self: *Builder, token_type: TokenType, token_modifiers: TokenModifiers, loc: offsets.Loc) error{OutOfMemory}!void { + fn addDirect(self: *Builder, param_token_type: TokenType, token_modifiers: TokenModifiers, loc: offsets.Loc) error{OutOfMemory}!void { std.debug.assert(loc.start <= loc.end); if (loc.start < self.previous_source_index) return; + var token_type = param_token_type; switch (token_type) { .type, .enumMember, @@ -127,9 +128,11 @@ const Builder = struct { .namespace, .@"struct", .@"enum", + => {}, + .@"union", .@"opaque", - => {}, + => token_type = .type, .parameter, .variable, diff --git a/tests/lsp_features/semantic_tokens.zig b/tests/lsp_features/semantic_tokens.zig index 567af1c..8ed7f5a 100644 --- a/tests/lsp_features/semantic_tokens.zig +++ b/tests/lsp_features/semantic_tokens.zig @@ -568,7 +568,7 @@ test "semantic tokens - union" { \\const Foo = union {}; , &.{ .{ "const", .keyword, .{} }, - .{ "Foo", .@"union", .{ .declaration = true } }, + .{ "Foo", .type, .{ .declaration = true } }, .{ "=", .operator, .{} }, .{ "union", .keyword, .{} }, }); @@ -576,7 +576,7 @@ test "semantic tokens - union" { \\const Foo = packed union(enum) {}; , &.{ .{ "const", .keyword, .{} }, - .{ "Foo", .@"union", .{ .declaration = true } }, + .{ "Foo", .type, .{ .declaration = true } }, .{ "=", .operator, .{} }, .{ "packed", .keyword, .{} }, .{ "union", .keyword, .{} }, @@ -588,7 +588,7 @@ test "semantic tokens - union" { \\}; , &.{ .{ "const", .keyword, .{} }, - .{ "Foo", .@"union", .{ .declaration = true } }, + .{ "Foo", .type, .{ .declaration = true } }, .{ "=", .operator, .{} }, .{ "union", .keyword, .{} }, .{ "E", .variable, .{} }, @@ -601,7 +601,7 @@ test "semantic tokens - union" { \\}; , &.{ .{ "const", .keyword, .{} }, - .{ "Foo", .@"union", .{ .declaration = true } }, + .{ "Foo", .type, .{ .declaration = true } }, .{ "=", .operator, .{} }, .{ "union", .keyword, .{} }, .{ "E", .variable, .{} }, @@ -615,7 +615,7 @@ test "semantic tokens - union" { \\}; , &.{ .{ "const", .keyword, .{} }, - .{ "Foo", .@"union", .{ .declaration = true } }, + .{ "Foo", .type, .{ .declaration = true } }, .{ "=", .operator, .{} }, .{ "union", .keyword, .{} }, .{ "E", .variable, .{} }, @@ -688,7 +688,7 @@ test "semantic tokens - opaque" { \\const Foo = opaque {}; , &.{ .{ "const", .keyword, .{} }, - .{ "Foo", .@"opaque", .{ .declaration = true } }, + .{ "Foo", .type, .{ .declaration = true } }, .{ "=", .operator, .{} }, .{ "opaque", .keyword, .{} }, });