Skip to content

Change workspace symbols to only look at modules in the current application #261

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

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,7 @@ defmodule ElixirLS.LanguageServer.Providers.WorkspaceSymbols do
) do
JsonRpc.log_message(:info, "[ElixirLS WorkspaceSymbols] Indexing...")

module_paths =
:code.all_loaded()
|> process_chunked(fn chunk ->
for {module, beam_file} <- chunk,
path = find_module_path(module, beam_file),
path != nil,
do: {module, path}
end)
module_paths = module_paths()

JsonRpc.log_message(:info, "[ElixirLS WorkspaceSymbols] Module discovery complete")

Expand All @@ -155,14 +148,7 @@ defmodule ElixirLS.LanguageServer.Providers.WorkspaceSymbols do
) do
JsonRpc.log_message(:info, "[ElixirLS WorkspaceSymbols] Updating index...")

module_paths =
:code.all_loaded()
|> process_chunked(fn chunk ->
for {module, beam_file} <- chunk,
path = find_module_path(module, beam_file),
SourceFile.path_to_uri(path) in modified_uris,
do: {module, path}
end)
module_paths = module_paths()

JsonRpc.log_message(
:info,
Expand Down Expand Up @@ -247,28 +233,14 @@ defmodule ElixirLS.LanguageServer.Providers.WorkspaceSymbols do
end
end

defp find_module_path(module, beam_file) do
file =
with true <- Code.ensure_loaded?(module),
path when not is_nil(path) <- module.module_info(:compile)[:source],
path_binary = List.to_string(path),
true <- File.exists?(path_binary) do
path_binary
else
_ -> nil
end

if file do
file
defp find_module_path(module) do
with true <- Code.ensure_loaded?(module),
path when not is_nil(path) <- module.module_info(:compile)[:source],
path_binary = List.to_string(path),
true <- File.exists?(path_binary) do
path_binary
else
with beam_file when not is_nil(beam_file) <-
ErlangSourceFile.get_beam_file(module, beam_file),
erl_file = ErlangSourceFile.beam_file_to_erl_file(beam_file),
true <- File.exists?(erl_file) do
erl_file
else
_ -> nil
end
_ -> nil
end
end

Expand Down Expand Up @@ -483,6 +455,20 @@ defmodule ElixirLS.LanguageServer.Providers.WorkspaceSymbols do
end)
end

defp module_paths do
app = Keyword.fetch!(Mix.Project.config(), :app)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it umbrella friendly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately not, we will need to find an umbrella-friendly alternative


Application.load(app)

Application.spec(app, :modules)
|> Enum.flat_map(fn app_module ->
case find_module_path(app_module) do
nil -> []
path -> [{app_module, path}]
end
end)
end

@spec build_result(key_t, symbol_t, String.t(), nil | non_neg_integer) :: symbol_information_t
defp build_result(key, symbol, path, line) do
%{
Expand Down