Skip to content

Commit 286d11e

Browse files
committed
Move from lsp-zero to native lsp
1 parent 77accab commit 286d11e

File tree

2 files changed

+157
-90
lines changed

2 files changed

+157
-90
lines changed
Lines changed: 155 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
local M = {
2-
"VonHeikemen/lsp-zero.nvim",
2+
"neovim/nvim-lspconfig",
33
lazy = true,
4-
event = "InsertEnter",
5-
branch = "v3.x",
4+
event = { "BufReadPre", "BufNewFile" },
65
dependencies = {
76
-- LSP Support
8-
"neovim/nvim-lspconfig",
97
"williamboman/mason.nvim",
108
"williamboman/mason-lspconfig.nvim",
119
"folke/neodev.nvim",
@@ -28,94 +26,139 @@ local M = {
2826
}
2927

3028
function M.config()
31-
local status_neodev_ok, neodev = pcall(require, "neodev")
32-
if not status_neodev_ok then
33-
return
34-
end
35-
36-
local status_lsp_zero_ok, lsp_zero = pcall(require, "lsp-zero")
37-
if not status_lsp_zero_ok then
38-
return
39-
end
40-
41-
local status_mason_ok, mason = pcall(require, "mason")
42-
if not status_mason_ok then
43-
return
44-
end
45-
46-
local status_mason_settings_ok, mason_settings = pcall(require, "mason.settings")
47-
if not status_mason_settings_ok then
48-
return
49-
end
29+
-- Setup Mason
30+
require("mason").setup({
31+
ui = {
32+
border = "rounded",
33+
},
34+
})
5035

51-
local status_mason_lspconfig_ok, mason_lspconfig = pcall(require, "mason-lspconfig")
52-
if not status_mason_lspconfig_ok then
53-
return
54-
end
36+
-- Setup Mason LSP Config
37+
require("mason-lspconfig").setup({
38+
ensure_installed = { "solargraph", "lua_ls", "ts_ls" },
39+
handlers = {
40+
-- Default handler for all servers
41+
function(server_name)
42+
require("lspconfig")[server_name].setup({
43+
capabilities = require("cmp_nvim_lsp").default_capabilities(),
44+
on_attach = function(client, bufnr)
45+
-- Prevent multiple attachments
46+
if vim.b.lsp_attached then
47+
return
48+
end
49+
vim.b.lsp_attached = true
5550

56-
local status_navic_ok, navic = pcall(require, "nvim-navic")
57-
if not status_navic_ok then
58-
return
59-
end
51+
-- Setup neodev for lua_ls
52+
if client.name == "lua_ls" then
53+
require("neodev").setup({})
54+
end
6055

61-
local status_fidget_ok, fidget = pcall(require, "fidget")
62-
if not status_fidget_ok then
63-
return
64-
end
56+
-- Setup navic for breadcrumbs
57+
local navic_ok, navic = pcall(require, "nvim-navic")
58+
if navic_ok and client.server_capabilities.documentSymbolProvider then
59+
navic.attach(client, bufnr)
60+
end
61+
end,
62+
})
63+
end,
64+
-- Custom handler for lua_ls
65+
["lua_ls"] = function()
66+
local lua_ls_opts = require("config.lsp.lua_ls")
67+
require("lspconfig").lua_ls.setup({
68+
capabilities = require("cmp_nvim_lsp").default_capabilities(),
69+
settings = lua_ls_opts.settings,
70+
on_attach = function(client, bufnr)
71+
-- Prevent multiple attachments
72+
if vim.b.lsp_attached then
73+
return
74+
end
75+
vim.b.lsp_attached = true
6576

66-
local icons = require("config.icons").diagnostics
77+
-- Setup neodev
78+
require("neodev").setup({})
6779

68-
local lua_ls_opts = require("config.lsp.lua_ls")
69-
local solargraph_opts = require("config.lsp.solargraph")
80+
-- Setup navic for breadcrumbs
81+
local navic_ok, navic = pcall(require, "nvim-navic")
82+
if navic_ok and client.server_capabilities.documentSymbolProvider then
83+
navic.attach(client, bufnr)
84+
end
85+
end,
86+
})
87+
end,
88+
-- Custom handler for solargraph
89+
["solargraph"] = function()
90+
local solargraph_opts = require("config.lsp.solargraph")
91+
require("lspconfig").solargraph.setup({
92+
capabilities = require("cmp_nvim_lsp").default_capabilities(),
93+
cmd = solargraph_opts.cmd,
94+
filetypes = solargraph_opts.filetypes,
95+
init_options = solargraph_opts.init_options,
96+
root_dir = solargraph_opts.root_dir,
97+
settings = solargraph_opts.settings,
98+
on_attach = function(client, bufnr)
99+
-- Prevent multiple attachments
100+
if vim.b.lsp_attached then
101+
return
102+
end
103+
vim.b.lsp_attached = true
70104

71-
mason.setup({})
72-
mason_settings.set({ ui = { border = "rounded" } })
73-
mason_lspconfig.setup({
74-
ensure_installed = { "solargraph", "lua_ls", "ts_ls" },
75-
handlers = {
76-
lsp_zero.default_setup,
77-
},
78-
})
79-
lsp_zero.preset("recommended")
80-
lsp_zero.set_preferences({
81-
suggest_lsp_servers = true,
82-
setup_servers_on_start = true,
83-
set_lsp_keymaps = true,
84-
configure_diagnostics = true,
85-
cmp_capabilities = true,
86-
manage_nvim_cmp = false,
87-
call_servers = "local",
88-
sign_icons = {
89-
error = icons.Error,
90-
warn = icons.Warning,
91-
hint = icons.Hint,
92-
info = icons.Information,
105+
-- Setup navic for breadcrumbs
106+
local navic_ok, navic = pcall(require, "nvim-navic")
107+
if navic_ok and client.server_capabilities.documentSymbolProvider then
108+
navic.attach(client, bufnr)
109+
end
110+
end,
111+
})
112+
end,
93113
},
94114
})
95-
lsp_zero.configure("lua_ls", lua_ls_opts)
96-
lsp_zero.configure("solargraph", solargraph_opts)
97-
lsp_zero.on_attach(function(client, bufnr)
98-
if vim.b.lsp_attached then
99-
return
100-
end
101-
vim.b.lsp_attached = true
102-
if client.name == "lua_ls" then
103-
neodev.setup({})
104-
end
105-
if client.server_capabilities["documentSymbolProvider"] then
106-
navic.attach(client, bufnr)
107-
end
108-
end)
109-
-- lsp.nvim_workspace(lua_ls_opts)
110-
lsp_zero.setup()
111115

116+
-- Setup diagnostics
117+
local icons = require("config.icons").diagnostics
112118
vim.diagnostic.config({
113-
signs = { severity = { min = vim.diagnostic.severity.WARN } },
119+
signs = {
120+
severity = { min = vim.diagnostic.severity.WARN },
121+
text = {
122+
[vim.diagnostic.severity.ERROR] = icons.Error,
123+
[vim.diagnostic.severity.WARN] = icons.Warning,
124+
[vim.diagnostic.severity.HINT] = icons.Hint,
125+
[vim.diagnostic.severity.INFO] = icons.Information,
126+
},
127+
},
114128
underline = false,
115129
update_in_insert = false,
116130
virtual_text = { severity = { min = vim.diagnostic.severity.ERROR } },
131+
float = {
132+
border = "rounded",
133+
},
134+
})
135+
136+
-- Setup LSP keymaps
137+
vim.api.nvim_create_autocmd("LspAttach", {
138+
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
139+
callback = function(ev)
140+
local opts = { buffer = ev.buf }
141+
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
142+
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
143+
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
144+
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
145+
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
146+
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
147+
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
148+
vim.keymap.set("n", "<space>wl", function()
149+
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
150+
end, opts)
151+
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
152+
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
153+
vim.keymap.set({ "n", "v" }, "<space>ca", vim.lsp.buf.code_action, opts)
154+
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
155+
vim.keymap.set("n", "<space>f", function()
156+
vim.lsp.buf.format({ async = true })
157+
end, opts)
158+
end,
117159
})
118160

161+
-- Setup completion
119162
local cmp_status_ok, cmp = pcall(require, "cmp")
120163
if not cmp_status_ok then
121164
return
@@ -190,7 +233,6 @@ function M.config()
190233
require("luasnip.extras.select_choice")()
191234
end
192235
end,
193-
-- ["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
194236
["<C-c>"] = cmp.mapping({
195237
i = cmp.mapping.abort(),
196238
c = cmp.mapping.close(),
@@ -211,8 +253,6 @@ function M.config()
211253
i = cmp.mapping.abort(),
212254
c = cmp.mapping.close(),
213255
}),
214-
-- Accept currently selected item. If none selected, `select` first item.
215-
-- Set `select` to `false` to only confirm explicitly selected items.
216256
["<CR>"] = cmp.mapping.confirm({ select = false }),
217257
["<Right>"] = cmp.mapping.confirm({ select = true }),
218258
["<Tab>"] = cmp.mapping(function(fallback)
@@ -227,7 +267,6 @@ function M.config()
227267
elseif vim.api.nvim_get_mode().mode == "i" then
228268
tabout.tabout()
229269
elseif check_backspace() then
230-
-- cmp.complete()
231270
fallback()
232271
else
233272
fallback()
@@ -252,7 +291,6 @@ function M.config()
252291
formatting = {
253292
fields = { "kind", "abbr", "menu" },
254293
format = function(entry, vim_item)
255-
-- NOTE: order matters
256294
vim_item.menu = ({
257295
luasnip = "",
258296
nvim_lsp = "",
@@ -266,7 +304,7 @@ function M.config()
266304
sources = {
267305
{
268306
name = "nvim_lsp",
269-
filter = function(entry, _) -- entry, ctx
307+
filter = function(entry, _)
270308
local kind = require("cmp.types.lsp").CompletionItemKind[entry:get_kind()]
271309
if kind == "Text" then
272310
return true
@@ -279,7 +317,7 @@ function M.config()
279317
{
280318
name = "buffer",
281319
group_index = 2,
282-
filter = function(_, ctx) -- entry, ctx
320+
filter = function(_, ctx)
283321
if not contains(buffer_fts, ctx.prev_context.filetype) then
284322
return true
285323
end
@@ -292,11 +330,9 @@ function M.config()
292330
comparators = {
293331
compare.offset,
294332
compare.exact,
295-
-- compare.scopes,
296333
compare.score,
297334
compare.recently_used,
298335
compare.locality,
299-
-- compare.kind,
300336
compare.sort_text,
301337
compare.length,
302338
compare.order,
@@ -307,7 +343,6 @@ function M.config()
307343
select = false,
308344
},
309345
window = {
310-
--[[ documentation = false, ]]
311346
documentation = {
312347
border = "rounded",
313348
winhighlight = "NormalFloat:Pmenu,NormalFloat:Pmenu,CursorLine:PmenuSel,Search:None",
@@ -334,7 +369,39 @@ function M.config()
334369
},
335370
})
336371

337-
fidget.setup()
372+
-- Setup fidget with vim.notify override
373+
require("fidget").setup({
374+
notification = {
375+
override_vim_notify = true, -- Route vim.notify() to fidget.nvim
376+
window = {
377+
winblend = 0, -- Make notifications slightly transparent
378+
border = "rounded", -- Use rounded borders for notifications
379+
x_padding = 1,
380+
y_padding = 1,
381+
max_width = 0.6, -- 60% of editor width
382+
max_height = 10,
383+
},
384+
view = {
385+
stack_upwards = true,
386+
icon_separator = " ",
387+
group_separator = "",
388+
group_separator_hl = "",
389+
},
390+
},
391+
progress = {
392+
display = {
393+
render_limit = 5,
394+
done_ttl = 2,
395+
done_icon = "",
396+
done_style = "Constant",
397+
progress_ttl = math.huge,
398+
progress_icon = { "dots" },
399+
progress_style = "WarningMsg",
400+
group_style = "Title",
401+
icon_style = "Question",
402+
},
403+
},
404+
})
338405
end
339406

340407
return M

lua/config/plugins/neo-tree.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function M.config()
2929
"git_status",
3030
"buffers",
3131
},
32-
close_if_last_window = "false",
32+
close_if_last_window = false,
3333
popup_border_style = "rounded", -- "double", "none", "rounded", "shadow", "single" or "solid"
3434
default_component_configs = {
3535
indent = {
@@ -133,7 +133,7 @@ function M.config()
133133
leave_dirs_open = false, -- `false` closes auto expanded dirs, such as with `:Neotree reveal`
134134
},
135135
use_libuv_file_watcher = true, -- This will use the OS level file watchers to detect changes instead of relying on nvim autocmd events.
136-
async_directory_scan = false, -- Scan files synchronously
136+
async_directory_scan = "never", -- Scan files synchronously
137137
window = {
138138
mappings = {
139139
["o"] = "system_open",

0 commit comments

Comments
 (0)