Skip to content

Commit fc6430f

Browse files
committed
fix crash on invalid typespec
1 parent 13f1a7a commit fc6430f

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
179179
defp extract_symbol(_current_module, {:@, location, [{type_kind, _, type_expression}]})
180180
when type_kind in [:type, :typep, :opaque, :callback, :macrocallback] and
181181
not is_nil(type_expression) do
182-
{type_name, type_head_location} =
182+
type_name_location =
183183
case type_expression do
184184
[{:"::", _, [{_, type_head_location, _} = type_head | _]}] ->
185185
{Macro.to_string(type_head), type_head_location}
@@ -189,22 +189,29 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
189189

190190
[{_, type_head_location, _} = type_head | _] ->
191191
{Macro.to_string(type_head), type_head_location}
192+
193+
_ ->
194+
nil
192195
end
193196

194-
type_name =
195-
type_name
196-
|> String.replace("\n", "")
197+
if type_name_location do
198+
{type_name, type_head_location} = type_name_location
197199

198-
type = if type_kind in [:type, :typep, :opaque], do: :class, else: :event
200+
type_name =
201+
type_name
202+
|> String.replace("\n", "")
199203

200-
%Info{
201-
type: type,
202-
name: "@#{type_kind} #{type_name}",
203-
location: location,
204-
selection_location: type_head_location,
205-
symbol: "#{type_name}",
206-
children: []
207-
}
204+
type = if type_kind in [:type, :typep, :opaque], do: :class, else: :event
205+
206+
%Info{
207+
type: type,
208+
name: "@#{type_kind} #{type_name}",
209+
location: location,
210+
selection_location: type_head_location,
211+
symbol: "#{type_name}",
212+
children: []
213+
}
214+
end
208215
end
209216

210217
# @behaviour BehaviourModule

0 commit comments

Comments
 (0)