Implement all of the semantic tokens

This commit is contained in:
Luuk de Gram 2021-03-04 22:30:25 +01:00
parent 08075a1261
commit 9224bbd4dc
No known key found for this signature in database
GPG Key ID: A002B174963DBB7D
2 changed files with 544 additions and 373 deletions

View File

@ -30,13 +30,13 @@ pub fn getDocCommentTokenIndex(tree: ast.Tree, node: ast.Node.Index) ?ast.TokenI
idx -= 2; // skip '.' token idx -= 2; // skip '.' token
}, },
else => { else => {
// if (isContainer(tags[node])) { if (isContainer(tags[node])) {
// idx -= 1; // go to '=' idx -= 1; // go to '='
// idx -= 1; // mutability idx -= 1; // mutability
// idx -= 1; // possible 'pub' idx -= 1; // possible 'pub'
// if (tokens[idx] == .keyword_pub and idx > 0) if (tokens[idx] == .keyword_pub and idx > 0)
// idx -= 1; idx -= 1;
// } } else log.debug("Doc comment check for tag: {s}", .{tags[node]});
}, },
} }
@ -187,7 +187,7 @@ pub fn isTypeFunction(tree: ast.Tree, func: ast.full.FnProto) bool {
} }
pub fn isGenericFunction(tree: ast.Tree, func: ast.full.FnProto) bool { pub fn isGenericFunction(tree: ast.Tree, func: ast.full.FnProto) bool {
var it = func.iterate(); var it = func.iterate(tree);
while (it.next()) |param| { while (it.next()) |param| {
if (param.anytype_ellipsis3 != null or param.comptime_noalias != null) { if (param.anytype_ellipsis3 != null or param.comptime_noalias != null) {
return true; return true;
@ -983,7 +983,7 @@ pub const TypeWithHandle = struct {
} }
} }
fn isContainer(self: TypeWithHandle, container_kind_tok: std.zig.Token.Tag, tree: ast.Tree) bool { fn isContainerKind(self: TypeWithHandle, container_kind_tok: std.zig.Token.Tag, tree: ast.Tree) bool {
const main_tokens = tree.nodes.items(.main_token); const main_tokens = tree.nodes.items(.main_token);
const tags = tree.tokens.items(.tag); const tags = tree.tokens.items(.tag);
switch (self.type.data) { switch (self.type.data) {
@ -993,30 +993,33 @@ pub const TypeWithHandle = struct {
} }
pub fn isStructType(self: TypeWithHandle, tree: ast.Tree) bool { pub fn isStructType(self: TypeWithHandle, tree: ast.Tree) bool {
return self.isContainer(.keyword_struct, tree) or self.isRoot(); return self.isContainerKind(.keyword_struct, tree) or self.isRoot();
} }
pub fn isNamespace(self: TypeWithHandle, tree: ast.Tree) bool { pub fn isNamespace(self: TypeWithHandle, tree: ast.Tree) bool {
if (!self.isStructType()) return false; if (!self.isStructType(tree)) return false;
var idx: usize = 0;
// @TODO: FIX ME const node = self.type.data.other;
while (self.type.data.other.iterate(idx)) |child| : (idx += 1) { const tags = tree.nodes.items(.tag);
if (child.tag == .ContainerField) if (isContainer(tags[node])) {
return false; var buf: [2]ast.Node.Index = undefined;
for (declMembers(tree, tags[node], node, &buf)) |child| {
if (tags[child].isContainerField()) return false;
}
} }
return true; return true;
} }
pub fn isEnumType(self: TypeWithHandle, tree: ast.Tree) bool { pub fn isEnumType(self: TypeWithHandle, tree: ast.Tree) bool {
return self.isContainer(.keyword_enum, tree); return self.isContainerKind(.keyword_enum, tree);
} }
pub fn isUnionType(self: TypeWithHandle, tree: ast.Tree) bool { pub fn isUnionType(self: TypeWithHandle, tree: ast.Tree) bool {
return self.isContainer(.keyword_union, tree); return self.isContainerKind(.keyword_union, tree);
} }
pub fn isOpaqueType(self: TypeWithHandle, tree: ast.Tree) bool { pub fn isOpaqueType(self: TypeWithHandle, tree: ast.Tree) bool {
return self.isContainer(.keyword_opaque, tree); return self.isContainerKind(.keyword_opaque, tree);
} }
pub fn isTypeFunc(self: TypeWithHandle, tree: ast.Tree) bool { pub fn isTypeFunc(self: TypeWithHandle, tree: ast.Tree) bool {

File diff suppressed because it is too large Load Diff