From ae5fa110b5b81abf2fbdf7b93569a861a66e7728 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Fri, 31 Mar 2023 20:49:25 +0200 Subject: [PATCH] test and simplify semantic tokens on function call --- src/features/semantic_tokens.zig | 6 ----- tests/lsp_features/semantic_tokens.zig | 36 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/features/semantic_tokens.zig b/src/features/semantic_tokens.zig index 41546bd..0e138d2 100644 --- a/src/features/semantic_tokens.zig +++ b/src/features/semantic_tokens.zig @@ -44,7 +44,6 @@ const Builder = struct { analyser: *Analyser, handle: *const DocumentStore.Handle, previous_source_index: usize = 0, - previous_token: ?Ast.TokenIndex = null, token_buffer: std.ArrayListUnmanaged(u32) = .{}, encoding: offsets.Encoding, limited: bool, @@ -595,11 +594,6 @@ fn writeNodeTokens(builder: *Builder, node: Ast.Node.Index) error{OutOfMemory}!v try writeToken(builder, call.async_token, .keyword); try callWriteNodeTokens(allocator, .{ builder, call.ast.fn_expr }); - if (builder.previous_token) |prev| { - if (prev != ast.lastToken(tree, call.ast.fn_expr) and token_tags[ast.lastToken(tree, call.ast.fn_expr)] == .identifier) { - try writeToken(builder, ast.lastToken(tree, call.ast.fn_expr), .function); - } - } for (call.ast.params) |param| try callWriteNodeTokens(allocator, .{ builder, param }); }, .slice, diff --git a/tests/lsp_features/semantic_tokens.zig b/tests/lsp_features/semantic_tokens.zig index 5200431..303e118 100644 --- a/tests/lsp_features/semantic_tokens.zig +++ b/tests/lsp_features/semantic_tokens.zig @@ -226,6 +226,42 @@ test "semantic tokens - field access" { }); } +test "semantic tokens - call" { + try testSemanticTokens( + \\fn foo() void {} + \\const alpha = foo(); + , &.{ + .{ "fn", .keyword, .{} }, + .{ "foo", .function, .{ .declaration = true } }, + .{ "void", .type, .{} }, + + .{ "const", .keyword, .{} }, + .{ "alpha", .variable, .{ .declaration = true } }, + .{ "=", .operator, .{} }, + .{ "foo", .function, .{} }, + }); + try testSemanticTokens( + \\const ns = struct { + \\ fn foo() void {} + \\}; + \\const alpha = ns.foo(); + , &.{ + .{ "const", .keyword, .{} }, + .{ "ns", .type, .{ .namespace = true, .declaration = true } }, + .{ "=", .operator, .{} }, + .{ "struct", .keyword, .{} }, + .{ "fn", .keyword, .{} }, + .{ "foo", .function, .{ .declaration = true } }, + .{ "void", .type, .{} }, + + .{ "const", .keyword, .{} }, + .{ "alpha", .variable, .{ .declaration = true } }, + .{ "=", .operator, .{} }, + .{ "ns", .type, .{ .namespace = true } }, + .{ "foo", .function, .{} }, + }); +} + test "semantic tokens - catch" { try testSemanticTokens( \\var alpha = a catch b;