Skip to content

Commit

Permalink
Do not crash on completions in untitled: schema
Browse files Browse the repository at this point in the history
Fixes #732
  • Loading branch information
lukaszsamson committed Sep 29, 2022
1 parent e95dcc5 commit 65e889a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion apps/language_server/lib/language_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,12 @@ defmodule ElixirLS.LanguageServer.Server do

signature_after_complete = Map.get(state.settings || %{}, "signatureAfterComplete", true)

path =
case uri do
"file:" <> _ -> SourceFile.path_from_uri(uri)
_ -> nil
end

fun = fn ->
Completion.completion(source_file.text, line, character,
snippets_supported: snippets_supported,
Expand All @@ -703,7 +709,7 @@ defmodule ElixirLS.LanguageServer.Server do
signature_help_supported: signature_help_supported,
locals_without_parens: locals_without_parens,
signature_after_complete: signature_after_complete,
file_path: SourceFile.path_from_uri(uri)
file_path: path
)
end

Expand Down
28 changes: 28 additions & 0 deletions apps/language_server/test/providers/completion_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,34 @@ defmodule ElixirLS.LanguageServer.Providers.CompletionTest do
"insertText" => "defmodule $1 do\n\t$0\nend"
} = first
end

test "will suggest defmodule without module_name snippet when file path is nil" do
text = """
defmod
# ^
"""

{line, char} = {0, 6}

TestUtils.assert_has_cursor_char(text, line, char)

assert {:ok, %{"items" => [first | _] = _items}} =
Completion.completion(
text,
line,
char,
@supports
|> Keyword.put(
:file_path,
nil
)
)

assert %{
"label" => "defmodule",
"insertText" => "defmodule $1 do\n\t$0\nend"
} = first
end
end

describe "generic suggestions" do
Expand Down

0 comments on commit 65e889a

Please sign in to comment.