mroavi
June 30, 2021, 1:16pm
1
Is there a way to navigate to a require
ed file/function by placing the cursor on that line and hitting a keystroke?
E.g. suppose I have:
require('mrv.settings').setup()
and that I place my cursor on that line. Can I easily navigate to that function in the file it is defined with a shortcut?
vim.lsp.buf.definition()
make sure you tell the LSP to discover the lua config/plugins/runtime directory, you can either snatch some part from this plugin or just use it in its entirety
1 Like
Thanks for the answer @elianiva . I have a follow-up question. I already have this setup for the sumneko Lua language server:
local lua_lsp_dir = "/home/mroavi/lsp-servers/lua-language-server/"
lspconfig.sumneko_lua.setup{
cmd = {lua_lsp_dir .. "bin/Linux/lua-language-server", "-E", lua_lsp_dir .. "/main.lua"},
capabilities = capabilities,
settings = {
Lua = {
runtime = {version = "LuaJIT", path = vim.split(package.path, ";")},
diagnostics = {globals = {"vim"}},
workspace = {
-- Make the server aware of Neovim runtime files
library = {
[vim.fn.expand "$VIMRUNTIME/lua"] = true,
[vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true
}
}
}
}
}
If I use the plugin you suggest, should I remove all this config and just add:
local luadev = require("lua-dev").setup()
lspconfig.sumneko_lua.setup(luadev)
? I tried this but it didn’t work.
Ohh I fixed it. The cmd
was the only thing I had to specify properly. This config works now:
local lua_lsp_dir = "/home/mroavi/lsp-servers/lua-language-server/"
local luadev = require("lua-dev").setup({
lspconfig = {
cmd = {lua_lsp_dir .. "bin/Linux/lua-language-server", "-E", lua_lsp_dir .. "/main.lua"}
},
})
lspconfig.sumneko_lua.setup(luadev)
I also noticed that I was testing it too quickly after starting nvim. I forgot that the sumneko lua server takes a while to kick in.
@elianiva thanks again.