@@ -6,33 +6,38 @@ vim.pack.add {
66
77require (' mason' ).setup {}
88
9- vim .api .nvim_create_autocmd (' LspProgress' , {
10- group = vim .api .nvim_create_augroup (' lsp-osc-progress' , { clear = true }),
11- callback = function (ev )
12- local value = ev .data .params .value or {}
13- local msg = value .message or ' done'
14-
15- -- rust-analyzer in particular has really long LSP messages so truncate them
16- if # msg > 40 then msg = msg :sub (1 , 37 ) .. ' ...' end
17-
18- -- :h LspProgress
19- vim .api .nvim_echo ({ { msg } }, false , {
20- id = ' lsp' ,
21- kind = ' progress' ,
22- title = value .title ,
23- source = ' lsp' ,
24- status = value .kind ~= ' end' and ' running' or ' success' ,
25- percent = value .percentage ,
26- })
27- end ,
28- })
9+ require (' mason-tool-installer' ).setup {
10+ -- LSP servers are auto-discovered from lsp/*.lua via vim.lsp.enable
11+ ensure_installed = {
12+ ' delve' ,
13+ ' buildifier' ,
14+ ' hadolint' ,
15+ ' stylua' ,
16+ ' prettier' ,
17+ },
18+ }
2919
30- -- Global fallback root marker for all servers
3120vim .lsp .config (' *' , {
3221 root_markers = { ' .git' },
3322})
3423
35- -- LspAttach: behaviour beyond Neovim defaults
24+ vim .lsp .enable {
25+ ' bashls' ,
26+ ' clangd' ,
27+ ' cue' ,
28+ ' gopls' ,
29+ ' jsonls' ,
30+ ' jsonnet_ls' ,
31+ ' lua_ls' ,
32+ ' nushell' ,
33+ ' starpls' ,
34+ ' taplo' ,
35+ ' terraformls' ,
36+ ' ty' ,
37+ ' vtsls' ,
38+ ' yamlls' ,
39+ }
40+
3641-- Neovim 0.11+ already maps globally: grn, gra, grr, gri, grt, K
3742vim .api .nvim_create_autocmd (' LspAttach' , {
3843 group = vim .api .nvim_create_augroup (' lsp-attach' , { clear = true }),
@@ -73,7 +78,6 @@ vim.api.nvim_create_autocmd('LspAttach', {
7378 end ,
7479})
7580
76- -- Diagnostic configuration
7781vim .diagnostic .config {
7882 update_in_insert = false ,
7983 severity_sort = true ,
@@ -86,32 +90,45 @@ vim.diagnostic.config {
8690
8791vim .keymap .set (' n' , ' <leader>q' , vim .diagnostic .setloclist , { desc = ' Open diagnostic [Q]uickfix list' })
8892
89- -- Enable servers (each configured in nvim/lsp/<name>.lua)
90- vim .lsp .enable {
91- ' bashls' ,
92- ' clangd' ,
93- ' cue' ,
94- ' gopls' ,
95- ' jsonls' ,
96- ' jsonnet_ls' ,
97- ' lua_ls' ,
98- ' nushell' ,
99- ' starpls' ,
100- ' taplo' ,
101- ' terraformls' ,
102- ' ty' ,
103- ' vtsls' ,
104- ' yamlls' ,
105- }
93+ -- Forwards LSP progress to nvim_echo so it integrates with the ghostty status line
94+ vim .api .nvim_create_autocmd (' LspProgress' , {
95+ group = vim .api .nvim_create_augroup (' lsp-osc-progress' , { clear = true }),
96+ callback = function (ev )
97+ local value = ev .data .params .value or {}
98+ local msg = value .message or ' done'
10699
107- -- Ensure non-LSP Mason packages are installed
108- -- (LSP servers are auto-discovered from lsp/*.lua via vim.lsp.enable)
109- require (' mason-tool-installer' ).setup {
110- ensure_installed = {
111- ' delve' ,
112- ' buildifier' ,
113- ' hadolint' ,
114- ' stylua' ,
115- ' prettier' ,
116- },
117- }
100+ -- rust-analyzer in particular has really long LSP messages so truncate them
101+ if # msg > 40 then msg = msg :sub (1 , 37 ) .. ' ...' end
102+
103+ -- :h LspProgress
104+ vim .api .nvim_echo ({ { msg } }, false , {
105+ id = ' lsp' ,
106+ kind = ' progress' ,
107+ title = value .title ,
108+ source = ' lsp' ,
109+ status = value .kind ~= ' end' and ' running' or ' success' ,
110+ percent = value .percentage ,
111+ })
112+ end ,
113+ })
114+
115+ -- Organize C/C++ includes on save via clangd's organizeImports code action
116+ vim .api .nvim_create_autocmd (' BufWritePre' , {
117+ pattern = { ' *.c' , ' *.cpp' , ' *.h' , ' *.hpp' },
118+ group = vim .api .nvim_create_augroup (' clangd-organize-imports' , { clear = true }),
119+ callback = function (ev )
120+ local client = vim .lsp .get_clients ({ bufnr = ev .buf , name = ' clangd' })[1 ]
121+ if not client then return end
122+ local params = vim .tbl_extend (' force' , vim .lsp .util .make_range_params (0 , client .offset_encoding ), {
123+ context = { only = { ' source.organizeImports' }, diagnostics = {} },
124+ })
125+ local result = vim .lsp .buf_request_sync (ev .buf , ' textDocument/codeAction' , params , 1000 )
126+ for _ , res in pairs (result or {}) do
127+ for _ , action in pairs (res .result or {}) do
128+ if action .edit then
129+ vim .lsp .util .apply_workspace_edit (action .edit , client .offset_encoding )
130+ end
131+ end
132+ end
133+ end ,
134+ })
0 commit comments