Made function snippet generation better.
This commit is contained in:
parent
a2f314301c
commit
aacad999c4
@ -88,22 +88,41 @@ pub fn getFunctionSnippet(allocator: *std.mem.Allocator, tree: *ast.Tree, func:
|
|||||||
var param_it = func.params.iterator(0);
|
var param_it = func.params.iterator(0);
|
||||||
while (param_it.next()) |param_ptr| : (param_num += 1) {
|
while (param_it.next()) |param_ptr| : (param_num += 1) {
|
||||||
const param = param_ptr.*;
|
const param = param_ptr.*;
|
||||||
|
const param_decl = param.cast(ast.Node.ParamDecl).?;
|
||||||
|
|
||||||
if (param_num != 1) try buffer.appendSlice(", ${")
|
if (param_num != 1) try buffer.appendSlice(", ${")
|
||||||
else try buffer.appendSlice("${");
|
else try buffer.appendSlice("${");
|
||||||
|
|
||||||
try buf_stream.print("{}:", .{param_num});
|
try buf_stream.print("{}:", .{param_num});
|
||||||
var curr_tok = param.firstToken();
|
|
||||||
const end_tok = param.lastToken();
|
|
||||||
|
|
||||||
var first_tok = true;
|
if (param_decl.comptime_token) |_| {
|
||||||
|
try buffer.appendSlice("comptime ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param_decl.noalias_token) |_| {
|
||||||
|
try buffer.appendSlice("noalias ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param_decl.name_token) |name_token| {
|
||||||
|
try buffer.appendSlice(tree.tokenSlice(name_token));
|
||||||
|
try buffer.appendSlice(": ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param_decl.var_args_token) |_| {
|
||||||
|
try buffer.appendSlice("...");
|
||||||
|
}
|
||||||
|
|
||||||
|
var curr_tok = param_decl.type_node.firstToken();
|
||||||
|
var end_tok = param_decl.type_node.lastToken();
|
||||||
while (curr_tok <= end_tok) : (curr_tok += 1) {
|
while (curr_tok <= end_tok) : (curr_tok += 1) {
|
||||||
try buffer.appendSlice(tree.tokenSlice(curr_tok));
|
try buffer.appendSlice(tree.tokenSlice(curr_tok));
|
||||||
if (!first_tok and curr_tok != end_tok) try buffer.append(' ')
|
if (tree.tokens.at(curr_tok).id == .Comma) try buffer.append(' ');
|
||||||
else first_tok = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try buffer.append('}');
|
try buffer.append('}');
|
||||||
|
if (param_it.peek() != null) {
|
||||||
|
try buffer.appendSlice(", ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try buffer.append(')');
|
try buffer.append(')');
|
||||||
|
|
||||||
|
@ -253,6 +253,8 @@ fn completeGlobal(id: i64, document: *types.TextDocument, config: Config) !void
|
|||||||
else
|
else
|
||||||
null;
|
null;
|
||||||
|
|
||||||
|
if (insert_text != null) try log("SNIP: {}", .{insert_text});
|
||||||
|
|
||||||
var doc_comments = try analysis.getDocComments(&arena.allocator, tree, decl);
|
var doc_comments = try analysis.getDocComments(&arena.allocator, tree, decl);
|
||||||
var doc = types.MarkupContent{
|
var doc = types.MarkupContent{
|
||||||
.kind = .Markdown,
|
.kind = .Markdown,
|
||||||
|
Loading…
Reference in New Issue
Block a user