Merge pull request #1209 from Vexu/semantic-tokens

Semantic token adjustments
This commit is contained in:
Lee Cannon 2023-05-30 21:24:58 +01:00 committed by GitHub
commit 5d53f0104f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 11 deletions

View File

@ -115,20 +115,36 @@ 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); std.debug.assert(loc.start <= loc.end);
if (loc.start < self.previous_source_index) return; if (loc.start < self.previous_source_index) return;
var token_type = param_token_type;
switch (token_type) { switch (token_type) {
.type, .type,
.parameter,
.variable,
.enumMember, .enumMember,
.property, .property,
.errorTag, .errorTag,
.function, .function,
.label, .namespace,
.@"struct",
.@"enum",
=> {}, => {},
else => if (self.limited) return,
.@"union",
.@"opaque",
=> token_type = .type,
.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]; const delta_text = self.handle.tree.source[self.previous_source_index..loc.start];

View File

@ -568,7 +568,7 @@ test "semantic tokens - union" {
\\const Foo = union {}; \\const Foo = union {};
, &.{ , &.{
.{ "const", .keyword, .{} }, .{ "const", .keyword, .{} },
.{ "Foo", .@"union", .{ .declaration = true } }, .{ "Foo", .type, .{ .declaration = true } },
.{ "=", .operator, .{} }, .{ "=", .operator, .{} },
.{ "union", .keyword, .{} }, .{ "union", .keyword, .{} },
}); });
@ -576,7 +576,7 @@ test "semantic tokens - union" {
\\const Foo = packed union(enum) {}; \\const Foo = packed union(enum) {};
, &.{ , &.{
.{ "const", .keyword, .{} }, .{ "const", .keyword, .{} },
.{ "Foo", .@"union", .{ .declaration = true } }, .{ "Foo", .type, .{ .declaration = true } },
.{ "=", .operator, .{} }, .{ "=", .operator, .{} },
.{ "packed", .keyword, .{} }, .{ "packed", .keyword, .{} },
.{ "union", .keyword, .{} }, .{ "union", .keyword, .{} },
@ -588,7 +588,7 @@ test "semantic tokens - union" {
\\}; \\};
, &.{ , &.{
.{ "const", .keyword, .{} }, .{ "const", .keyword, .{} },
.{ "Foo", .@"union", .{ .declaration = true } }, .{ "Foo", .type, .{ .declaration = true } },
.{ "=", .operator, .{} }, .{ "=", .operator, .{} },
.{ "union", .keyword, .{} }, .{ "union", .keyword, .{} },
.{ "E", .variable, .{} }, .{ "E", .variable, .{} },
@ -601,7 +601,7 @@ test "semantic tokens - union" {
\\}; \\};
, &.{ , &.{
.{ "const", .keyword, .{} }, .{ "const", .keyword, .{} },
.{ "Foo", .@"union", .{ .declaration = true } }, .{ "Foo", .type, .{ .declaration = true } },
.{ "=", .operator, .{} }, .{ "=", .operator, .{} },
.{ "union", .keyword, .{} }, .{ "union", .keyword, .{} },
.{ "E", .variable, .{} }, .{ "E", .variable, .{} },
@ -615,7 +615,7 @@ test "semantic tokens - union" {
\\}; \\};
, &.{ , &.{
.{ "const", .keyword, .{} }, .{ "const", .keyword, .{} },
.{ "Foo", .@"union", .{ .declaration = true } }, .{ "Foo", .type, .{ .declaration = true } },
.{ "=", .operator, .{} }, .{ "=", .operator, .{} },
.{ "union", .keyword, .{} }, .{ "union", .keyword, .{} },
.{ "E", .variable, .{} }, .{ "E", .variable, .{} },
@ -688,7 +688,7 @@ test "semantic tokens - opaque" {
\\const Foo = opaque {}; \\const Foo = opaque {};
, &.{ , &.{
.{ "const", .keyword, .{} }, .{ "const", .keyword, .{} },
.{ "Foo", .@"opaque", .{ .declaration = true } }, .{ "Foo", .type, .{ .declaration = true } },
.{ "=", .operator, .{} }, .{ "=", .operator, .{} },
.{ "opaque", .keyword, .{} }, .{ "opaque", .keyword, .{} },
}); });