Skip to content

Commit e2194c5

Browse files
authored
fix: clamp diagnostic line number to 0 (#116)
1 parent f8a94ec commit e2194c5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Diff for: lib/next_ls/extensions/elixir_extension.ex

+8-6
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ defmodule NextLS.ElixirExtension do
5757
defp range({start_line, start_col, end_line, end_col}) do
5858
%GenLSP.Structures.Range{
5959
start: %GenLSP.Structures.Position{
60-
line: start_line - 1,
60+
line: clamp(start_line - 1),
6161
character: start_col - 1
6262
},
6363
end: %GenLSP.Structures.Position{
64-
line: end_line - 1,
64+
line: clamp(end_line - 1),
6565
character: end_col - 1
6666
}
6767
}
@@ -70,11 +70,11 @@ defmodule NextLS.ElixirExtension do
7070
defp range({line, col}) do
7171
%GenLSP.Structures.Range{
7272
start: %GenLSP.Structures.Position{
73-
line: line - 1,
73+
line: clamp(line - 1),
7474
character: col - 1
7575
},
7676
end: %GenLSP.Structures.Position{
77-
line: line - 1,
77+
line: clamp(line - 1),
7878
character: 999
7979
}
8080
}
@@ -83,13 +83,15 @@ defmodule NextLS.ElixirExtension do
8383
defp range(line) do
8484
%GenLSP.Structures.Range{
8585
start: %GenLSP.Structures.Position{
86-
line: line - 1,
86+
line: clamp(line - 1),
8787
character: 0
8888
},
8989
end: %GenLSP.Structures.Position{
90-
line: line - 1,
90+
line: clamp(line - 1),
9191
character: 999
9292
}
9393
}
9494
end
95+
96+
def clamp(line), do: max(line, 0)
9597
end

0 commit comments

Comments
 (0)