Skip to content

Commit a7151bf

Browse files
committed
fix crash when prev_line is out of range
1 parent 824fbe0 commit a7151bf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

apps/language_server/lib/language_server/providers/on_type_formatting.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule ElixirLS.LanguageServer.Providers.OnTypeFormatting do
1313
def format(%SourceFile{} = source_file, line, character, "\n", _options) when line >= 1 do
1414
# we don't care about utf16 positions here as we only pass character back to client
1515
lines = SourceFile.lines(source_file)
16-
prev_line = Enum.at(lines, line - 1)
16+
prev_line = Enum.at(lines, line - 1, "")
1717

1818
prev_tokens = tokens(prev_line)
1919

@@ -49,6 +49,9 @@ defmodule ElixirLS.LanguageServer.Providers.OnTypeFormatting do
4949
{:ok, nil}
5050
end
5151
end
52+
def format(%SourceFile{} = _source_file, _line, _character, _, _options) do
53+
{:ok, nil}
54+
end
5255

5356
# If terminators are already correct, we never want to insert an "end" that would break them.
5457
# If terminators are incorrect, we check if inserting an "end" will fix them.

0 commit comments

Comments
 (0)