give tests names in outline

This commit is contained in:
SuperAuguste 2020-05-28 08:41:40 -04:00
parent 0720452217
commit 985a1d6398

View File

@ -189,6 +189,10 @@ pub fn getDeclNameToken(tree: *ast.Tree, node: *ast.Node) ?ast.TokenIndex {
const ident = node.cast(ast.Node.Identifier).?; const ident = node.cast(ast.Node.Identifier).?;
return ident.token; return ident.token;
}, },
.TestDecl => {
const decl = node.cast(ast.Node.TestDecl).?;
return (decl.name.cast(ast.Node.StringLiteral) orelse return null).token;
},
else => {}, else => {},
} }
@ -196,7 +200,11 @@ pub fn getDeclNameToken(tree: *ast.Tree, node: *ast.Node) ?ast.TokenIndex {
} }
fn getDeclName(tree: *ast.Tree, node: *ast.Node) ?[]const u8 { fn getDeclName(tree: *ast.Tree, node: *ast.Node) ?[]const u8 {
return tree.tokenSlice(getDeclNameToken(tree, node) orelse return null); const name = tree.tokenSlice(getDeclNameToken(tree, node) orelse return null);
return switch (node.id) {
.TestDecl => name[1..name.len - 1],
else => name
};
} }
/// Gets the child of node /// Gets the child of node
@ -1048,22 +1056,13 @@ fn addOutlineNodes(allocator: *std.mem.Allocator, children: *std.ArrayList(types
.SwitchCase, .For, .EnumLiteral, .PointerIndexPayload , .StructInitializerDot, .SwitchCase, .For, .EnumLiteral, .PointerIndexPayload , .StructInitializerDot,
.PointerPayload, .While, .Switch, .Else, .BoolLiteral, .NullLiteral, .Defer, .PointerPayload, .While, .Switch, .Else, .BoolLiteral, .NullLiteral, .Defer,
.StructInitializer, .FieldInitializer, .If, .FnProto, .MultilineStringLiteral, .StructInitializer, .FieldInitializer, .If, .FnProto, .MultilineStringLiteral,
.UndefinedLiteral, .VarType => return, .UndefinedLiteral, .VarType, .Block => return,
.ContainerDecl => { .ContainerDecl => {
const decl = child.cast(ast.Node.ContainerDecl).?; const decl = child.cast(ast.Node.ContainerDecl).?;
for (decl.fieldsAndDecls()) |cchild| for (decl.fieldsAndDecls()) |cchild|
try addOutlineNodes(allocator, children, tree, cchild); try addOutlineNodes(allocator, children, tree, cchild);
// _ = try children.append(try getDocumentSymbolsInternal(allocator, tree, cchild));
return;
},
.Block => {
// const block = child.cast(ast.Node.Block).?;
// for (block.statements()) |cchild|
// try addOutlineNodes(allocator, children, tree, cchild);
// _ = try children.append(try getDocumentSymbolsInternal(allocator, tree, cchild));
return; return;
}, },
else => {} else => {}