@@ -16,80 +16,59 @@ const data = @import("version_data");
1616fn hoverSymbol (
1717 analyser : * Analyser ,
1818 arena : std.mem.Allocator ,
19- decl_handle : Analyser.DeclWithHandle ,
19+ param_decl_handle : Analyser.DeclWithHandle ,
2020 markup_kind : types.MarkupKind ,
21- ) error {OutOfMemory }! ? []const u8 {
22- var doc_strings : std .ArrayList ([]const u8 ) = .empty ;
23- return hoverSymbolRecursive (analyser , arena , decl_handle , markup_kind , & doc_strings , null );
24- }
25-
26- fn hoverSymbolRecursive (
27- analyser : * Analyser ,
28- arena : std.mem.Allocator ,
29- decl_handle : Analyser.DeclWithHandle ,
30- markup_kind : types.MarkupKind ,
31- doc_strings : * std .ArrayList ([]const u8 ),
32- resolved_type_maybe : ? Analyser.Type ,
3321) error {OutOfMemory }! ? []const u8 {
3422 const tracy_zone = tracy .trace (@src ());
3523 defer tracy_zone .end ();
3624
37- const handle = decl_handle .handle ;
38- const tree = handle .tree ;
39- const resolved_type = resolved_type_maybe orelse try decl_handle .resolveType (analyser );
25+ var doc_strings : std .ArrayList ([]const u8 ) = .empty ;
4026
41- if ( try decl_handle . docComments ( arena )) | doc |
42- try doc_strings . append ( arena , doc );
27+ var decl_handle : Analyser.DeclWithHandle = param_decl_handle ;
28+ var maybe_resolved_type = try param_decl_handle . resolveType ( analyser );
4329
44- const def_str = switch (decl_handle .decl ) {
45- .ast_node = > | node | def : {
46- if (try analyser .resolveVarDeclAlias (.{
47- .node_handle = .of (node , handle ),
48- .container_type = decl_handle .container_type ,
49- })) | result | {
50- return try hoverSymbolRecursive (analyser , arena , result , markup_kind , doc_strings , resolved_type );
51- }
30+ while (true ) {
31+ if (try decl_handle .docComments (arena )) | doc_string | {
32+ try doc_strings .append (arena , doc_string );
33+ }
34+ if (decl_handle .decl != .ast_node ) break ;
35+ decl_handle = try analyser .resolveVarDeclAlias (.{
36+ .node_handle = .of (decl_handle .decl .ast_node , decl_handle .handle ),
37+ .container_type = decl_handle .container_type ,
38+ }) orelse break ;
39+ maybe_resolved_type = maybe_resolved_type orelse try decl_handle .resolveType (analyser );
40+ }
5241
53- switch (tree .nodeTag (node )) {
54- .global_var_decl ,
55- .local_var_decl ,
56- .aligned_var_decl ,
57- .simple_var_decl ,
58- = > {
59- const var_decl = tree .fullVarDecl (node ).? ;
60- break :def try Analyser .getVariableSignature (arena , tree , var_decl , true );
61- },
62- .container_field ,
63- .container_field_init ,
64- .container_field_align ,
65- = > {
66- const field = tree .fullContainerField (node ).? ;
67- break :def Analyser .getContainerFieldSignature (tree , field ) orelse return null ;
68- },
69- .fn_proto ,
70- .fn_proto_multi ,
71- .fn_proto_one ,
72- .fn_proto_simple ,
73- .fn_decl ,
74- = > {
75- var buf : [1 ]Ast.Node.Index = undefined ;
76- const fn_proto = tree .fullFnProto (& buf , node ).? ;
77- break :def Analyser .getFunctionSignature (tree , fn_proto );
78- },
79- .test_decl = > {
80- const test_name_token , const test_name = ast .testDeclNameAndToken (tree , node ) orelse return null ;
81- _ = test_name_token ;
82- break :def test_name ;
83- },
84- else = > {
85- return null ;
86- },
87- }
88- },
89- .function_parameter = > | pay | def : {
90- const param = pay .get (tree ).? ;
91- break :def ast .paramSlice (tree , param , false );
42+ const tree = decl_handle .handle .tree ;
43+ const def_str = switch (decl_handle .decl ) {
44+ .ast_node = > | node | switch (tree .nodeTag (node )) {
45+ .global_var_decl ,
46+ .local_var_decl ,
47+ .aligned_var_decl ,
48+ .simple_var_decl ,
49+ = > try Analyser .getVariableSignature (
50+ arena ,
51+ tree ,
52+ tree .fullVarDecl (node ).? ,
53+ true ,
54+ ),
55+ .container_field ,
56+ .container_field_init ,
57+ .container_field_align ,
58+ = > Analyser .getContainerFieldSignature (tree , tree .fullContainerField (node ).? ) orelse return null ,
59+ .fn_proto ,
60+ .fn_proto_multi ,
61+ .fn_proto_one ,
62+ .fn_proto_simple ,
63+ .fn_decl ,
64+ = > def : {
65+ var buf : [1 ]Ast.Node.Index = undefined ;
66+ const fn_proto = tree .fullFnProto (& buf , node ).? ;
67+ break :def Analyser .getFunctionSignature (tree , fn_proto );
68+ },
69+ else = > unreachable ,
9270 },
71+ .function_parameter = > | payload | ast .paramSlice (tree , payload .get (tree ).? , false ),
9372 .optional_payload ,
9473 .error_union_payload ,
9574 .error_union_error ,
@@ -107,8 +86,8 @@ fn hoverSymbolRecursive(
10786 arena ,
10887 def_str ,
10988 markup_kind ,
110- doc_strings ,
111- resolved_type ,
89+ & doc_strings ,
90+ maybe_resolved_type ,
11291 );
11392}
11493
0 commit comments