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('}');
|
try buffer.append('}');
|
||||||
if (param_it.peek() != null) {
|
|
||||||
try buffer.appendSlice(", ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
try buffer.append(')');
|
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) {
|
switch (infix_op.op) {
|
||||||
.Period => {
|
.Period => {
|
||||||
var left = resolveTypeOfNode(tree, infix_op.lhs).?;
|
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 => {}
|
else => {}
|
||||||
}
|
}
|
||||||
@ -280,7 +279,7 @@ pub fn getCompletionsFromNode(allocator: *std.mem.Allocator, tree: *std.zig.ast.
|
|||||||
return nodes.items;
|
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) {
|
switch (node.id) {
|
||||||
.ContainerField => {
|
.ContainerField => {
|
||||||
const field = node.cast(std.zig.ast.Node.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).?;
|
const field = node.cast(std.zig.ast.Node.Identifier).?;
|
||||||
return tree.tokenSlice(field.token);
|
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 => {
|
else => {
|
||||||
std.debug.warn("INVALID: {}\n", .{node.id});
|
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 {
|
pub fn nodesToString(tree: *std.zig.ast.Tree, maybe_nodes: ?[]*std.zig.ast.Node) void {
|
||||||
|
10
src/main.zig
10
src/main.zig
@ -315,10 +315,12 @@ fn completeFieldAccess(id: i64, document: *types.TextDocument, position: types.P
|
|||||||
if (analysis.getNodeFromTokens(tree, &tree.root_node.base, &tokenizer)) |node| {
|
if (analysis.getNodeFromTokens(tree, &tree.root_node.base, &tokenizer)) |node| {
|
||||||
var index: usize = 0;
|
var index: usize = 0;
|
||||||
while (node.iterate(index)) |child_node| {
|
while (node.iterate(index)) |child_node| {
|
||||||
try completions.append(.{
|
if (analysis.nodeToString(tree, child_node)) |string| {
|
||||||
.label = analysis.nodeToString(tree, child_node),
|
try completions.append(.{
|
||||||
.kind = .Variable,
|
.label = string,
|
||||||
});
|
.kind = .Variable,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user