Skip to content

Commit 7d8f2c7

Browse files
committed
fix(diagnostics): use span field if present
1 parent fd5d76a commit 7d8f2c7

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/next_ls/extensions/elixir_extension.ex

+17-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ defmodule NextLS.ElixirExtension do
4444
severity: severity(d.severity),
4545
message: IO.iodata_to_binary(d.message),
4646
source: d.compiler_name,
47-
range: range(d.position)
47+
range: range(d.position, Map.get(d, :span))
4848
})
4949
end
5050

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

61-
defp range({start_line, start_col, end_line, end_col}) do
61+
defp range({start_line, start_col, end_line, end_col}, _) do
6262
%GenLSP.Structures.Range{
6363
start: %GenLSP.Structures.Position{
6464
line: clamp(start_line - 1),
@@ -71,7 +71,20 @@ defmodule NextLS.ElixirExtension do
7171
}
7272
end
7373

74-
defp range({line, col}) do
74+
defp range({startl, startc}, {endl, endc}) do
75+
%GenLSP.Structures.Range{
76+
start: %GenLSP.Structures.Position{
77+
line: clamp(startl - 1),
78+
character: startc - 1
79+
},
80+
end: %GenLSP.Structures.Position{
81+
line: clamp(endl - 1),
82+
character: endc - 1
83+
}
84+
}
85+
end
86+
87+
defp range({line, col}, nil) do
7588
%GenLSP.Structures.Range{
7689
start: %GenLSP.Structures.Position{
7790
line: clamp(line - 1),
@@ -84,7 +97,7 @@ defmodule NextLS.ElixirExtension do
8497
}
8598
end
8699

87-
defp range(line) do
100+
defp range(line, _) do
88101
%GenLSP.Structures.Range{
89102
start: %GenLSP.Structures.Position{
90103
line: clamp(line - 1),

test/next_ls/diagnostics_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ defmodule NextLS.DiagnosticsTest do
9999
"variable \"arg1\" is unused (if the variable is not meant to be used, prefix it with an underscore)",
100100
"range" => %{
101101
"start" => %{"line" => 3, "character" => ^char},
102-
"end" => %{"line" => 3, "character" => 999}
102+
"end" => %{"line" => 3, "character" => 14}
103103
}
104104
}
105105
]

0 commit comments

Comments
 (0)