Skip to content

Commit b442cf8

Browse files
committed
make completion kinds and document symbol kinds consistent with workspace symbols
this adds visual distinction between functions and macros in completions (at least in VSCode)
1 parent 89ec9e1 commit b442cf8

File tree

4 files changed

+68
-49
lines changed

4 files changed

+68
-49
lines changed

apps/language_server/lib/language_server/providers/completion.ex

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
1212
import ElixirLS.LanguageServer.Protocol, only: [range: 4]
1313
alias ElixirSense.Providers.Suggestion.Matcher
1414
alias ElixirSense.Core.Normalized.Code, as: NormalizedCode
15+
require Logger
1516

1617
@enforce_keys [:label, :kind, :insert_text, :priority, :tags]
1718
defstruct [
@@ -172,6 +173,21 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
172173
)
173174

174175
required_alias = Keyword.get(options, :auto_insert_required_alias, true)
176+
parent = self()
177+
pid = spawn(fn ->
178+
for _i <- 1..100 do
179+
receive do
180+
:done -> :ok
181+
after
182+
1000 ->
183+
case Process.info(parent, :current_stacktrace) do
184+
{:current_stacktrace, stacktrace} ->
185+
dbg(stacktrace)
186+
nil -> :ok
187+
end
188+
end
189+
end
190+
end)
175191

