问题
sumneko_lua
在编辑的时候 LSP 只进入单文件模式,对于 require
导入的文件、函数不进行补全
配置:
if server.name == "sumneko_lua" then
opts = {
cmd = { "lua-language-server" },
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
path = vim.api.nvim_get_option('path')
},
diagnostics = {
globals = { 'vim', 'use' },
},
workspace = {
library = {
[vim.fn.expand('$VIMRUNTIME/lua')] = true,
[vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
-- vim.api.nvim_get_runtime_file("", true)
},
ignoreDir = { '.git', '.vscode', '.idea', 'site' },
maxPreload = 2000,
preloadFileSize = 2000,
},
telemetry = { enable = false, }
},
},
single_file_support = true,
}
end
解决
设置 root_dir
,升级为项目(针对 runtime_path
内所有 lua 文件)
root_dir = require "lspconfig".util.root_pattern('*.lua'),
-- 或者
root_dir = require "lspconfig".util.root_pattern('init.lua', 'lua'),
if server.name == "sumneko_lua" then
opts = {
cmd = { "lua-language-server" },
root_dir = require "lspconfig".util.root_pattern('init.lua', 'lua'), -- 设置 root_dir
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
path = vim.api.nvim_get_option('path')
},
diagnostics = {
globals = { 'vim', 'use' },
},
workspace = {
library = {
[vim.fn.expand('$VIMRUNTIME/lua')] = true,
[vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
-- vim.api.nvim_get_runtime_file("", true)
},
ignoreDir = { '.git', '.vscode', '.idea', 'site' },
maxPreload = 2000,
preloadFileSize = 2000,
},
telemetry = { enable = false, }
},
},
single_file_support = true,
}
end
网友评论