Skip to content

Commit

Permalink
Merge pull request #574 from Techatrix/tokenize-undefined
Browse files Browse the repository at this point in the history
Semantic token for keyword 'undefined'
  • Loading branch information
SuperAuguste authored Aug 5, 2022
2 parents a73c77d + a30d310 commit ea24928
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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.*) {
Expand Down
8 changes: 6 additions & 2 deletions src/semantic_tokens.zig
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,19 @@ 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);
}

if (try analysis.lookupSymbolGlobal(
store,
arena,
handle,
tree.getNodeSource(node),
name,
tree.tokens.items(.start)[main_token],
)) |child| {
if (child.decl.* == .param_decl) {
Expand Down

0 comments on commit ea24928

Please sign in to comment.