Add function completion, fix function snippet generation
This commit is contained in:
parent
7c388812c7
commit
e9b5bf433e
@ -120,9 +120,6 @@ pub fn getFunctionSnippet(allocator: *std.mem.Allocator, tree: *ast.Tree, func:
|
||||
}
|
||||
|
||||
try buffer.append('}');
|
||||
if (param_it.peek() != null) {
|
||||
try buffer.appendSlice(", ");
|
||||
}
|
||||
}
|
||||
try buffer.append(')');
|
||||
|
||||
@ -214,7 +211,9 @@ pub fn resolveTypeOfNode(tree: *std.zig.ast.Tree, node: *std.zig.ast.Node) ?*std
|
||||
switch (infix_op.op) {
|
||||
.Period => {
|
||||
var left = resolveTypeOfNode(tree, infix_op.lhs).?;
|
||||
return getChild(tree, left, nodeToString(tree, infix_op.rhs));
|
||||
if (nodeToString(tree, infix_op.rhs)) |string| {
|
||||
return getChild(tree, left, string);
|
||||
} else return null;
|
||||
},
|
||||
else => {}
|
||||
}
|
||||
@ -280,7 +279,7 @@ pub fn getCompletionsFromNode(allocator: *std.mem.Allocator, tree: *std.zig.ast.
|
||||
return nodes.items;
|
||||
}
|
||||
|
||||
pub fn nodeToString(tree: *std.zig.ast.Tree, node: *std.zig.ast.Node) []const u8 {
|
||||
pub fn nodeToString(tree: *std.zig.ast.Tree, node: *std.zig.ast.Node) ?[]const u8 {
|
||||
switch (node.id) {
|
||||
.ContainerField => {
|
||||
const field = node.cast(std.zig.ast.Node.ContainerField).?;
|
||||
@ -290,12 +289,18 @@ pub fn nodeToString(tree: *std.zig.ast.Tree, node: *std.zig.ast.Node) []const u8
|
||||
const field = node.cast(std.zig.ast.Node.Identifier).?;
|
||||
return tree.tokenSlice(field.token);
|
||||
},
|
||||
.FnProto => {
|
||||
const func = node.cast(std.zig.ast.Node.FnProto).?;
|
||||
if (func.name_token) |name_token| {
|
||||
return tree.tokenSlice(name_token);
|
||||
}
|
||||
},
|
||||
else => {
|
||||
std.debug.warn("INVALID: {}\n", .{node.id});
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn nodesToString(tree: *std.zig.ast.Tree, maybe_nodes: ?[]*std.zig.ast.Node) void {
|
||||
|
@ -315,10 +315,12 @@ fn completeFieldAccess(id: i64, document: *types.TextDocument, position: types.P
|
||||
if (analysis.getNodeFromTokens(tree, &tree.root_node.base, &tokenizer)) |node| {
|
||||
var index: usize = 0;
|
||||
while (node.iterate(index)) |child_node| {
|
||||
if (analysis.nodeToString(tree, child_node)) |string| {
|
||||
try completions.append(.{
|
||||
.label = analysis.nodeToString(tree, child_node),
|
||||
.label = string,
|
||||
.kind = .Variable,
|
||||
});
|
||||
}
|
||||
|
||||
index += 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user