nvim: lsp: Add support for lua
This commit is contained in:
parent
c51261d94a
commit
c646381a00
1 changed files with 65 additions and 0 deletions
|
@ -179,3 +179,68 @@ for _, lsp in ipairs(servers) do
|
|||
capabilities = set_snippet_capabilities(),
|
||||
}
|
||||
end
|
||||
|
||||
-- See https://github.com/sumneko/lua-language-server/wiki/Setting-without-VSCode#neovim-with-built-in-lsp-client
|
||||
-- on why we do this library thing
|
||||
-- Idea taken from https://gist.github.com/folke/fe5d28423ea5380929c3f7ce674c41d8
|
||||
local library = {}
|
||||
local function add_to_library(lib_path)
|
||||
for _, p in pairs(vim.fn.expand(lib_path, false, true)) do
|
||||
p = vim.loop.fs_realpath(p)
|
||||
library[p] = true
|
||||
end
|
||||
end
|
||||
|
||||
local function add_libraries()
|
||||
local cwd = vim.fn.getcwd()
|
||||
if string.find(cwd, "neovim") then
|
||||
add_to_library("$VIMRUNTIME")
|
||||
elseif string.find(cwd, "dotfiles") then
|
||||
add_to_library("$VIMRUNTIME")
|
||||
add_to_library("~/.config/nvim")
|
||||
add_to_library("~/.local/share/nvim/site/pack/packer/opt/*")
|
||||
add_to_library("~/.local/share/nvim/site/pack/packer/start/*")
|
||||
else
|
||||
add_to_library(cwd .. "/*")
|
||||
end
|
||||
end
|
||||
|
||||
local function determine_lua_version()
|
||||
local cwd = vim.fn.getcwd()
|
||||
if string.find(cwd, "neovim") or string.find(cwd, "dotfiles") then
|
||||
return "LuaJIT"
|
||||
else
|
||||
return "Lua 5.4"
|
||||
end
|
||||
end
|
||||
|
||||
add_libraries()
|
||||
|
||||
local runtime_path = vim.split(package.path, ';')
|
||||
table.insert(runtime_path, "lua/?.lua")
|
||||
table.insert(runtime_path, "lua/?/init.lua")
|
||||
|
||||
nvim_lsp.sumneko_lua.setup {
|
||||
cmd = { "/usr/bin/lua-language-server" };
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
version = determine_lua_version(),
|
||||
path = runtime_path,
|
||||
},
|
||||
completion = { callSnippet = "Both" },
|
||||
diagnostics = {
|
||||
globals = {'vim'},
|
||||
},
|
||||
workspace = {
|
||||
library = library,
|
||||
maxPreload = 2000,
|
||||
preloadFileSize = 50000
|
||||
},
|
||||
telemetry = {
|
||||
enable = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue