From 498517ba715f7c65c4beb247abb2c9a0d6f12c96 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Fri, 31 Mar 2023 17:38:17 +0200 Subject: [PATCH] replace semantic token type .field with .property --- src/features/semantic_tokens.zig | 17 +++++++++-------- tests/lsp_features/semantic_tokens.zig | 16 ++++++++-------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/features/semantic_tokens.zig b/src/features/semantic_tokens.zig index 0e138d2..a22c305 100644 --- a/src/features/semantic_tokens.zig +++ b/src/features/semantic_tokens.zig @@ -13,7 +13,7 @@ pub const TokenType = enum(u32) { parameter, variable, enumMember, - field, + property, errorTag, function, keyword, @@ -115,7 +115,7 @@ const Builder = struct { .parameter, .variable, .enumMember, - .field, + .property, .errorTag, .function, .label, @@ -162,8 +162,9 @@ fn fieldTokenType(container_decl: Ast.Node.Index, handle: *const DocumentStore.H const main_token = handle.tree.nodes.items(.main_token)[container_decl]; if (main_token > handle.tree.tokens.len) return null; return @as(?TokenType, switch (handle.tree.tokens.items(.tag)[main_token]) { - .keyword_struct => .field, + .keyword_struct => .property, .keyword_union, .keyword_enum => .enumMember, + .keyword_error => .errorTag, else => null, }); } @@ -229,7 +230,7 @@ fn writeNodeTokens(builder: *Builder, node: Ast.Node.Index) error{OutOfMemory}!v .container_field, .container_field_align, .container_field_init, - => try writeContainerField(builder, node, .field), + => try writeContainerField(builder, node, .property), .@"errdefer" => { try writeToken(builder, main_token, .keyword); @@ -253,7 +254,7 @@ fn writeNodeTokens(builder: *Builder, node: Ast.Node.Index) error{OutOfMemory}!v for (statements) |child| { if (node_tags[child].isContainerField()) { - try writeContainerField(builder, child, .field); + try writeContainerField(builder, child, .property); } else { try callWriteNodeTokens(allocator, .{ builder, child }); } @@ -573,8 +574,8 @@ fn writeNodeTokens(builder: *Builder, node: Ast.Node.Index) error{OutOfMemory}!v for (struct_init.ast.fields) |field_init| { const init_token = tree.firstToken(field_init); - try writeToken(builder, init_token - 3, field_token_type orelse .field); // '.' - try writeToken(builder, init_token - 2, field_token_type orelse .field); // name + try writeToken(builder, init_token - 3, field_token_type orelse .property); // '.' + try writeToken(builder, init_token - 2, field_token_type orelse .property); // name try writeToken(builder, init_token - 1, .operator); // '=' try callWriteNodeTokens(allocator, .{ builder, field_init }); } @@ -823,7 +824,7 @@ fn writeNodeTokens(builder: *Builder, node: Ast.Node.Index) error{OutOfMemory}!v const tok_type: ?TokenType = if (ast.isContainer(lhs_type.handle.tree, left_type_node)) fieldTokenType(decl_node, lhs_type.handle) else if (left_type_node == 0) - TokenType.field + .property else null; diff --git a/tests/lsp_features/semantic_tokens.zig b/tests/lsp_features/semantic_tokens.zig index 303e118..4363ec7 100644 --- a/tests/lsp_features/semantic_tokens.zig +++ b/tests/lsp_features/semantic_tokens.zig @@ -516,9 +516,9 @@ test "semantic tokens - struct" { .{ "Foo", .type, .{ .@"struct" = true, .declaration = true } }, .{ "=", .operator, .{} }, .{ "struct", .keyword, .{} }, - .{ "alpha", .field, .{} }, + .{ "alpha", .property, .{} }, .{ "u32", .type, .{} }, - .{ "beta", .field, .{} }, + .{ "beta", .property, .{} }, .{ "void", .type, .{} }, }); try testSemanticTokens( @@ -531,12 +531,12 @@ test "semantic tokens - struct" { .{ "Foo", .type, .{ .@"struct" = true, .declaration = true } }, .{ "=", .operator, .{} }, .{ "struct", .keyword, .{} }, - .{ "alpha", .field, .{} }, + .{ "alpha", .property, .{} }, .{ "u32", .type, .{} }, .{ "=", .operator, .{} }, .{ "3", .number, .{} }, .{ "comptime", .keyword, .{} }, - .{ "beta", .field, .{} }, + .{ "beta", .property, .{} }, .{ "void", .type, .{} }, .{ "=", .operator, .{} }, }); @@ -592,7 +592,7 @@ test "semantic tokens - union" { .{ "=", .operator, .{} }, .{ "union", .keyword, .{} }, .{ "E", .variable, .{} }, - .{ "alpha", .field, .{} }, + .{ "alpha", .property, .{} }, }); try testSemanticTokens( \\const Foo = union(E) { @@ -605,8 +605,8 @@ test "semantic tokens - union" { .{ "=", .operator, .{} }, .{ "union", .keyword, .{} }, .{ "E", .variable, .{} }, - .{ "alpha", .field, .{} }, - .{ "beta", .field, .{} }, + .{ "alpha", .property, .{} }, + .{ "beta", .property, .{} }, .{ "void", .keyword, .{} }, }); try testSemanticTokens( @@ -619,7 +619,7 @@ test "semantic tokens - union" { .{ "=", .operator, .{} }, .{ "union", .keyword, .{} }, .{ "E", .variable, .{} }, - .{ "alpha", .field, .{} }, + .{ "alpha", .property, .{} }, .{ "void", .keyword, .{} }, .{ "align", .keyword, .{} }, .{ "2", .number, .{} },