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
[Issue] sumneko_lua LSP client is defined but cannot attach to buffer #20
Comments
Not sure if this is the cause, but I think the root path and path to the binary need to be included in the command, as per the lspconfig wiki. |
It now seems to attach to the buffer. My config for the LSP (based on lsp = {
provider = "sumneko_lua",
setup = {
-- filetypes = {},
cmd = {
-- DATA_PATH .. "/lspinstall/lua/sumneko-lua-language-server", "-E", DATA_PATH .. "/lspinstall/lua/main.lua",
"C:/Work/Projects/Repositories/GitHub/sumneko/lua-language-server".."\\bin\\".."Windows".."\\lua-language-server",
"-E",
"C:/Work/Projects/Repositories/GitHub/sumneko/lua-language-server" .. "/main.lua"
},
capabilities = common_capabilities,
on_attach = on_attach_sumneko_lua,
on_init = common_on_init,
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
-- Setup your lua path
path = vim.split(package.path, ";"),
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim", "lvim", "MA", "MAA" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = {
-- WARN: IS THIS SETUP OK?
["C:/Work/MEGA/Portable/Neovim/config/LunarVim/lua"] = true,
["C:/Work/MEGA/Portable/Neovim/config/MyLunarVim/lua"] = true,
["C:/Work/MEGA/Portable/Neovim/config/mine/lua"] = true,
[vim.fn.expand "$VIMRUNTIME/lua"] = true,
[vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
},
maxPreload = 100000,
preloadFileSize = 1000,
},
},
},
},
},
-- lsp = nil,
-- lsp = {},
}, Still there seem to be two main problems:
More in general, I'm not sure of the above config, and if it could be fixed/optimized somehow. |
You shouldn't set the workspace library yourself. That's what this plugin does |
I removed the library item and now this is my config: lsp = {
provider = "sumneko_lua",
setup = {
-- filetypes = {},
cmd = {
-- DATA_PATH .. "/lspinstall/lua/sumneko-lua-language-server", "-E", DATA_PATH .. "/lspinstall/lua/main.lua",
"C:/Work/Projects/Repositories/GitHub/sumneko/lua-language-server".."\\bin\\".."Windows".."\\lua-language-server",
"-E",
"C:/Work/Projects/Repositories/GitHub/sumneko/lua-language-server" .. "/main.lua"
},
capabilities = common_capabilities,
on_attach = on_attach_sumneko_lua,
on_init = common_on_init,
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
-- Setup your lua path
path = vim.split(package.path, ";"),
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim", "lvim", "MA", "MAA" },
},
workspace = {
maxPreload = 100000,
preloadFileSize = 1000,
},
},
},
},
},
-- lsp = nil,
-- lsp = {},
}, Let consider this file:
if MAA.plugins.tagbar.active then
require("my-tagbar")
end The issue is that when looking for the definition of It is located at:
But, when looking for the definition of another module like at the following {
"folke/todo-comments.nvim",
requires = "nvim-lua/plenary.nvim",
config = function()
require("todo-comments").setup { }
end,
disable = not MAA.plugins.todo_comments.active,
}, then the proper file is subsequently opened:
|
You're not using standard directories. What is your neovim config directory here? Inside that directory, all your lua config should be under |
You're right. I'm using a portable setup.
But that path only contains:
Content of my if has('win32')
" -----------------------------
" LunarVim
" -----------------------------
let $VIMCONFIG = fnamemodify(expand("$VIM"), ':h:h') . '\config' " Get the path equivalent to $VIM\config
let $MYVIMRC = $VIMCONFIG . '\MyLunarVim\init.lua' " Set $MYVIMRC to point to the init.vim file
let &rtp .= ',' . $VIMCONFIG . '\MyLunarVim' " Add custom runtime path
let &rtp .= ',' . $VIMCONFIG . '\LunarVim' " Add custom runtime path
let &rtp .= ',' . $VIMCONFIG . '\mine' " Add custom runtime path
exec 'luafile ' . $MYVIMRC
endif Also:
thus:
I would be very interested in finding a possible solution to fix the |
As I mentioned before, this setup is not supported by luadev.settings.Lua.workspace.library["C:\\Work\\MEGA\\Portable\\Neovim\\config\\MyLunarVim\\"] = true
luadev.settings.Lua.workspace.library["C:\\Work\\MEGA\\Portable\\Neovim\\config\\mine"] = true I haven't tested this, so not sure it will work. I'll close this issue since this is not supported. |
I'm not sure about the place where I should put those extra settings. Any hint? Currently, my LUA LSP settings are defined here: https://github.com/LunarVim/LunarVim/blob/rolling/lua/default-config.lua#L690 |
I don't get it. You are not using |
Also, since you;re probably using local lspconfig = require('lspconfig')
lspconfig.sumneko_lua.setup(luadev) |
I finally solved it. Here is the new config:
if MAA.plugins.lua_dev.active then
require("my-lua-dev")
end
local lspconfig = require 'lspconfig'
local configs = require 'lspconfig/configs'
-- Check if lua_dev server already defined.
if not lspconfig.lua_dev then configs['lua_dev'] = {default_config = {}} end
-- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone)
USER = vim.fn.expand('$USER')
local system_name
if vim.fn.has("mac") == 1 then
system_name = "macOS"
elseif vim.fn.has("unix") == 1 then
system_name = "Linux"
elseif vim.fn.has('win32') == 1 or vim.fn.has('win64') == 1 then
system_name = "Windows"
else
print("Unsupported system for sumneko")
end
local sumneko_root_path = ""
local sumneko_binary = ""
if vim.fn.has("mac") == 1 then
sumneko_root_path = "/Users/" .. USER .. "/.config/nvim/lua-language-server"
sumneko_binary = "/Users/" .. USER .. "/.config/nvim/lua-language-server/bin/macOS/lua-language-server"
elseif vim.fn.has("unix") == 1 then
sumneko_root_path = "/home/" .. USER .. "/.config/nvim/lua-language-server"
sumneko_binary = "/home/" .. USER .. "/.config/nvim/lua-language-server/bin/Linux/lua-language-server"
elseif vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1 then
sumneko_root_path = "C:/Work/Projects/Repositories/GitHub/sumneko/lua-language-server"
sumneko_binary = sumneko_root_path.."\\bin\\"..system_name.."\\lua-language-server"
else
print("Unsupported system for sumneko")
end
local luadev = require("lua-dev").setup({
lspconfig = {
filetypes = {"lua"},
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"},
root_dir = require('lspconfig/util').root_pattern(".nv_root"),
-- WARN: By doing so, two main roots are defined, according to the active buffer path:
-- LV Config : C:\Work\MEGA\Portable\Neovim\config
-- Packer.nvim : C:\Users\MyUsername\AppData\Local\nvim-data
},
})
-- lspconfig.sumneko_lua.setup(luadev) -- WARN: Conflict with sumneko_lua setups defined elsewhere
lspconfig.lua_dev.setup(luadev) The trick was indeed to define a new LUA LSP config ( lspconfig.lua_dev.setup(luadev) Otherwise, if defined as The strange thing is that some definitions and references seem to be found twice: |
Neovim version: V0.6 nightly
OS: Windows 10 x64 Pro
:LspInfo
:lsp.log
:lua-dev
setup file:The text was updated successfully, but these errors were encountered: