Skip to content
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

Can't go to definition of symbols in other modules #1118

Closed
mawkler opened this issue Sep 26, 2024 · 2 comments
Closed

Can't go to definition of symbols in other modules #1118

mawkler opened this issue Sep 26, 2024 · 2 comments

Comments

@mawkler
Copy link

mawkler commented Sep 26, 2024

Hi! I noticed that I couldn't go to the definition of other modules. Checking the log I found two interesting errors:

[Warning] error: module MacroA is not loaded and could not be found
└─ nofile: Bug (module)

and

Elixir sources not found (checking in /build/elixir/src/elixir-1.17.3). Code navigation to Elixir modules disabled.

Here's the full log:

Click to expand
[Info] Started ElixirLS v0.22.0
[Info] Running in /home/melker/code/elixir-ls-go-to-definition-bug
[Info] ElixirLS built with elixir "1.17.3" on OTP "27"
[Info] Running on elixir "1.17.3 (compiled with Erlang/OTP 27)" on OTP "27"
[Info] Protocols are not consolidated
[Info] Elixir sources not found (checking in /build/elixir/src/elixir-1.17.3). Code navigation to Elixir modules disabled.
[Info] Received client configuration via workspace/configuration
%{"dialyzerEnabled" => true, "enableTestLenses" => false, "fetchDeps" => false, "suggestSpecs" => false}
[Info] Client does not support workspace/didChangeConfiguration dynamic registration
[Info] Client does not support workspace/didChangeWatchedFiles dynamic registration
[Info] Received workspace/didChangeConfiguration
[Info] Received client configuration via workspace/didChangeConfiguration
%{"dialyzerEnabled" => true, "enableTestLenses" => false, "fetchDeps" => false, "suggestSpecs" => false}
[Info] Starting build with MIX_ENV: test MIX_TARGET: host
[Info] Loaded DETS databases in 23ms
[Warning] error: module MacroA is not loaded and could not be found
└─ nofile: Bug (module)

[Info] Loaded DETS databases in 1ms
[Warning] ** (ErlangError) Erlang error: "CompileError during metadata build pre:\nnofile: cannot compile file (errors have been logged)\nast node: {:use, [end_of_expression: [newlines: 2, line: 2, column: 13], line: 2, column: 3], [{:__aliases__, [last: [line: 2, column: 7], line: 2, column: 7], [:MacroA]}]}"
    (elixir 1.17.3) src/elixir_expand.erl:102: :elixir_expand.expand/3
    (elixir 1.17.3) src/elixir_expand.erl:579: :elixir_expand.expand_block/5
    (elixir 1.17.3) src/elixir_expand.erl:46: :elixir_expand.expand/3
    (elixir 1.17.3) src/elixir.erl:455: :elixir.quoted_to_erl/4
    (elixir 1.17.3) src/elixir.erl:332: :elixir.eval_forms/4
    (elixir 1.17.3) lib/module/parallel_checker.ex:112: Module.ParallelChecker.verify/1
    (elixir 1.17.3) lib/code.ex:572: Code.validated_eval_string/3
    (elixir_sense 2.0.0) lib/elixir_sense/core/macro_expander.ex:24: ElixirSense.Core.MacroExpander.require_and_expand/2
    (elixir 1.17.3) lib/macro.ex:639: anonymous fn/4 in Macro.do_traverse_args/4
    (stdlib 6.0.1) lists.erl:2343: :lists.mapfoldl_1/3
    (elixir 1.17.3) lib/macro.ex:604: Macro.do_traverse/4
    (stdlib 6.0.1) lists.erl:2343: :lists.mapfoldl_1/3
    (elixir 1.17.3) lib/macro.ex:604: Macro.do_traverse/4
    (elixir_sense 2.0.0) lib/elixir_sense/core/macro_expander.ex:18: ElixirSense.Core.MacroExpander.expand_use/4
    (elixir_sense 2.0.0) lib/elixir_sense/core/state.ex:1690: ElixirSense.Core.State.expand/3

[Log] Compiling 3 files (.ex)
[Log] Generated bug app
[Info] Compile took 107 milliseconds
[Info] Starting build with MIX_ENV: test MIX_TARGET: host
[Info] [ElixirLS WorkspaceSymbols] Indexing...
[Info] [ElixirLS WorkspaceSymbols] Module discovery complete
[Info] [ElixirLS WorkspaceSymbols] 0 symbols added to index in 0ms
[Info] Compile took 58 milliseconds
[Info] Updating incremental PLT
[Info] Incremental PLT updated in 1273ms, changed 0 modules, analyzed 0, 0 warnings found
[Info] Loaded PLT info in 1377ms
[Info] Dialyzer analysis is up to date

I created an issue in the Neovim wrapper plugin that I'm using (elixir-tools/elixir-tools.nvim#225), but it seems to be an issue with elixirls.

To reproduce

To reproduce, here is the minimal Neovim configuration that I'm using:

Click to expand
local root = vim.fn.fnamemodify("./.repro", ":p")
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

local plugins = {
  {
    "elixir-tools/elixir-tools.nvim",
    version = "*",
    event = { "BufReadPre", "BufNewFile" },
    config = function()
      local elixir = require("elixir")
      local elixirls = require("elixir.elixirls")

      elixir.setup {
        projectionist = {
          enable = false
        }
      }
    end,
    dependencies = {
      "nvim-lua/plenary.nvim",
    },
  }
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

Steps to reproduce:

  1. Clone https://github.com/robsonpeixoto/elixir-ls-go-to-definition-bug.

  2. Open lib/bug.ex with the config above by doing nvim -u path/to/config/above elixir-ls-go-to-definition-bug/lib/bug.ex

  3. Wait a couple of seconds for the elixirls to load and index the workspace

  4. Move your scursor to ModA.say_hi() and type :=vim.lsp.buf.definition() (or right-click on ModA.say_hi() and click "Go to definition" if you're a mouse-enjoyer). Here's what the file looks like:

    defmodule Bug do
      use MacroA
    
      def hello do
        ModA.say_hi()
      end
    end
  5. Nothing happens

  • Elixir & Erlang versions (elixir --version):

    Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]
    
    Elixir 1.17.3 (compiled with Erlang/OTP 27)
    

Environment

  • Elixir Language Server version: v0.23.0
  • Operating system: EndeavourOS
  • Editor or IDE name (e.g. Emacs/VSCode): Neovim
  • Editor Plugin/LSP Client name and version:
    elixir-tools.nvim, v0.16.0 (but I get the same behaviour if I just raw-dog nvim-lspconfig)

Current behavior

Go to definition doesn't work when trying to go to symbols in other modules

Expected behavior

Go to definition does work when trying to go to symbols in other modules

@lukaszsamson
Copy link
Collaborator

  1. The ModA alias is not working with the current inference engine. This PR replaces the engine and as you can see this case is going to be handled
Screenshot 2024-09-26 at 09 15 35
  1. For go to stdlib to work you need to build elixir from sources. Otherwise the metadata points to paths from the build server like /build/elixir/src/elixir-1.17.3. I created Allow configuring stdlib directories #1119 for tracking

@mawkler
Copy link
Author

mawkler commented Sep 26, 2024

I see. Thank you for clarifying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants