@@ -8,6 +8,10 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
8
8
alias ElixirLS.LanguageServer.Providers.SymbolUtils
9
9
alias ElixirLS.LanguageServer.Protocol
10
10
11
+ defmodule Info do
12
+ defstruct [ :type , :name , :location , :children ]
13
+ end
14
+
11
15
@ defs [ :def , :defp , :defmacro , :defmacrop , :defguard , :defguardp , :defdelegate ]
12
16
13
17
@ docs [
@@ -95,7 +99,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
95
99
:defprotocol -> :interface
96
100
end
97
101
98
- % { type: type , name: module_name , location: location , children: module_symbols }
102
+ % Info { type: type , name: module_name , location: location , children: module_symbols }
99
103
end
100
104
101
105
# Protocol implementations
@@ -128,7 +132,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
128
132
[ ]
129
133
end
130
134
131
- % { type: :struct , name: name , location: location , children: children }
135
+ % Info { type: :struct , name: name , location: location , children: children }
132
136
end
133
137
134
138
# Docs
@@ -148,7 +152,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
148
152
149
153
type = if type_kind in [ :type , :typep , :opaque ] , do: :class , else: :event
150
154
151
- % {
155
+ % Info {
152
156
type: type ,
153
157
name: type_name ,
154
158
location: location ,
@@ -160,40 +164,42 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
160
164
defp extract_symbol ( _current_module , { :@ , _ , [ { :behaviour , location , [ behaviour_expression ] } ] } ) do
161
165
module_name = extract_module_name ( behaviour_expression )
162
166
163
- % { type: :constant , name: "@behaviour #{ module_name } " , location: location , children: [ ] }
167
+ % Info { type: :constant , name: "@behaviour #{ module_name } " , location: location , children: [ ] }
164
168
end
165
169
166
170
# @impl true
167
171
defp extract_symbol ( _current_module , { :@ , _ , [ { :impl , location , [ true ] } ] } ) do
168
- % { type: :constant , name: "@impl true" , location: location , children: [ ] }
172
+ % Info { type: :constant , name: "@impl true" , location: location , children: [ ] }
169
173
end
170
174
171
175
# @impl BehaviourModule
172
176
defp extract_symbol ( _current_module , { :@ , _ , [ { :impl , location , [ impl_expression ] } ] } ) do
173
177
module_name = extract_module_name ( impl_expression )
174
178
175
- % { type: :constant , name: "@impl #{ module_name } " , location: location , children: [ ] }
179
+ % Info { type: :constant , name: "@impl #{ module_name } " , location: location , children: [ ] }
176
180
end
177
181
178
182
# Other attributes
179
183
defp extract_symbol ( _current_module , { :@ , _ , [ { name , location , _ } ] } ) do
180
- % { type: :constant , name: "@#{ name } " , location: location , children: [ ] }
184
+ % Info { type: :constant , name: "@#{ name } " , location: location , children: [ ] }
181
185
end
182
186
183
187
# Function, macro, guard, delegate
184
188
defp extract_symbol ( _current_module , { defname , _ , [ { _ , location , _ } = fn_head | _ ] } )
185
189
when defname in @ defs do
186
- % {
190
+ name = Macro . to_string ( fn_head )
191
+
192
+ % Info {
187
193
type: :function ,
188
- name: Macro . to_string ( fn_head ) ,
194
+ name: " #{ defname } #{ name } " ,
189
195
location: location ,
190
196
children: [ ]
191
197
}
192
198
end
193
199
194
200
# ExUnit test
195
201
defp extract_symbol ( _current_module , { :test , location , [ name | _ ] } ) do
196
- % {
202
+ % Info {
197
203
type: :function ,
198
204
name: ~s( test "#{ name } ") ,
199
205
location: location ,
@@ -204,7 +210,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
204
210
# ExUnit setup and setup_all callbacks
205
211
defp extract_symbol ( _current_module , { name , location , [ _name | _ ] } )
206
212
when name in [ :setup , :setup_all ] do
207
- % {
213
+ % Info {
208
214
type: :function ,
209
215
name: "#{ name } " ,
210
216
location: location ,
@@ -227,7 +233,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
227
233
|> Enum . map ( & extract_symbol ( current_module , & 1 ) )
228
234
|> Enum . reject ( & is_nil / 1 )
229
235
230
- % {
236
+ % Info {
231
237
type: :function ,
232
238
name: ~s( describe "#{ name } ") ,
233
239
location: location ,
@@ -249,7 +255,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
249
255
end
250
256
251
257
for key <- keys do
252
- % {
258
+ % Info {
253
259
type: :key ,
254
260
name: "config :#{ app } #{ key } " ,
255
261
location: location ,
@@ -263,7 +269,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
263
269
defp build_symbol_information_hierarchical ( uri , info ) when is_list ( info ) ,
264
270
do: Enum . map ( info , & build_symbol_information_hierarchical ( uri , & 1 ) )
265
271
266
- defp build_symbol_information_hierarchical ( uri , info ) do
272
+ defp build_symbol_information_hierarchical ( uri , % Info { } = info ) do
267
273
% Protocol.DocumentSymbol {
268
274
name: info . name ,
269
275
kind: SymbolUtils . symbol_kind_to_code ( info . type ) ,
@@ -278,7 +284,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
278
284
defp build_symbol_information_flat ( uri , info , parent_name ) when is_list ( info ) ,
279
285
do: Enum . map ( info , & build_symbol_information_flat ( uri , & 1 , parent_name ) )
280
286
281
- defp build_symbol_information_flat ( uri , info , parent_name ) do
287
+ defp build_symbol_information_flat ( uri , % Info { } = info , parent_name ) do
282
288
case info . children do
283
289
[ _ | _ ] ->
284
290
[
@@ -346,7 +352,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
346
352
defp extract_module_name ( _ ) , do: "# unknown"
347
353
348
354
defp extract_property ( property_name , location ) when is_atom ( property_name ) do
349
- % {
355
+ % Info {
350
356
type: :property ,
351
357
name: "#{ property_name } " ,
352
358
location: location ,
0 commit comments