Can't go to definition when trying to go to function in other module
Hi! I'm trying out this plugin, but I can't seem to do vim.lsp.buf.definition() to jump to functions in other modules.
To reproduce,
-
Clone https://github.com/robsonpeixoto/elixir-ls-go-to-definition-bug.
-
Open
lib/bug.exwith the config below -
In
lib/bug.ex, move your scursor toModA.say_hi()and call:=vim.lsp.buf.definition(). Here's what the file looks like:defmodule Bug do use MacroA def hello do ModA.say_hi() end end -
Nothing happens
Here's the minimal config 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",
})
It does however work when navigating to symbols in the same file, like if I would try to go to hello() in that file.
Its probably still indexing your project, you can run :ElixirOutputPanel to see if there are any logs in there that show anything
@mhanberg The output of :ElixirOutputPanel contains this:
[Warning] error: module MacroA is not loaded and could not be found
└─ nofile: Bug (module)
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 apologize if I'm doing something dumb here, I just started using Elixir, so I'm a complete novice.
I see, you might want to take this to the ElixirLS repo to ask.
This plugin merely handles starting and configuring it for you.
But, as a community we are starting a new LSP initiative and are working on a new official one, so support on the existing ones is reduced as we push forward.