From ca8ca06da954dff7f2d113ef9030e601e0259e70 Mon Sep 17 00:00:00 2001 From: ikrima Date: Wed, 12 Jan 2022 02:21:03 -0600 Subject: [PATCH] yolo: add type function symbols to outline Questions: - `getDocumentSymbolsInternal`: from looking at the code + cross referencing VSCode Api, looks like its just used to enumerate document symbols (call tree: `documentSymbol()->getDocumentSymbols()->getDocumentSymbolsInternal()`) - sanity check: are there any other places this modification needs to be propogated? - sanity check: specifically so that symbol resolve/rename/goto def/etc aren't broken? - error handling: unsure what the pre/post conditions are of the parse tree when `getDocumentSymbolsInternal` is invoked so there might be superflous guards/checks - any tests to add? --- src/analysis.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/analysis.zig b/src/analysis.zig index 8b35967..f49c584 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -1809,6 +1809,16 @@ fn getDocumentSymbolsInternal(allocator: std.mem.Allocator, tree: Ast, node: Ast if (var_decl.ast.init_node != 0) try addOutlineNodes(allocator, tree, var_decl.ast.init_node, &child_context); } + if (tags[node] == .fn_decl) fn_ch: { + const fn_decl = tree.nodes.items(.data)[node]; + var params: [1]Ast.Node.Index = undefined; + const fn_proto = ast.fnProto(tree, fn_decl.lhs, ¶ms) orelse break :fn_ch; + if (!isTypeFunction(tree, fn_proto)) break :fn_ch; + const ret_stmt = findReturnStatement(tree, fn_proto, fn_decl.rhs) orelse break :fn_ch; + const type_decl = tree.nodes.items(.data)[ret_stmt].lhs; + if (type_decl != 0) + try addOutlineNodes(allocator, tree, type_decl, &child_context); + } break :ch children.items; }, };