Skip to content

Commit

Permalink
fix crash on invalid diagnostic severity
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Feb 27, 2024
1 parent a7151bf commit 586a935
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
23 changes: 19 additions & 4 deletions apps/language_server/lib/language_server/diagnostics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
from various sources
"""
alias ElixirLS.LanguageServer.{SourceFile, JsonRpc}
require Logger

@enforce_keys [:file, :severity, :message, :position, :compiler_name]
defstruct [
Expand Down Expand Up @@ -314,10 +315,24 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
for %__MODULE__{} = diagnostic <- uri_diagnostics do
severity =
case diagnostic.severity do
:error -> 1
:warning -> 2
:information -> 3
:hint -> 4
:error ->
1

:warning ->
2

:information ->
3

:hint ->
4

other ->
Logger.warn(
"Invalid severity on diagnostic: #{inspect(other)}, using warning level"
)

2
end

%{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ defmodule ElixirLS.LanguageServer.Providers.OnTypeFormatting do
{:ok, nil}
end
end

def format(%SourceFile{} = _source_file, _line, _character, _, _options) do
{:ok, nil}
end
Expand Down

0 comments on commit 586a935

Please sign in to comment.