Skip to content

Commit

Permalink
fix crash when hover header cannot be formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Oct 24, 2023
1 parent cbdec4b commit 2fb3108
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions apps/language_server/lib/language_server/providers/hover.ex
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do

function_name =
"#{mod_str}.#{fun_str}(#{Enum.join(info.args, ", ")})"
|> Code.format_string!(line_length: 40)
|> to_string
|> format_header

"""
```elixir
Expand Down Expand Up @@ -159,8 +158,7 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do

type_name =
"#{mod_formatted}#{info.type}(#{Enum.join(info.args, ", ")})"
|> Code.format_string!(line_length: 40)
|> to_string
|> format_header

"""
```elixir
Expand Down Expand Up @@ -307,4 +305,15 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do
defp get_metadata_entry_md({key, value}) do
"**#{key}** #{value}"
end

defp format_header(text) do
text
|> Code.format_string!(line_length: 40)
|> to_string
rescue
_ ->
# Code.format_string! can raise SyntaxError e.g.
# for Kernel...(first, last)
text
end
end

0 comments on commit 2fb3108

Please sign in to comment.