Skip to content

Commit 1b41c05

Browse files
authored
Guard against sending -1 line or column locations in LSP messages (#558)
1 parent 3645148 commit 1b41c05

File tree

1 file changed

+7
-2
lines changed
  • apps/language_server/lib/language_server/protocol

1 file changed

+7
-2
lines changed

apps/language_server/lib/language_server/protocol/location.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ defmodule ElixirLS.LanguageServer.Protocol.Location do
1717
_ -> SourceFile.path_to_uri(file)
1818
end
1919

20+
# LSP messages are 0 indexed whilst elixir/erlang is 1 indexed.
21+
# Guard against malformed line or column values.
22+
line = max(line - 1, 0)
23+
column = max(column - 1, 0)
24+
2025
%Protocol.Location{
2126
uri: uri,
2227
range: %{
23-
"start" => %{"line" => line - 1, "character" => column - 1},
24-
"end" => %{"line" => line - 1, "character" => column - 1}
28+
"start" => %{"line" => line, "character" => column},
29+
"end" => %{"line" => line, "character" => column}
2530
}
2631
}
2732
end

0 commit comments

Comments
 (0)