176192
items =
177193
ElixirSense.suggestions(text, line, character,
@@ -185,10 +201,12 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
185201
|> Enum.reject(&is_nil/1)
186202
|> sort_items()
187203

204+
send(pid, :done)
205+
188206
# add trigger signatures to arity 0 if there are higher arity completions that would trigger
189207
commands =
190208
items
191-
|> Enum.filter(&(&1.kind in [:function, :class]))
209+
|> Enum.filter(&(&1.kind in [:function, :constant, :class]))
192210
|> Enum.group_by(&{&1.kind, &1.label})
193211
|> Map.new(fn {key, values} ->
194212
command = Enum.find_value(values, & &1.command)
@@ -198,7 +216,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
198216
items =
199217
items
200218
|> Enum.map(fn
201-
%{command: nil, kind: kind} = item when kind in [:function, :class] ->
219+
%{command: nil, kind: kind} = item when kind in [:function, :constant, :class] ->
202220
command = commands[{kind, item.label}]
203221

204222
if command do
@@ -375,7 +393,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
375393

376394
%__MODULE__{
377395
label: name,
378-
kind: :variable,
396+
kind: :enum_member,
379397
detail: "module attribute",
380398
documentation: name <> "\n" <> if(summary, do: summary, else: ""),
381399
insert_text: insert_text,
@@ -1223,7 +1241,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
12231241
if label == name or remote_calls? do
12241242
%__MODULE__{
12251243
label: label,
1226-
kind: :function,
1244+
kind: if(type == :function, do: :function, else: :constant),
12271245
detail: to_string(type),
12281246
label_details: %{
12291247
"detail" => "(#{Enum.join(args_list, ", ")})",

apps/language_server/lib/language_server/providers/document_symbols.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
1313
defstruct [:type, :name, :location, :children, :selection_location, :symbol]
1414
end
1515

16+
@macro_defs [:defmacro, :defmacrop, :defguard, :defguardp]
1617
@defs [:def, :defp, :defmacro, :defmacrop, :defguard, :defguardp, :defdelegate]
1718

1819
@supplementing_attributes [
@@ -210,7 +211,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
210211

211212
# Other attributes
212213
defp extract_symbol(_current_module, {:@, location, [{name, _, _}]}) when is_atom(name) do
213-
%Info{type: :constant, name: "@#{name}", location: location, children: []}
214+
%Info{type: :enum_member, name: "@#{name}", location: location, children: []}
214215
end
215216

216217
# Function, macro, guard with when
@@ -222,7 +223,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
222223
name = Macro.to_string(fn_head) |> String.replace("\n", "")
223224

224225
%Info{
225-
type: :function,
226+
type: if(defname in @macro_defs, do: :constant, else: :function),
226227
symbol: "#{name}",
227228
name: "#{defname} #{name}",
228229
location: location,
@@ -237,7 +238,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
237238
name = Macro.to_string(fn_head) |> String.replace("\n", "")
238239

239240
%Info{
240-
type: :function,
241+
type: if(defname in @macro_defs, do: :constant, else: :function),
241242
symbol: "#{name}",
242243
name: "#{defname} #{name}",
243244
location: location,

apps/language_server/test/providers/completion_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ defmodule ElixirLS.LanguageServer.Providers.CompletionTest do
565565

566566
assert [item] = items
567567

568-
# 3 is function
569-
assert item["kind"] == 3
568+
# 21 is constant which we use for macro
569+
assert item["kind"] == 21
570570
assert item["label"] == "error"
571571
assert item["detail"] == "macro"
572572
assert item["labelDetails"]["detail"] == "(message_or_fun, metadata \\\\ [])"

apps/language_server/test/providers/document_symbols_test.exs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
5252
children: [
5353
%Protocol.DocumentSymbol{
5454
children: [],
55-
kind: 14,
55+
kind: 22,
5656
name: "@my_mod_var",
5757
range: %{
5858
"end" => %{"character" => 37, "line" => 2},
@@ -83,17 +83,17 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
8383
},
8484
%Protocol.DocumentSymbol{
8585
children: [],
86-
kind: 12,
86+
kind: 14,
8787
name: "defmacro my_macro()"
8888
},
8989
%Protocol.DocumentSymbol{
9090
children: [],
91-
kind: 12,
91+
kind: 14,
9292
name: "defmacrop my_private_macro()"
9393
},
9494
%Protocol.DocumentSymbol{
9595
children: [],
96-
kind: 12,
96+
kind: 14,
9797
name: "defguard my_guard(a)",
9898
range: %{
9999
"end" => %{"character" => 47, "line" => 7},
@@ -106,7 +106,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
106106
},
107107
%Protocol.DocumentSymbol{
108108
children: [],
109-
kind: 12,
109+
kind: 14,
110110
name: "defguardp my_private_guard(a)"
111111
},
112112
%Protocol.DocumentSymbol{
@@ -124,7 +124,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
124124
},
125125
%Protocol.DocumentSymbol{
126126
children: [],
127-
kind: 12,
127+
kind: 14,
128128
name: "defguard my_guard"
129129
},
130130
%Protocol.DocumentSymbol{
@@ -257,7 +257,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
257257
},
258258
%Protocol.SymbolInformation{
259259
name: "@my_mod_var",
260-
kind: 14,
260+
kind: 22,
261261
location: %{
262262
range: %{
263263
"end" => %{"character" => 37, "line" => 2},
@@ -284,17 +284,17 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
284284
},
285285
%Protocol.SymbolInformation{
286286
name: "defmacro my_macro()",
287-
kind: 12,
287+
kind: 14,
288288
containerName: "MyModule"
289289
},
290290
%Protocol.SymbolInformation{
291291
name: "defmacrop my_private_macro()",
292-
kind: 12,
292+
kind: 14,
293293
containerName: "MyModule"
294294
},
295295
%Protocol.SymbolInformation{
296296
name: "defguard my_guard(a)",
297-
kind: 12,
297+
kind: 14,
298298
location: %{
299299
range: %{
300300
"end" => %{"character" => 47, "line" => 7},
@@ -305,7 +305,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
305305
},
306306
%Protocol.SymbolInformation{
307307
name: "defguardp my_private_guard(a)",
308-
kind: 12,
308+
kind: 14,
309309
containerName: "MyModule"
310310
},
311311
%Protocol.SymbolInformation{
@@ -321,7 +321,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
321321
},
322322
%Protocol.SymbolInformation{
323323
name: "defguard my_guard",
324-
kind: 12,
324+
kind: 14,
325325
containerName: "MyModule"
326326
},
327327
%Protocol.SymbolInformation{
@@ -1269,7 +1269,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
12691269
},
12701270
%Protocol.DocumentSymbol{
12711271
children: [],
1272-
kind: 14,
1272+
kind: 22,
12731273
name: "@type"
12741274
}
12751275
],
@@ -1345,7 +1345,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
13451345
containerName: "MyModule"
13461346
},
13471347
%Protocol.SymbolInformation{
1348-
kind: 14,
1348+
kind: 22,
13491349
name: "@type",
13501350
containerName: "MyModule"
13511351
}
@@ -1739,7 +1739,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
17391739
children: [
17401740
%Protocol.DocumentSymbol{
17411741
children: [],
1742-
kind: 14,
1742+
kind: 22,
17431743
name: "@optional_callbacks",
17441744
range: %{
17451745
"end" => %{"character" => 58, "line" => 1},
@@ -1757,62 +1757,62 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
17571757
},
17581758
%Protocol.DocumentSymbol{
17591759
children: [],
1760-
kind: 14,
1760+
kind: 22,
17611761
name: "@derive"
17621762
},
17631763
%Protocol.DocumentSymbol{
17641764
children: [],
1765-
kind: 14,
1765+
kind: 22,
17661766
name: "@enforce_keys"
17671767
},
17681768
%Protocol.DocumentSymbol{
17691769
children: [],
1770-
kind: 14,
1770+
kind: 22,
17711771
name: "@compile"
17721772
},
17731773
%Protocol.DocumentSymbol{
17741774
children: [],
1775-
kind: 14,
1775+
kind: 22,
17761776
name: "@dialyzer"
17771777
},
17781778
%Protocol.DocumentSymbol{
17791779
children: [],
1780-
kind: 14,
1780+
kind: 22,
17811781
name: "@file"
17821782
},
17831783
%Protocol.DocumentSymbol{
17841784
children: [],
1785-
kind: 14,
1785+
kind: 22,
17861786
name: "@external_resource"
17871787
},
17881788
%Protocol.DocumentSymbol{
17891789
children: [],
1790-
kind: 14,
1790+
kind: 22,
17911791
name: "@on_load"
17921792
},
17931793
%Protocol.DocumentSymbol{
17941794
children: [],
1795-
kind: 14,
1795+
kind: 22,
17961796
name: "@on_definition"
17971797
},
17981798
%Protocol.DocumentSymbol{
17991799
children: [],
1800-
kind: 14,
1800+
kind: 22,
18011801
name: "@vsn"
18021802
},
18031803
%Protocol.DocumentSymbol{
18041804
children: [],
1805-
kind: 14,
1805+
kind: 22,
18061806
name: "@after_compile"
18071807
},
18081808
%Protocol.DocumentSymbol{
18091809
children: [],
1810-
kind: 14,
1810+
kind: 22,
18111811
name: "@before_compile"
18121812
},
18131813
%Protocol.DocumentSymbol{
18141814
children: [],
1815-
kind: 14,
1815+
kind: 22,
18161816
name: "@fallback_to_any"
18171817
}
18181818
],
@@ -1863,7 +1863,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
18631863
},
18641864
%Protocol.SymbolInformation{
18651865
name: "@optional_callbacks",
1866-
kind: 14,
1866+
kind: 22,
18671867
location: %{
18681868
range: %{
18691869
"end" => %{"character" => 58, "line" => 1},
@@ -1879,62 +1879,62 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
18791879
},
18801880
%Protocol.SymbolInformation{
18811881
name: "@derive",
1882-
kind: 14,
1882+
kind: 22,
18831883
containerName: "MyModule"
18841884
},
18851885
%Protocol.SymbolInformation{
18861886
name: "@enforce_keys",
1887-
kind: 14,
1887+
kind: 22,
18881888
containerName: "MyModule"
18891889
},
18901890
%Protocol.SymbolInformation{
18911891
name: "@compile",
1892-
kind: 14,
1892+
kind: 22,
18931893
containerName: "MyModule"
18941894
},
18951895
%Protocol.SymbolInformation{
18961896
name: "@dialyzer",
1897-
kind: 14,
1897+
kind: 22,
18981898
containerName: "MyModule"
18991899
},
19001900
%Protocol.SymbolInformation{
19011901
name: "@file",
1902-
kind: 14,
1902+
kind: 22,
19031903
containerName: "MyModule"
19041904
},
19051905
%Protocol.SymbolInformation{
19061906
name: "@external_resource",
1907-
kind: 14,
1907+
kind: 22,
19081908
containerName: "MyModule"
19091909
},
19101910
%Protocol.SymbolInformation{
19111911
name: "@on_load",
1912-
kind: 14,
1912+
kind: 22,
19131913
containerName: "MyModule"
19141914
},
19151915
%Protocol.SymbolInformation{
19161916
name: "@on_definition",
1917-
kind: 14,
1917+
kind: 22,
19181918
containerName: "MyModule"
19191919
},
19201920
%Protocol.SymbolInformation{
19211921
name: "@vsn",
1922-
kind: 14,
1922+
kind: 22,
19231923
containerName: "MyModule"
19241924
},
19251925
%Protocol.SymbolInformation{
19261926
name: "@after_compile",
1927-
kind: 14,
1927+
kind: 22,
19281928
containerName: "MyModule"
19291929
},
19301930
%Protocol.SymbolInformation{
19311931
name: "@before_compile",
1932-
kind: 14,
1932+
kind: 22,
19331933
containerName: "MyModule"
19341934
},
19351935
%Protocol.SymbolInformation{
19361936
name: "@fallback_to_any",
1937-
kind: 14,
1937+
kind: 22,
19381938
containerName: "MyModule"
19391939
}
19401940
]} = DocumentSymbols.symbols(uri, parser_context, false)

0 commit comments

Comments
 (0)