@@ -11,17 +11,33 @@ const tracy = @import("../tracy.zig");
11
11
const Analyser = @import ("../analysis.zig" );
12
12
const DocumentStore = @import ("../DocumentStore.zig" );
13
13
14
+ pub const GotoKind = enum {
15
+ declaration ,
16
+ definition ,
17
+ type_definition ,
18
+ };
19
+
14
20
pub fn gotoDefinitionSymbol (
15
21
analyser : * Analyser ,
16
22
name_range : types.Range ,
17
23
decl_handle : Analyser.DeclWithHandle ,
18
- resolve_alias : bool ,
24
+ kind : GotoKind ,
19
25
offset_encoding : offsets.Encoding ,
20
26
) error {OutOfMemory }! ? types.DefinitionLink {
21
27
const tracy_zone = tracy .trace (@src ());
22
28
defer tracy_zone .end ();
23
29
24
- const token_handle = try decl_handle .definitionToken (analyser , resolve_alias );
30
+ const token_handle = switch (kind ) {
31
+ .declaration = > try decl_handle .definitionToken (analyser , false ),
32
+ .definition = > try decl_handle .definitionToken (analyser , true ),
33
+ .type_definition = > blk : {
34
+ const resolved_type = try decl_handle .resolveType (analyser ) orelse
35
+ return null ;
36
+
37
+ break :blk resolved_type .typeDefinitionToken () orelse
38
+ return null ;
39
+ },
40
+ };
25
41
const target_range = offsets .tokenToRange (token_handle .handle .tree , token_handle .token , offset_encoding );
26
42
27
43
return types.DefinitionLink {
@@ -37,6 +53,7 @@ pub fn gotoDefinitionLabel(
37
53
arena : std.mem.Allocator ,
38
54
handle : * const DocumentStore.Handle ,
39
55
pos_index : usize ,
56
+ kind : GotoKind ,
40
57
offset_encoding : offsets.Encoding ,
41
58
) error {OutOfMemory }! ? types.DefinitionLink {
42
59
const tracy_zone = tracy .trace (@src ());
@@ -46,15 +63,15 @@ pub fn gotoDefinitionLabel(
46
63
const name_loc = Analyser .identifierLocFromPosition (pos_index , handle ) orelse return null ;
47
64
const name = offsets .locToSlice (handle .text , name_loc );
48
65
const decl = (try Analyser .getLabelGlobal (pos_index , handle , name )) orelse return null ;
49
- return try gotoDefinitionSymbol (analyser , offsets .locToRange (handle .text , name_loc , offset_encoding ), decl , false , offset_encoding );
66
+ return try gotoDefinitionSymbol (analyser , offsets .locToRange (handle .text , name_loc , offset_encoding ), decl , kind , offset_encoding );
50
67
}
51
68
52
69
pub fn gotoDefinitionGlobal (
53
70
analyser : * Analyser ,
54
71
arena : std.mem.Allocator ,
55
72
handle : * const DocumentStore.Handle ,
56
73
pos_index : usize ,
57
- resolve_alias : bool ,
74
+ kind : GotoKind ,
58
75
offset_encoding : offsets.Encoding ,
59
76
) error {OutOfMemory }! ? types.DefinitionLink {
60
77
const tracy_zone = tracy .trace (@src ());
@@ -64,14 +81,15 @@ pub fn gotoDefinitionGlobal(
64
81
const name_loc = Analyser .identifierLocFromPosition (pos_index , handle ) orelse return null ;
65
82
const name = offsets .locToSlice (handle .text , name_loc );
66
83
const decl = (try analyser .getSymbolGlobal (pos_index , handle , name )) orelse return null ;
67
- return try gotoDefinitionSymbol (analyser , offsets .locToRange (handle .text , name_loc , offset_encoding ), decl , resolve_alias , offset_encoding );
84
+ return try gotoDefinitionSymbol (analyser , offsets .locToRange (handle .text , name_loc , offset_encoding ), decl , kind , offset_encoding );
68
85
}
69
86
70
87
pub fn gotoDefinitionEnumLiteral (
71
88
analyser : * Analyser ,
72
89
arena : std.mem.Allocator ,
73
90
handle : * const DocumentStore.Handle ,
74
91
source_index : usize ,
92
+ kind : GotoKind ,
75
93
offset_encoding : offsets.Encoding ,
76
94
) error {OutOfMemory }! ? types.DefinitionLink {
77
95
const tracy_zone = tracy .trace (@src ());
@@ -80,7 +98,7 @@ pub fn gotoDefinitionEnumLiteral(
80
98
const name_loc = Analyser .identifierLocFromPosition (source_index , handle ) orelse return null ;
81
99
const name = offsets .locToSlice (handle .text , name_loc );
82
100
const decl = (try analyser .getSymbolEnumLiteral (arena , handle , source_index , name )) orelse return null ;
83
- return try gotoDefinitionSymbol (analyser , offsets .locToRange (handle .text , name_loc , offset_encoding ), decl , false , offset_encoding );
101
+ return try gotoDefinitionSymbol (analyser , offsets .locToRange (handle .text , name_loc , offset_encoding ), decl , kind , offset_encoding );
84
102
}
85
103
86
104
pub fn gotoDefinitionBuiltin (
@@ -126,7 +144,7 @@ pub fn gotoDefinitionFieldAccess(
126
144
handle : * const DocumentStore.Handle ,
127
145
source_index : usize ,
128
146
loc : offsets.Loc ,
129
- resolve_alias : bool ,
147
+ kind : GotoKind ,
130
148
offset_encoding : offsets.Encoding ,
131
149
) error {OutOfMemory }! ? []const types.DefinitionLink {
132
150
const tracy_zone = tracy .trace (@src ());
@@ -139,7 +157,7 @@ pub fn gotoDefinitionFieldAccess(
139
157
var locs = std .ArrayListUnmanaged (types .DefinitionLink ){};
140
158
141
159
for (accesses ) | access | {
142
- if (try gotoDefinitionSymbol (analyser , offsets .locToRange (handle .text , name_loc , offset_encoding ), access , resolve_alias , offset_encoding )) | l |
160
+ if (try gotoDefinitionSymbol (analyser , offsets .locToRange (handle .text , name_loc , offset_encoding ), access , kind , offset_encoding )) | l |
143
161
try locs .append (arena , l );
144
162
}
145
163
@@ -208,22 +226,22 @@ pub fn goto(
208
226
arena : std.mem.Allocator ,
209
227
handle : * const DocumentStore.Handle ,
210
228
source_index : usize ,
211
- resolve_alias : bool ,
229
+ kind : GotoKind ,
212
230
offset_encoding : offsets.Encoding ,
213
231
) ! ? []const types.DefinitionLink {
214
232
const pos_context = try Analyser .getPositionContext (arena , handle .text , source_index , true );
215
233
var links = std .ArrayListUnmanaged (types .DefinitionLink ){};
216
234
217
235
try links .append (arena , switch (pos_context ) {
218
236
.builtin = > | loc | try gotoDefinitionBuiltin (document_store , handle , loc , offset_encoding ),
219
- .var_access = > try gotoDefinitionGlobal (analyser , arena , handle , source_index , resolve_alias , offset_encoding ),
220
- .field_access = > | loc | return try gotoDefinitionFieldAccess (analyser , arena , handle , source_index , loc , resolve_alias , offset_encoding ),
237
+ .var_access = > try gotoDefinitionGlobal (analyser , arena , handle , source_index , kind , offset_encoding ),
238
+ .field_access = > | loc | return try gotoDefinitionFieldAccess (analyser , arena , handle , source_index , loc , kind , offset_encoding ),
221
239
.import_string_literal ,
222
240
.cinclude_string_literal ,
223
241
.embedfile_string_literal ,
224
242
= > try gotoDefinitionString (document_store , arena , pos_context , handle , offset_encoding ),
225
- .label = > try gotoDefinitionLabel (analyser , arena , handle , source_index , offset_encoding ),
226
- .enum_literal = > try gotoDefinitionEnumLiteral (analyser , arena , handle , source_index , offset_encoding ),
243
+ .label = > try gotoDefinitionLabel (analyser , arena , handle , source_index , kind , offset_encoding ),
244
+ .enum_literal = > try gotoDefinitionEnumLiteral (analyser , arena , handle , source_index , kind , offset_encoding ),
227
245
else = > null ,
228
246
} orelse return null );
229
247
0 commit comments