diff --git a/apps/language_server/lib/language_server/providers/on_type_formatting.ex b/apps/language_server/lib/language_server/providers/on_type_formatting.ex index 8f0315478..b2fa2cbbb 100644 --- a/apps/language_server/lib/language_server/providers/on_type_formatting.ex +++ b/apps/language_server/lib/language_server/providers/on_type_formatting.ex @@ -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) @@ -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.