From db6407ea3b90068c0aef0ec3402219c87ac7259c Mon Sep 17 00:00:00 2001 From: Vexu Date: Thu, 14 May 2020 19:07:46 +0300 Subject: [PATCH 1/2] implement getDocComments for rest of named nodes with docs --- src/analysis.zig | 57 +++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 0ce83b9..f42aef3 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -30,37 +30,48 @@ pub fn getDocComments(allocator: *std.mem.Allocator, tree: *ast.Tree, node: *ast .FnProto => { const func = node.cast(ast.Node.FnProto).?; if (func.doc_comments) |doc_comments| { - var doc_it = doc_comments.lines.iterator(0); - var lines = std.ArrayList([]const u8).init(allocator); - defer lines.deinit(); - - while (doc_it.next()) |doc_comment| { - _ = try lines.append(std.fmt.trim(tree.tokenSlice(doc_comment.*)[3..])); - } - - return try std.mem.join(allocator, "\n", lines.items); - } else { - return null; + return try collectDocComments(allocator, tree, doc_comments); } }, .VarDecl => { const var_decl = node.cast(ast.Node.VarDecl).?; if (var_decl.doc_comments) |doc_comments| { - var doc_it = doc_comments.lines.iterator(0); - var lines = std.ArrayList([]const u8).init(allocator); - defer lines.deinit(); - - while (doc_it.next()) |doc_comment| { - _ = try lines.append(std.fmt.trim(tree.tokenSlice(doc_comment.*)[3..])); - } - - return try std.mem.join(allocator, "\n", lines.items); - } else { - return null; + return try collectDocComments(allocator, tree, doc_comments); } }, - else => return null + .ContainerField => { + const field = node.cast(ast.Node.ContainerField).?; + if (field.doc_comments) |doc_comments| { + return try collectDocComments(allocator, tree, doc_comments); + } + }, + .ErrorTag => { + const tag = node.cast(ast.Node.ErrorTag).?; + if (tag.doc_comments) |doc_comments| { + return try collectDocComments(allocator, tree, doc_comments); + } + }, + .ParamDecl => { + const param = node.cast(ast.Node.ParamDecl).?; + if (param.doc_comments) |doc_comments| { + return try collectDocComments(allocator, tree, doc_comments); + } + }, + else => {} } + return null; +} + +fn collectDocComments(allocator: *std.mem.Allocator, tree: *ast.Tree, doc_comments: *ast.Node.DocComment) ![]const u8 { + var doc_it = doc_comments.lines.iterator(0); + var lines = std.ArrayList([]const u8).init(allocator); + defer lines.deinit(); + + while (doc_it.next()) |doc_comment| { + _ = try lines.append(std.fmt.trim(tree.tokenSlice(doc_comment.*)[3..])); + } + + return try std.mem.join(allocator, "\n", lines.items); } /// Gets a function signature (keywords, name, return value) From a739bf64994d403ee5143da15f669652c4fdefff Mon Sep 17 00:00:00 2001 From: Vexu Date: Thu, 14 May 2020 19:11:03 +0300 Subject: [PATCH 2/2] implement completion for error sets --- src/analysis.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/analysis.zig b/src/analysis.zig index f42aef3..ac91c62 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -214,6 +214,9 @@ pub fn resolveTypeOfNode(analysis_ctx: *AnalysisContext, node: *ast.Node) ?*ast. const field = node.cast(ast.Node.ContainerField).?; return resolveTypeOfNode(analysis_ctx, field.type_expr orelse return null); }, + .ErrorSetDecl => { + return node; + }, .SuffixOp => { const suffix_op = node.cast(ast.Node.SuffixOp).?; switch (suffix_op.op) { @@ -371,6 +374,10 @@ pub fn nodeToString(tree: *ast.Tree, node: *ast.Node) ?[]const u8 { const field = node.cast(ast.Node.ContainerField).?; return tree.tokenSlice(field.name_token); }, + .ErrorTag => { + const tag = node.cast(ast.Node.ErrorTag).?; + return tree.tokenSlice(tag.name_token); + }, .Identifier => { const field = node.cast(ast.Node.Identifier).?; return tree.tokenSlice(field.token);