Skip to content

Commit

Permalink
fix(diagnostics): use span field if present
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed Feb 15, 2024
1 parent fd5d76a commit 7d8f2c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions lib/next_ls/extensions/elixir_extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule NextLS.ElixirExtension do
severity: severity(d.severity),
message: IO.iodata_to_binary(d.message),
source: d.compiler_name,
range: range(d.position)
range: range(d.position, Map.get(d, :span))
})
end

Expand All @@ -58,7 +58,7 @@ defmodule NextLS.ElixirExtension do
defp severity(:info), do: GenLSP.Enumerations.DiagnosticSeverity.information()
defp severity(:hint), do: GenLSP.Enumerations.DiagnosticSeverity.hint()

defp range({start_line, start_col, end_line, end_col}) do
defp range({start_line, start_col, end_line, end_col}, _) do
%GenLSP.Structures.Range{
start: %GenLSP.Structures.Position{
line: clamp(start_line - 1),
Expand All @@ -71,7 +71,20 @@ defmodule NextLS.ElixirExtension do
}
end

defp range({line, col}) do
defp range({startl, startc}, {endl, endc}) do
%GenLSP.Structures.Range{
start: %GenLSP.Structures.Position{
line: clamp(startl - 1),
character: startc - 1
},
end: %GenLSP.Structures.Position{
line: clamp(endl - 1),
character: endc - 1
}
}
end

defp range({line, col}, nil) do
%GenLSP.Structures.Range{
start: %GenLSP.Structures.Position{
line: clamp(line - 1),
Expand All @@ -84,7 +97,7 @@ defmodule NextLS.ElixirExtension do
}
end

defp range(line) do
defp range(line, _) do
%GenLSP.Structures.Range{
start: %GenLSP.Structures.Position{
line: clamp(line - 1),
Expand Down
2 changes: 1 addition & 1 deletion test/next_ls/diagnostics_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ defmodule NextLS.DiagnosticsTest do
"variable \"arg1\" is unused (if the variable is not meant to be used, prefix it with an underscore)",
"range" => %{
"start" => %{"line" => 3, "character" => ^char},
"end" => %{"line" => 3, "character" => 999}
"end" => %{"line" => 3, "character" => 14}
}
}
]
Expand Down

0 comments on commit 7d8f2c7

Please sign in to comment.