-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathinit.lua
More file actions
191 lines (178 loc) · 5.82 KB
/
init.lua
File metadata and controls
191 lines (178 loc) · 5.82 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
require("kide.lsp.lsp_ui").init()
local mason_lspconfig = require("mason-lspconfig")
mason_lspconfig.setup({
ensure_installed = {
"lua_ls",
},
})
-- { key: 语言 value: 配置文件 }
local server_configs = {
lua_ls = require("kide.lsp.lua_ls"),
jdtls = require("kide.lsp.java"),
metals = require("kide.lsp.metals"),
clangd = require("kide.lsp.clangd"),
tsserver = require("kide.lsp.tsserver"),
html = require("kide.lsp.html"),
pyright = require("kide.lsp.pyright"),
rust_analyzer = require("kide.lsp.rust_analyzer"),
sqlls = require("kide.lsp.sqlls"),
gopls = require("kide.lsp.gopls"),
kotlin_language_server = {},
vuels = {},
lemminx = require("kide.lsp.lemminx"),
gdscript = require("kide.lsp.gdscript"),
rime_ls = require("kide.lsp.rime_ls"),
sourcekit = require("kide.lsp.sourcekit"),
sonarlint = require("kide.lsp.sonarlint"),
spring_boot = require("kide.lsp.spring_boot"),
taplo = {
setup = function(cfg)
require("lspconfig").taplo.setup(cfg)
end,
},
}
local utils = require("kide.core.utils")
require("mason-lspconfig").setup_handlers({
function(server_name)
local lspconfig = require("lspconfig")
-- tools config
local cfg = utils.or_default(server_configs[server_name], {})
-- 自定义启动方式
if cfg.setup then
return
end
-- lspconfig
local scfg = utils.or_default(cfg.server, {})
scfg.flags = {
debounce_text_changes = 150,
}
scfg.capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
lspconfig[server_name].setup(scfg)
end,
})
-- 自定义 LSP 启动方式
for _, value in pairs(server_configs) do
if value.setup then
value.setup({
flags = {
debounce_text_changes = 150,
},
capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()),
})
end
end
-- LspAttach 事件
vim.api.nvim_create_augroup("LspAttach_keymap", {})
vim.api.nvim_create_autocmd("LspAttach", {
group = "LspAttach_keymap",
callback = function(args)
if not (args.data and args.data.client_id) then
return
end
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client.name == "copilot" then
return
end
-- 绑定快捷键
require("kide.core.keybindings").maplsp(client, bufnr, client.name == "null-ls")
end,
})
vim.api.nvim_create_augroup("LspAttach_inlay_hint", {})
vim.api.nvim_create_autocmd("LspAttach", {
group = "LspAttach_inlay_hint",
callback = function(args)
if not (args.data and args.data.client_id) then
return
end
local bufnr = args.buf
vim.api.nvim_buf_create_user_command(bufnr, "InlayHint", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
end, {
nargs = 0,
})
-- local client = vim.lsp.get_client_by_id(args.data.client_id)
-- if client.server_capabilities.inlayHintProvider and vim.lsp.inlay_hint then
-- vim.lsp.inlay_hint.enable(true)
-- end
end,
})
vim.api.nvim_create_augroup("LspAttach_navic", {})
vim.api.nvim_create_autocmd("LspAttach", {
group = "LspAttach_navic",
callback = function(args)
if not (args.data and args.data.client_id) then
return
end
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client.name == "spring-boot" then
return
end
if client.server_capabilities.documentSymbolProvider then
vim.opt_local.winbar = "%{%v:lua.require'nvim-navic'.get_location()%}"
require("nvim-navic").attach(client, bufnr)
end
end,
})
local CLIENT_CACHE = {}
local function clientCache(client_id)
if not CLIENT_CACHE[client_id] then
CLIENT_CACHE[client_id] = {
CursorHold = {},
CursorHoldI = {},
CursorMoved = {},
}
end
return CLIENT_CACHE[client_id]
end
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client.server_capabilities.documentHighlightProvider then
if not clientCache(args.data.client_id).CursorHold[bufnr] then
clientCache(args.data.client_id).CursorHold[bufnr] = vim.api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
vim.lsp.buf.document_highlight()
end,
})
end
if not clientCache(args.data.client_id).CursorHoldI[bufnr] then
clientCache(args.data.client_id).CursorHoldI[bufnr] = vim.api.nvim_create_autocmd("CursorHoldI", {
buffer = bufnr,
callback = function()
vim.lsp.buf.document_highlight()
end,
})
end
if not clientCache(args.data.client_id).CursorMoved[bufnr] then
clientCache(args.data.client_id).CursorMoved[bufnr] = vim.api.nvim_create_autocmd("CursorMoved", {
buffer = bufnr,
callback = function()
vim.lsp.buf.clear_references()
end,
})
end
end
end,
})
vim.api.nvim_create_autocmd("LspDetach", {
callback = function(args)
local bufnr = args.buf
-- local client = vim.lsp.get_client_by_id(args.data.client_id)
if clientCache(args.data.client_id).CursorHold[bufnr] then
vim.api.nvim_del_autocmd(clientCache(args.data.client_id).CursorHold[bufnr])
clientCache(args.data.client_id).CursorHold[bufnr] = nil
end
if clientCache(args.data.client_id).CursorHoldI[bufnr] then
vim.api.nvim_del_autocmd(clientCache(args.data.client_id).CursorHoldI[bufnr])
clientCache(args.data.client_id).CursorHoldI[bufnr] = nil
end
if clientCache(args.data.client_id).CursorMoved[bufnr] then
vim.api.nvim_del_autocmd(clientCache(args.data.client_id).CursorMoved[bufnr])
clientCache(args.data.client_id).CursorMoved[bufnr] = nil
end
end,
})