diff --git a/src/analysis.zig b/src/analysis.zig index ea0b0a4..bfb8e2e 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -627,7 +627,7 @@ fn allDigits(str: []const u8) bool { return true; } -pub fn isTypeIdent(tree: Ast, token_idx: Ast.TokenIndex) bool { +pub fn isTypeIdent(text: []const u8) bool { const PrimitiveTypes = std.ComptimeStringMap(void, .{ .{"isize"}, .{"usize"}, .{"c_short"}, .{"c_ushort"}, @@ -644,7 +644,6 @@ pub fn isTypeIdent(tree: Ast, token_idx: Ast.TokenIndex) bool { .{"anyframe"}, .{"anytype"}, }); - const text = tree.tokenSlice(token_idx); if (PrimitiveTypes.has(text)) return true; if (text.len == 1) return false; if (!(text[0] == 'u' or text[0] == 'i')) return false; @@ -693,7 +692,9 @@ pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAl return try resolveTypeOfNodeInternal(store, arena, value, bound_type_params); }, .identifier => { - if (isTypeIdent(handle.tree, main_tokens[node])) { + const name = tree.getNodeSource(node); + + if (isTypeIdent(name)) { return TypeWithHandle{ .type = .{ .data = .{ .primitive = node }, .is_type_val = true }, .handle = handle, @@ -704,7 +705,7 @@ pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAl store, arena, handle, - tree.getNodeSource(node), + name, starts[main_tokens[node]], )) |child| { switch (child.decl.*) { diff --git a/src/semantic_tokens.zig b/src/semantic_tokens.zig index f756fcc..301458e 100644 --- a/src/semantic_tokens.zig +++ b/src/semantic_tokens.zig @@ -425,7 +425,11 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D try writeToken(builder, node_data[node].rhs, .errorTag); }, .identifier => { - if (analysis.isTypeIdent(tree, main_token)) { + const name = tree.getNodeSource(node); + + if(std.mem.eql(u8,name, "undefined")) { + return try writeToken(builder, main_token, .keywordLiteral); + } else if (analysis.isTypeIdent(name)) { return try writeToken(builder, main_token, .type); } @@ -433,7 +437,7 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D store, arena, handle, - tree.getNodeSource(node), + name, tree.tokens.items(.start)[main_token], )) |child| { if (child.decl.* == .param_decl) {