Skip to content

Commit 1e38db4

Browse files
committed
improvements to document symbols provider
1 parent 7f37d59 commit 1e38db4

File tree

3 files changed

+138
-153
lines changed

3 files changed

+138
-153
lines changed

apps/language_server/lib/language_server/providers/document_symbols.ex

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
1515

1616
@defs [:def, :defp, :defmacro, :defmacrop, :defguard, :defguardp, :defdelegate]
1717

18-
@docs [
18+
@supplementing_attributes [
1919
:doc,
2020
:moduledoc,
21-
:typedoc
21+
:typedoc,
22+
:spec,
23+
:impl,
24+
:deprecated
2225
]
2326

2427
@max_parser_errors 6
@@ -118,14 +121,8 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
118121
end
119122

120123
# Struct and exception
121-
defp extract_symbol(_module_name, {defname, location, [properties | _]})
124+
defp extract_symbol(module_name, {defname, location, [properties | _]})
122125
when defname in [:defstruct, :defexception] do
123-
name =
124-
case defname do
125-
:defstruct -> "struct"
126-
:defexception -> "exception"
127-
end
128-
129126
children =
130127
if is_list(properties) do
131128
properties
@@ -135,15 +132,20 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
135132
[]
136133
end
137134

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+
}
139141
end
140142

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
143145

144146
# Types
145147
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
147149
type_name =
148150
case type_expression do
149151
[{:"::", _, [{_, _, _} = type_head | _]}] ->
@@ -158,7 +160,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
158160

159161
%Info{
160162
type: type,
161-
name: type_name,
163+
name: "@#{type_kind} #{type_name}",
162164
location: location,
163165
children: []
164166
}
@@ -168,19 +170,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
168170
defp extract_symbol(_current_module, {:@, _, [{:behaviour, location, [behaviour_expression]}]}) do
169171
module_name = extract_module_name(behaviour_expression)
170172

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: []}
184174
end
185175

186176
# Other attributes
@@ -217,6 +207,20 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
217207
}
218208
end
219209

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+
220224
# ExUnit test
221225
defp extract_symbol(_current_module, {:test, location, [name | _]}) do
222226
%Info{

apps/language_server/lib/language_server/providers/hover.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do
140140
""
141141
else
142142
s = root_mod_name |> source()
143+
143144
cond do
144145
third_dep?(s, project_dir) -> third_dep_name(s, project_dir)
145146
builtin?(s) -> builtin_dep_name(s)

0 commit comments

Comments
 (0)