Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions apps/language_server/lib/language_server/providers/completion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
)
|> maybe_reject_derived_functions(context, options)
|> Enum.map(&from_completion_item(&1, context, options))
|> maybe_add_do(context)
|> maybe_add_do(context, options)
|> maybe_add_keywords(context)
|> Enum.reject(&is_nil/1)
|> sort_items()
Expand Down Expand Up @@ -296,7 +296,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
{:ok, %{"isIncomplete" => is_incomplete(items_json), "items" => items_json}}
end

defp maybe_add_do(completion_items, context) do
defp maybe_add_do(completion_items, context, options) do
hint =
case Regex.scan(~r/(?<=\s|^)[a-z]+$/u, context.text_before_cursor) do
[] -> ""
Expand All @@ -309,7 +309,15 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
kind: :keyword,
detail: "reserved word",
insert_text:
if(String.trim(context.text_after_cursor) == "", do: "do\n $0\nend", else: "do: "),
if String.trim(context.text_after_cursor) == "" do
if Keyword.get(options, :snippets_supported, false) do
"do\n $0\nend"
else
"do"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to return "do\n " here, but I'm not sure - for my use-case (Emacs and lsp-mode) pressing return after plain do automatically inserts matching end, so if elixir-ls returns plain do then I can just press return twice to get the desired result (otherwise I will have to type end manually).

end
else
"do: "
end,
tags: [],
priority: 0,
# force selection over other longer not exact completions
Expand Down
Loading