Skip to content

Commit fefefbe

Browse files
committed
fix a few crashes in document symbols
1 parent c3763c1 commit fefefbe

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,20 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
190190

191191
type = if type_kind in [:type, :typep, :opaque], do: :class, else: :event
192192

193+
name_str =
194+
try do
195+
to_string(name)
196+
rescue
197+
_ -> "__unknown__"
198+
end
199+
193200
%Info{
194201
type: type,
195-
name: "#{name}/#{length(args || [])}",
202+
name: "#{name_str}/#{length(args || [])}",
196203
detail: "@#{type_kind}",
197204
location: location,
198205
selection_location: type_head_location,
199-
symbol: to_string(name),
206+
symbol: name_str,
200207
children: []
201208
}
202209
end
@@ -220,10 +227,17 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
220227
{defname, location, [{:when, _, [{name, head_location, args} = _fn_head, _]} | _]}
221228
)
222229
when defname in @defs do
230+
name_str =
231+
try do
232+
to_string(name)
233+
rescue
234+
_ -> "__unknown__"
235+
end
236+
223237
%Info{
224238
type: if(defname in @macro_defs, do: :constant, else: :function),
225-
symbol: to_string(name),
226-
name: "#{to_string(name)}/#{length(args || [])}",
239+
symbol: name_str,
240+
name: "#{name_str}/#{length(args || [])}",
227241
detail: defname,
228242
location: location,
229243
selection_location: head_location,
@@ -237,10 +251,17 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
237251
{defname, location, [{name, head_location, args} = _fn_head | _]}
238252
)
239253
when defname in @defs do
254+
name_str =
255+
try do
256+
to_string(name)
257+
rescue
258+
_ -> "__unknown__"
259+
end
260+
240261
%Info{
241262
type: if(defname in @macro_defs, do: :constant, else: :function),
242-
symbol: to_string(name),
243-
name: "#{to_string(name)}/#{length(args || [])}",
263+
symbol: name_str,
264+
name: "#{name_str}/#{length(args || [])}",
244265
detail: defname,
245266
location: location,
246267
selection_location: head_location,

0 commit comments

Comments
 (0)