Skip to content

Fix callback suggestions #359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
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
39 changes: 21 additions & 18 deletions apps/language_server/lib/language_server/providers/completion.ex
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
defp from_completion_item(
%{
type: :callback,
subtype: subtype,
args: args,
spec: spec,
name: name,
summary: summary,
arity: arity,
Expand All @@ -283,13 +283,13 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
context,
options
) do
if (context[:def_before] == :def && String.starts_with?(spec, "@macrocallback")) ||
(context[:def_before] == :defmacro && String.starts_with?(spec, "@callback")) do
if (context[:def_before] == :def && subtype == :macrocallback) ||
(context[:def_before] == :defmacro && subtype == :callback) do
nil
else
def_str =
if context[:def_before] == nil do
if String.starts_with?(spec, "@macrocallback") do
if subtype == :macrocallback do
"defmacro "
else
"def "
Expand All @@ -310,7 +310,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
%__MODULE__{
label: label,
kind: :interface,
detail: "#{origin} callback",
detail: "#{origin} #{subtype}",
documentation: summary,
insert_text: insert_text,
priority: 12,
Expand All @@ -334,21 +334,24 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
context,
options
) do
def_str = if(context[:def_before] == nil, do: "def ")
unless context[:def_before] == :defmacro do
def_str = if(context[:def_before] == nil, do: "def ")

insert_text = def_snippet(def_str, name, args, arity, options)
label = "#{def_str}#{name}/#{arity}"
opts = Keyword.put(options, :with_parens?, true)
insert_text = def_snippet(def_str, name, args, arity, opts)
label = "#{def_str}#{name}/#{arity}"

%__MODULE__{
label: label,
kind: :interface,
detail: "#{origin} protocol function",
documentation: summary,
insert_text: insert_text,
priority: 12,
filter_text: name,
tags: metadata_to_tags(metadata)
}
%__MODULE__{
label: label,
kind: :interface,
detail: "#{origin} protocol function",
documentation: summary,
insert_text: insert_text,
priority: 12,
filter_text: name,
tags: metadata_to_tags(metadata)
}
end
end

defp from_completion_item(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ defmodule ElixirLS.LanguageServer.Providers.ReferencesTest do
[
%{
"range" => %{
"start" => %{"line" => 3, "character" => 4},
"end" => %{"line" => 3, "character" => 12}
"start" => %{"line" => 2, "character" => 4},
"end" => %{"line" => 2, "character" => 12}
},
"uri" => uri
},
%{
"range" => %{
"start" => %{"line" => 5, "character" => 12},
"end" => %{"line" => 5, "character" => 20}
"start" => %{"line" => 4, "character" => 12},
"end" => %{"line" => 4, "character" => 20}
},
"uri" => uri
}
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%{
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"docsh": {:hex, :docsh, "0.7.2", "f893d5317a0e14269dd7fe79cf95fb6b9ba23513da0480ec6e77c73221cae4f2", [:rebar3], [{:providers, "1.8.1", [hex: :providers, repo: "hexpm", optional: false]}], "hexpm", "4e7db461bb07540d2bc3d366b8513f0197712d0495bb85744f367d3815076134"},
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "36484b2b5fd25278086fd3e88f84565011a616fc", []},
"elixir_sense": {:git, "https://github.com/elixir-lsp/elixir_sense.git", "8c82bc726f6f0e33680287ead72390fe4a8a74dd", []},
"erl2ex": {:git, "https://github.com/dazuma/erl2ex.git", "244c2d9ed5805ef4855a491d8616b8842fef7ca4", []},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"forms": {:hex, :forms, "0.0.1", "45f3b10b6f859f95f2c2c1a1de244d63855296d55ed8e93eb0dd116b3e86c4a6", [:rebar3], [], "hexpm", "530f63ed8ed5a171f744fc75bd69cb2e36496899d19dbef48101b4636b795868"},
Expand Down