Skip to content

Commit

Permalink
fix crash when prev_line is out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Feb 24, 2024
1 parent 824fbe0 commit a7151bf
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule ElixirLS.LanguageServer.Providers.OnTypeFormatting do
def format(%SourceFile{} = source_file, line, character, "\n", _options) when line >= 1 do
# we don't care about utf16 positions here as we only pass character back to client
lines = SourceFile.lines(source_file)
prev_line = Enum.at(lines, line - 1)
prev_line = Enum.at(lines, line - 1, "")

prev_tokens = tokens(prev_line)

Expand Down Expand Up @@ -49,6 +49,9 @@ defmodule ElixirLS.LanguageServer.Providers.OnTypeFormatting do
{:ok, nil}
end
end
def format(%SourceFile{} = _source_file, _line, _character, _, _options) do
{:ok, nil}
end

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

0 comments on commit a7151bf

Please sign in to comment.