Skip to content

Commit a522df8

Browse files
authored
Extract impl name for textDocument/documentSymbol (#79)
* Extract impl name * Update changelog and moduledocs * Extract @behaviour name
1 parent 9ad535f commit a522df8

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Unreleased
22

33
- Update dialyxir to 1.0.0-rc.7
4+
- Improvements to `textDocument/documentSymbol`, now `DocumentSymbol` is returned instead of the more simplistic `SymbolInformation` (thanks to [Łukasz Samson](https://github.com/lukaszsamson) and [kent-medin](https://github.com/kent-medin)) [#76](https://github.com/elixir-lsp/elixir-ls/pull/76)
45

56
### v0.2.28: 16 Nov 2019
67

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
22
@moduledoc """
3-
Document Symbols provider
3+
Document Symbols provider. Generates and returns the nested `DocumentSymbol` format.
4+
5+
https://microsoft.github.io//language-server-protocol/specifications/specification-3-14/#textDocument_documentSymbol
46
"""
7+
58
@symbol_enum %{
69
file: 1,
710
module: 2,
@@ -148,6 +151,25 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
148151
}
149152
end
150153

154+
# @behaviour BehaviourModule
155+
defp extract_symbol(_current_module, {:@, _, [{:behaviour, location, [behaviour_expression]}]}) do
156+
module_name = extract_module_name(behaviour_expression)
157+
158+
%{type: :constant, name: "@behaviour #{module_name}", location: location, children: []}
159+
end
160+
161+
# @impl true
162+
defp extract_symbol(_current_module, {:@, _, [{:impl, location, [true]}]}) do
163+
%{type: :constant, name: "@impl true", location: location, children: []}
164+
end
165+
166+
# @impl BehaviourModule
167+
defp extract_symbol(_current_module, {:@, _, [{:impl, location, [impl_expression]}]}) do
168+
module_name = extract_module_name(impl_expression)
169+
170+
%{type: :constant, name: "@impl #{module_name}", location: location, children: []}
171+
end
172+
151173
# Other attributes
152174
defp extract_symbol(_current_module, {:@, _, [{name, location, _}]}) do
153175
%{type: :constant, name: "@#{name}", location: location, children: []}

apps/language_server/test/providers/document_symbols_test.exs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
862862
@after_compile __MODULE__
863863
@before_compile __MODULE__
864864
@fallback_to_any true
865+
@impl MyBehaviour
865866
end
866867
"""
867868

@@ -882,7 +883,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
882883
%{
883884
children: [],
884885
kind: 14,
885-
name: "@behaviour",
886+
name: "@behaviour MyBehaviour",
886887
range: %{end: %{character: 3, line: 2}, start: %{character: 3, line: 2}},
887888
selectionRange: %{
888889
end: %{character: 3, line: 2},
@@ -892,7 +893,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
892893
%{
893894
children: [],
894895
kind: 14,
895-
name: "@impl",
896+
name: "@impl true",
896897
range: %{end: %{character: 3, line: 3}, start: %{character: 3, line: 3}},
897898
selectionRange: %{
898899
end: %{character: 3, line: 3},
@@ -1028,6 +1029,16 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
10281029
end: %{character: 3, line: 16},
10291030
start: %{character: 3, line: 16}
10301031
}
1032+
},
1033+
%{
1034+
children: [],
1035+
kind: 14,
1036+
name: "@impl MyBehaviour",
1037+
range: %{end: %{character: 3, line: 17}, start: %{character: 3, line: 17}},
1038+
selectionRange: %{
1039+
end: %{character: 3, line: 17},
1040+
start: %{character: 3, line: 17}
1041+
}
10311042
}
10321043
],
10331044
kind: 2,

0 commit comments

Comments
 (0)