Skip to content

Commit 035f9e0

Browse files
committed
some improvement
1 parent 7463c19 commit 035f9e0

6 files changed

Lines changed: 88 additions & 56 deletions

File tree

nvim/lsp/clangd.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
return {
2-
cmd = { 'clangd', '--background-index' },
2+
cmd = {
3+
'clangd',
4+
'--background-index',
5+
'--header-insertion=iwyu',
6+
},
37
filetypes = { 'c', 'cpp', 'objc', 'objcpp' },
48
root_markers = { '.clangd', 'compile_commands.json', 'compile_flags.txt', '.git' },
59
}

nvim/lua/options.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ vim.api.nvim_create_autocmd('FileType', {
8282
vim.api.nvim_create_autocmd('FileType', {
8383
pattern = 'go',
8484
group = filetype_group,
85-
callback = function() vim.opt_local.tabstop = 4 end,
85+
callback = function()
86+
vim.opt_local.tabstop = 4
87+
vim.opt_local.shiftwidth = 4
88+
end,
8689
})
8790

8891
vim.api.nvim_create_autocmd('FileType', {

nvim/nvim-pack-lock.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@
113113
"rev": "7caec274fd19c12b55902a5b795100d21531391f",
114114
"src": "https://github.com/nvim-treesitter/nvim-treesitter"
115115
},
116+
"nvim-ufo": {
117+
"rev": "ab3eb124062422d276fae49e0dd63b3ad1062cfc",
118+
"src": "git@github.com:kevinhwang91/nvim-ufo"
119+
},
116120
"nvim-web-devicons": {
117121
"rev": "d7462543c9e366c0d196c7f67a945eaaf5d99414",
118122
"src": "https://github.com/nvim-tree/nvim-web-devicons"
@@ -121,6 +125,10 @@
121125
"rev": "b9fd5226c2f76c951fc8ed5923d85e4de065e509",
122126
"src": "https://github.com/nvim-lua/plenary.nvim"
123127
},
128+
"promise-async": {
129+
"rev": "119e8961014c9bfaf1487bf3c2a393d254f337e2",
130+
"src": "git@github.com:kevinhwang91/promise-async"
131+
},
124132
"quicker.nvim": {
125133
"rev": "063cc44da1eef8681bbd653b29d3bc961780886a",
126134
"src": "https://github.com/stevearc/quicker.nvim"

nvim/plugin/lsp.lua

Lines changed: 68 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,38 @@ vim.pack.add {
66

77
require('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
3120
vim.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
3742
vim.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
7781
vim.diagnostic.config {
7882
update_in_insert = false,
7983
severity_sort = true,
@@ -86,32 +90,45 @@ vim.diagnostic.config {
8690

8791
vim.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+
})

nvim/plugin/treesitter.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ vim.opt.runtimepath:prepend(vim.fs.joinpath(install_dir, 'pack/core/opt/nvim-tre
99
require('nvim-treesitter').install {
1010
'bash',
1111
'c',
12+
'cpp',
1213
'cue',
1314
'diff',
1415
'go',
@@ -38,7 +39,5 @@ require('nvim-treesitter').install {
3839

3940
-- Enable treesitter highlighting for all filetypes
4041
vim.api.nvim_create_autocmd('FileType', {
41-
callback = function()
42-
pcall(vim.treesitter.start, vim.api.nvim_get_current_buf())
43-
end,
42+
callback = function() pcall(vim.treesitter.start, vim.api.nvim_get_current_buf()) end,
4443
})

zsh/.zshrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ _eval_cache() {
155155
source "$cache"
156156
}
157157

158+
_eval_cache uv uv uv generate-shell-completion zsh
158159
_eval_cache direnv direnv direnv hook zsh
159160
_eval_cache zoxide zoxide zoxide init zsh
160161
_eval_cache atuin atuin atuin init zsh

0 commit comments

Comments
 (0)