diff --git a/src/Server.zig b/src/Server.zig index 57fffb1..833e1ef 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -724,11 +724,8 @@ fn hoverSymbol( doc_str = try analysis.collectDocComments(server.arena.allocator(), handle.tree, doc_comments, hover_kind, false); } - const first_token = param.first_doc_comment orelse - param.comptime_noalias orelse - param.name_token orelse - tree.firstToken(param.type_expr); // extern fn - const last_token = param.anytype_ellipsis3 orelse tree.lastToken(param.type_expr); + const first_token = ast.paramFirstToken(tree, param); + const last_token = ast.paramLastToken(tree, param); const start = offsets.tokenToIndex(tree, first_token); const end = offsets.tokenToLoc(tree, last_token).end; @@ -1052,11 +1049,8 @@ fn declToCompletion(context: DeclToCompletionContext, decl_handle: analysis.Decl else null; - const first_token = param.first_doc_comment orelse - param.comptime_noalias orelse - param.name_token orelse - tree.firstToken(param.type_expr); - const last_token = param.anytype_ellipsis3 orelse tree.lastToken(param.type_expr); + const first_token = ast.paramFirstToken(tree, param); + const last_token = ast.paramLastToken(tree, param); try context.completions.append(allocator, .{ .label = tree.tokenSlice(param.name_token.?), diff --git a/src/ast.zig b/src/ast.zig index 13c55c2..29d433a 100644 --- a/src/ast.zig +++ b/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 { return switch (tree.nodes.items(.tag)[node]) { .container_field => tree.containerField(node),