-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsp.lua
82 lines (74 loc) · 2.4 KB
/
lsp.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local nvim_lsp = require('lspconfig')
local configs = require('lspconfig.configs')
local util = require('lspconfig.util')
local on_attach = require('lsp_on_attach').on_attach
-- languages
local languages = {'pyright', 'gopls', 'rust_analyzer', 'ts_ls', 'lua_ls', 'dartls', 'html', 'marksman', 'protobuf-language-server', 'sqls', 'denols'}
-- setup nvim-cmp
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local key = 'protobuf-language-server'
configs[key] = {
default_config = {
cmd = { '~/.gvm/pkgsets/go1.22/global/bin/protobuf-language-server' },
filetypes = { 'proto', 'cpp' },
root_fir = util.root_pattern('.git'),
single_file_support = true,
settings = {
-- ["additional-proto-dirs"] = [
-- -- path to additional protobuf directories
-- -- "vendor",
-- -- "third_party",
-- ]
},
}
}
-- java 配置在 ffplugin/java.lua 下
for _, lsp in ipairs(languages) do
local config = {
on_attach = on_attach,
capabilities = capabilities
}
if lsp == "pyright" then
local function get_python_extra_path()
-- 获取 Python 版本
local python_version = vim.fn.trim(vim.fn.system("pdm info --python | xargs -I {} {} -c 'import sys; print(f\"{sys.version_info.major}.{sys.version_info.minor}\")'"))
if python_version and python_version ~= "" then
return ".venv/lib/python" .. python_version .. "/site-packages"
else
return nil
end
end
config.settings = {
python = {
pythonPath = vim.fn.trim(vim.fn.system('pdm info --python')),
analysis = {
-- extraPaths = { get_python_extra_path() },
extraPaths = { ".venv/lib/python3.12/site-packages" },
}
}
}
elseif lsp == 'lua_ls' then
config.settings = {
Lua = {
runtime = {
version = "LuaJIT"
},
diagnostics = {
globals = {'vim'}
}
}
}
elseif lsp == 'gopls' then
config.settings = {
gopls = {
buildFlags = {'-tags=integration'}
}
}
elseif lsp == 'ts_ls' then
config.root_dir = nvim_lsp.util.root_pattern("package.json")
config.single_file_support = false
elseif lsp == 'denols' then
config.root_dir = nvim_lsp.util.root_pattern("deno.json", "deno.jsonc")
end
nvim_lsp[lsp].setup(config)
end