Skip to content

Extract impl name for textDocument/documentSymbol #79

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 3 commits into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Unreleased

- Update dialyxir to 1.0.0-rc.7
- 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)

### v0.2.28: 16 Nov 2019

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
@moduledoc """
Document Symbols provider
Document Symbols provider. Generates and returns the nested `DocumentSymbol` format.

https://microsoft.github.io//language-server-protocol/specifications/specification-3-14/#textDocument_documentSymbol
"""

@symbol_enum %{
file: 1,
module: 2,
Expand Down Expand Up @@ -148,6 +151,18 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
}
end

# @impl true
defp extract_symbol(_current_module, {:@, _, [{:impl, location, [true]}]}) do
%{type: :constant, name: "@impl true", location: location, children: []}
end

# @impl BehaviourModule
defp extract_symbol(_current_module, {:@, _, [{:impl, location, [impl_expression]}]}) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's do the same for @behaviour

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, good idea! I've added that to the PR.

module_name = extract_module_name(impl_expression)

%{type: :constant, name: "@impl #{module_name}", location: location, children: []}
end

# Other attributes
defp extract_symbol(_current_module, {:@, _, [{name, location, _}]}) do
%{type: :constant, name: "@#{name}", location: location, children: []}
Expand Down
13 changes: 12 additions & 1 deletion apps/language_server/test/providers/document_symbols_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
@after_compile __MODULE__
@before_compile __MODULE__
@fallback_to_any true
@impl MyBehaviour
end
"""

Expand Down Expand Up @@ -892,7 +893,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
%{
children: [],
kind: 14,
name: "@impl",
name: "@impl true",
range: %{end: %{character: 3, line: 3}, start: %{character: 3, line: 3}},
selectionRange: %{
end: %{character: 3, line: 3},
Expand Down Expand Up @@ -1028,6 +1029,16 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
end: %{character: 3, line: 16},
start: %{character: 3, line: 16}
}
},
%{
children: [],
kind: 14,
name: "@impl MyBehaviour",
range: %{end: %{character: 3, line: 17}, start: %{character: 3, line: 17}},
selectionRange: %{
end: %{character: 3, line: 17},
start: %{character: 3, line: 17}
}
}
],
kind: 2,
Expand Down