refactor getting the first & last parameter token into a function
This commit is contained in:
parent
6ff19e8b5f
commit
a8dcb89a81
@ -724,11 +724,8 @@ fn hoverSymbol(
|
|||||||
doc_str = try analysis.collectDocComments(server.arena.allocator(), handle.tree, doc_comments, hover_kind, false);
|
doc_str = try analysis.collectDocComments(server.arena.allocator(), handle.tree, doc_comments, hover_kind, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const first_token = param.first_doc_comment orelse
|
const first_token = ast.paramFirstToken(tree, param);
|
||||||
param.comptime_noalias orelse
|
const last_token = ast.paramLastToken(tree, param);
|
||||||
param.name_token orelse
|
|
||||||
tree.firstToken(param.type_expr); // extern fn
|
|
||||||
const last_token = param.anytype_ellipsis3 orelse tree.lastToken(param.type_expr);
|
|
||||||
|
|
||||||
const start = offsets.tokenToIndex(tree, first_token);
|
const start = offsets.tokenToIndex(tree, first_token);
|
||||||
const end = offsets.tokenToLoc(tree, last_token).end;
|
const end = offsets.tokenToLoc(tree, last_token).end;
|
||||||
@ -1052,11 +1049,8 @@ fn declToCompletion(context: DeclToCompletionContext, decl_handle: analysis.Decl
|
|||||||
else
|
else
|
||||||
null;
|
null;
|
||||||
|
|
||||||
const first_token = param.first_doc_comment orelse
|
const first_token = ast.paramFirstToken(tree, param);
|
||||||
param.comptime_noalias orelse
|
const last_token = ast.paramLastToken(tree, param);
|
||||||
param.name_token orelse
|
|
||||||
tree.firstToken(param.type_expr);
|
|
||||||
const last_token = param.anytype_ellipsis3 orelse tree.lastToken(param.type_expr);
|
|
||||||
|
|
||||||
try context.completions.append(allocator, .{
|
try context.completions.append(allocator, .{
|
||||||
.label = tree.tokenSlice(param.name_token.?),
|
.label = tree.tokenSlice(param.name_token.?),
|
||||||
|
11
src/ast.zig
11
src/ast.zig
@ -896,6 +896,17 @@ pub fn lastToken(tree: Ast, node: Ast.Node.Index) Ast.TokenIndex {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn paramFirstToken(tree: Ast, param: Ast.full.FnProto.Param) Ast.TokenIndex {
|
||||||
|
return param.first_doc_comment orelse
|
||||||
|
param.comptime_noalias orelse
|
||||||
|
param.name_token orelse
|
||||||
|
tree.firstToken(param.type_expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn paramLastToken(tree: Ast, param: Ast.full.FnProto.Param) Ast.TokenIndex {
|
||||||
|
return param.anytype_ellipsis3 orelse tree.lastToken(param.type_expr);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn containerField(tree: Ast, node: Ast.Node.Index) ?Ast.full.ContainerField {
|
pub fn containerField(tree: Ast, node: Ast.Node.Index) ?Ast.full.ContainerField {
|
||||||
return switch (tree.nodes.items(.tag)[node]) {
|
return switch (tree.nodes.items(.tag)[node]) {
|
||||||
.container_field => tree.containerField(node),
|
.container_field => tree.containerField(node),
|
||||||
|
Loading…
Reference in New Issue
Block a user