@@ -15,10 +15,13 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
15
15
16
16
@ defs [ :def , :defp , :defmacro , :defmacrop , :defguard , :defguardp , :defdelegate ]
17
17
18
- @ docs [
18
+ @ supplementing_attributes [
19
19
:doc ,
20
20
:moduledoc ,
21
- :typedoc
21
+ :typedoc ,
22
+ :spec ,
23
+ :impl ,
24
+ :deprecated
22
25
]
23
26
24
27
@ max_parser_errors 6
@@ -118,14 +121,8 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
118
121
end
119
122
120
123
# Struct and exception
121
- defp extract_symbol ( _module_name , { defname , location , [ properties | _ ] } )
124
+ defp extract_symbol ( module_name , { defname , location , [ properties | _ ] } )
122
125
when defname in [ :defstruct , :defexception ] do
123
- name =
124
- case defname do
125
- :defstruct -> "struct"
126
- :defexception -> "exception"
127
- end
128
-
129
126
children =
130
127
if is_list ( properties ) do
131
128
properties
@@ -135,15 +132,20 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
135
132
[ ]
136
133
end
137
134
138
- % Info { type: :struct , name: name , location: location , children: children }
135
+ % Info {
136
+ type: :struct ,
137
+ name: "#{ defname } #{ module_name } " ,
138
+ location: location ,
139
+ children: children
140
+ }
139
141
end
140
142
141
- # Docs
142
- defp extract_symbol ( _ , { :@ , _ , [ { kind , _ , _ } ] } ) when kind in @ docs , do: nil
143
+ # We skip attributes only supplementoing the symbol
144
+ defp extract_symbol ( _ , { :@ , _ , [ { kind , _ , _ } ] } ) when kind in @ supplementing_attributes , do: nil
143
145
144
146
# Types
145
147
defp extract_symbol ( _current_module , { :@ , _ , [ { type_kind , location , type_expression } ] } )
146
- when type_kind in [ :type , :typep , :opaque , :spec , : callback, :macrocallback ] do
148
+ when type_kind in [ :type , :typep , :opaque , :callback , :macrocallback ] do
147
149
type_name =
148
150
case type_expression do
149
151
[ { :"::" , _ , [ { _ , _ , _ } = type_head | _ ] } ] ->
@@ -158,7 +160,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
158
160
159
161
% Info {
160
162
type: type ,
161
- name: type_name ,
163
+ name: "@ #{ type_kind } #{ type_name } " ,
162
164
location: location ,
163
165
children: [ ]
164
166
}
@@ -168,19 +170,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
168
170
defp extract_symbol ( _current_module , { :@ , _ , [ { :behaviour , location , [ behaviour_expression ] } ] } ) do
169
171
module_name = extract_module_name ( behaviour_expression )
170
172
171
- % Info { type: :constant , name: "@behaviour #{ module_name } " , location: location , children: [ ] }
172
- end
173
-
174
- # @impl true
175
- defp extract_symbol ( _current_module , { :@ , _ , [ { :impl , location , [ true ] } ] } ) do
176
- % Info { type: :constant , name: "@impl true" , location: location , children: [ ] }
177
- end
178
-
179
- # @impl BehaviourModule
180
- defp extract_symbol ( _current_module , { :@ , _ , [ { :impl , location , [ impl_expression ] } ] } ) do
181
- module_name = extract_module_name ( impl_expression )
182
-
183
- % Info { type: :constant , name: "@impl #{ module_name } " , location: location , children: [ ] }
173
+ % Info { type: :interface , name: "@behaviour #{ module_name } " , location: location , children: [ ] }
184
174
end
185
175
186
176
# Other attributes
@@ -217,6 +207,20 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
217
207
}
218
208
end
219
209
210
+ defp extract_symbol (
211
+ _current_module ,
212
+ { { :. , location , [ { :__aliases__ , _ , [ :Record ] } , :defrecord ] } , _ , [ record_name , _ ] }
213
+ ) do
214
+ name = Macro . to_string ( record_name ) |> String . replace ( "\n " , "" )
215
+
216
+ % Info {
217
+ type: :class ,
218
+ name: "defrecord #{ name } " ,
219
+ location: location ,
220
+ children: [ ]
221
+ }
222
+ end
223
+
220
224
# ExUnit test
221
225
defp extract_symbol ( _current_module , { :test , location , [ name | _ ] } ) do
222
226
% Info {
0 commit comments