@@ -85,10 +85,13 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
85
85
end
86
86
87
87
[ module_expression , [ do: module_body ] ] ->
88
- module_name_location = case module_expression do
89
- { _ , location , _ } -> location
90
- _ -> nil
91
- end
88
+ module_name_location =
89
+ case module_expression do
90
+ { _ , location , _ } -> location
91
+ _ -> nil
92
+ end
93
+
94
+ # TODO extract module name location from Code.Fragment.surround_context?
92
95
{ extract_module_name ( module_expression ) , module_name_location , module_body }
93
96
end
94
97
@@ -156,20 +159,23 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
156
159
defp extract_symbol ( _ , { :@ , _ , [ { kind , _ , _ } ] } ) when kind in @ supplementing_attributes , do: nil
157
160
158
161
# Types
159
- defp extract_symbol ( _current_module , { :@ , location , [ { type_kind , type_head_location , type_expression } ] } )
162
+ defp extract_symbol ( _current_module , { :@ , location , [ { type_kind , _ , type_expression } ] } )
160
163
when type_kind in [ :type , :typep , :opaque , :callback , :macrocallback ] do
161
- type_name =
164
+ { type_name , type_head_location } =
162
165
case type_expression do
163
- [ { :"::" , _ , [ { _ , _ , _ } = type_head | _ ] } ] ->
164
- Macro . to_string ( type_head )
166
+ [ { :"::" , _ , [ { _ , type_head_location , _ } = type_head | _ ] } ] ->
167
+ { Macro . to_string ( type_head ) , type_head_location }
165
168
166
- [ { :when , _ , [ { :"::" , _ , [ { _ , _ , _ } = type_head , _ ] } , _ ] } ] ->
167
- Macro . to_string ( type_head )
169
+ [ { :when , _ , [ { :"::" , _ , [ { _ , type_head_location , _ } = type_head , _ ] } , _ ] } ] ->
170
+ { Macro . to_string ( type_head ) , type_head_location }
168
171
end
172
+
173
+ type_name =
174
+ type_name
169
175
|> String . replace ( "\n " , "" )
170
176
171
177
type = if type_kind in [ :type , :typep , :opaque ] , do: :class , else: :event
172
-
178
+ # TODO no closing metdata in type expressions
173
179
% Info {
174
180
type: type ,
175
181
name: "@#{ type_kind } #{ type_name } " ,
@@ -224,7 +230,8 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
224
230
225
231
defp extract_symbol (
226
232
_current_module ,
227
- { { :. , _ , [ { :__aliases__ , alias_location , [ :Record ] } , :defrecord ] } , location , [ record_name , properties ] }
233
+ { { :. , _ , [ { :__aliases__ , alias_location , [ :Record ] } , :defrecord ] } , location ,
234
+ [ record_name , properties ] }
228
235
) do
229
236
name = Macro . to_string ( record_name ) |> String . replace ( "\n " , "" )
230
237
@@ -293,8 +300,10 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
293
300
keys =
294
301
case config_entry do
295
302
list when is_list ( list ) ->
296
- string_list = list
297
- |> Enum . map_join ( ", " , fn { key , _ } -> Macro . to_string ( key ) end )
303
+ string_list =
304
+ list
305
+ |> Enum . map_join ( ", " , fn { key , _ } -> Macro . to_string ( key ) end )
306
+
298
307
"[#{ string_list } ]"
299
308
300
309
key ->
@@ -362,17 +371,27 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
362
371
{ start_line , start_character } =
363
372
SourceFile . elixir_position_to_lsp ( text , { location [ :line ] , location [ :column ] } )
364
373
365
- { end_line , end_character } = cond do
366
- end_location = location [ :end_of_expression ] ->
367
- SourceFile . elixir_position_to_lsp ( text , { end_location [ :line ] , end_location [ :column ] } )
368
- end_location = location [ :end ] ->
369
- SourceFile . elixir_position_to_lsp ( text , { end_location [ :line ] , end_location [ :column ] + 3 } )
370
- end_location = location [ :closing ] ->
371
- # all closing tags we expect hera are 1 char width
372
- SourceFile . elixir_position_to_lsp ( text , { end_location [ :line ] , end_location [ :column ] + 1 } )
373
- true ->
374
- { start_line , start_character }
375
- end
374
+ { end_line , end_character } =
375
+ cond do
376
+ end_location = location [ :end_of_expression ] ->
377
+ SourceFile . elixir_position_to_lsp ( text , { end_location [ :line ] , end_location [ :column ] } )
378
+
379
+ end_location = location [ :end ] ->
380
+ SourceFile . elixir_position_to_lsp (
381
+ text ,
382
+ { end_location [ :line ] , end_location [ :column ] + 3 }
383
+ )
384
+
385
+ end_location = location [ :closing ] ->
386
+ # all closing tags we expect hera are 1 char width
387
+ SourceFile . elixir_position_to_lsp (
388
+ text ,
389
+ { end_location [ :line ] , end_location [ :column ] + 1 }
390
+ )
391
+
392
+ true ->
393
+ { start_line , start_character }
394
+ end
376
395
377
396
Protocol . range ( start_line , start_character , end_line , end_character )
378
397
end
0 commit comments