Optimize Neovim configuration structure and LSP setup
- Remove duplicate nvim-web-devicons loading (already in kickstart) - Add clangd configuration to custom LSP setup with proper flags - Replace complex clangd_helper with universal LSP reload keybind (<leader>lr) - Clean up unused clangd target selection keybind - Streamline plugin organization for better maintainability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e9c3342170
commit
68f26dc50d
|
@ -6,5 +6,6 @@ nvim
|
||||||
spell/
|
spell/
|
||||||
|
|
||||||
# Project status tracking (local only)
|
# Project status tracking (local only)
|
||||||
|
CLAUDE.md
|
||||||
STATUS.md
|
STATUS.md
|
||||||
VIDINTEL.md
|
VIDINTEL.md
|
||||||
|
|
14
init.lua
14
init.lua
|
@ -665,7 +665,19 @@ require('lazy').setup({
|
||||||
-- - settings (table): Override the default settings passed when initializing the server.
|
-- - settings (table): Override the default settings passed when initializing the server.
|
||||||
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
|
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
|
||||||
local servers = {
|
local servers = {
|
||||||
clangd = require('custom.plugins.lsp.clangd').get_server_config(),
|
clangd = {
|
||||||
|
cmd = {
|
||||||
|
'clangd',
|
||||||
|
'--background-index',
|
||||||
|
'--clang-tidy',
|
||||||
|
'--header-insertion=never',
|
||||||
|
'--query-driver=' .. vim.fn.exepath('clang++'),
|
||||||
|
'--resource-dir=' .. vim.fn.systemlist({ 'clang++', '--print-resource-dir' })[1],
|
||||||
|
},
|
||||||
|
filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
|
||||||
|
root_dir = require('lspconfig.util').root_pattern('.git'),
|
||||||
|
single_file_support = true,
|
||||||
|
},
|
||||||
-- gopls = {},
|
-- gopls = {},
|
||||||
-- pyright = {},
|
-- pyright = {},
|
||||||
-- rust_analyzer = {},
|
-- rust_analyzer = {},
|
||||||
|
|
|
@ -1,10 +1,26 @@
|
||||||
-- [[ Basic Keymaps ]]
|
-- [[ Basic Keymaps ]]
|
||||||
-- See `:help vim.keymap.set()`
|
-- See `:help vim.keymap.set()`
|
||||||
|
|
||||||
-- Add any other general-purpose keymaps you want here
|
-- LSP reload function
|
||||||
vim.keymap.set('n', '<leader>T', function()
|
local function reload_lsp()
|
||||||
require('custom.lsp.clangd'):pick_target()
|
local clients = vim.lsp.get_clients()
|
||||||
end, { desc = 'Choose [T]arget' })
|
if #clients == 0 then
|
||||||
|
print('No LSP clients running')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, client in ipairs(clients) do
|
||||||
|
vim.lsp.stop_client(client.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.defer_fn(function()
|
||||||
|
vim.cmd('LspStart')
|
||||||
|
print('LSP servers reloaded')
|
||||||
|
end, 500)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Reload LSP keybind
|
||||||
|
vim.keymap.set('n', '<leader>lr', reload_lsp, { desc = '[L]SP [R]eload all servers' })
|
||||||
|
|
||||||
-- Standard practice for Lua modules that don't need to return complex data
|
-- Standard practice for Lua modules that don't need to return complex data
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -18,4 +18,3 @@ vim.o.softtabstop = 2
|
||||||
-- etc... Review the options section of your old init.lua and add any *changed* values here.
|
-- etc... Review the options section of your old init.lua and add any *changed* values here.
|
||||||
-- The kickstart defaults are generally sensible, so you might not need many overrides.
|
-- The kickstart defaults are generally sensible, so you might not need many overrides.
|
||||||
|
|
||||||
-- print 'Custom options loaded!' -- Optional: Add print statement for debugging
|
|
||||||
|
|
|
@ -3,14 +3,6 @@
|
||||||
--
|
--
|
||||||
-- See the kickstart.nvim README for more information
|
-- See the kickstart.nvim README for more information
|
||||||
return {
|
return {
|
||||||
{
|
|
||||||
'nvim-tree/nvim-web-devicons',
|
|
||||||
lazy = false,
|
|
||||||
priority = 1000,
|
|
||||||
config = function()
|
|
||||||
require('nvim-web-devicons').setup()
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
-- { import = 'custom.plugins.completion' },
|
-- { import = 'custom.plugins.completion' },
|
||||||
-- { import = 'custom.plugins.debug' },
|
-- { import = 'custom.plugins.debug' },
|
||||||
-- { import = 'custom.plugins.formatting' },
|
-- { import = 'custom.plugins.formatting' },
|
||||||
|
|
|
@ -1,110 +0,0 @@
|
||||||
local M = {}
|
|
||||||
|
|
||||||
local uv = vim.uv or vim.loop
|
|
||||||
local lspconfig_util = require 'lspconfig.util'
|
|
||||||
|
|
||||||
local debounce_timer, watcher
|
|
||||||
|
|
||||||
local function find_compile_commands()
|
|
||||||
local results = vim.fn.systemlist { 'fd', '-u', '-t', 'f', 'compile_commands.json' }
|
|
||||||
table.sort(results, function(a, b)
|
|
||||||
return a:match 'debug' and not b:match 'debug'
|
|
||||||
end)
|
|
||||||
local path = results[1]
|
|
||||||
return path and vim.fn.fnamemodify(path, ':h') or nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local function start_watcher(dir, reload_callback)
|
|
||||||
if watcher then
|
|
||||||
watcher:stop()
|
|
||||||
watcher:close()
|
|
||||||
watcher = nil
|
|
||||||
end
|
|
||||||
if debounce_timer then
|
|
||||||
debounce_timer:stop()
|
|
||||||
debounce_timer:close()
|
|
||||||
debounce_timer = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
if not dir then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
watcher = uv.new_fs_event()
|
|
||||||
watcher:start(
|
|
||||||
dir,
|
|
||||||
{ recursive = true },
|
|
||||||
vim.schedule_wrap(function(err, fname, status)
|
|
||||||
if err then
|
|
||||||
vim.notify('[clangd] Watcher error: ' .. err, vim.log.levels.ERROR)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if fname and fname:match '[\\/].*compile_commands%.json$' and status.change then
|
|
||||||
if debounce_timer then
|
|
||||||
debounce_timer:stop()
|
|
||||||
debounce_timer:close()
|
|
||||||
end
|
|
||||||
debounce_timer = uv.new_timer()
|
|
||||||
debounce_timer:start(200, 0, function()
|
|
||||||
vim.schedule(function()
|
|
||||||
vim.notify '[clangd] Detected compile_commands.json change. Restarting clangd...'
|
|
||||||
reload_callback()
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
M.get_server_config = function()
|
|
||||||
local dir = find_compile_commands()
|
|
||||||
local cmd = {
|
|
||||||
'clangd',
|
|
||||||
'--background-index',
|
|
||||||
'--clang-tidy',
|
|
||||||
'--header-insertion=never',
|
|
||||||
'--query-driver=' .. vim.fn.exepath 'clang++',
|
|
||||||
'--resource-dir=' .. vim.fn.systemlist({ 'clang++', '--print-resource-dir' })[1],
|
|
||||||
}
|
|
||||||
|
|
||||||
if dir then
|
|
||||||
table.insert(cmd, '--compile-commands-dir=' .. dir)
|
|
||||||
else
|
|
||||||
vim.notify '[clangd] Could not find compile_commands.json. clangd may still work in single-file mode.'
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
|
||||||
cmd = cmd,
|
|
||||||
filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
|
|
||||||
capabilities = require('blink.cmp').get_lsp_capabilities(),
|
|
||||||
root_dir = lspconfig_util.root_pattern '.git',
|
|
||||||
single_file_support = true,
|
|
||||||
on_attach = function(client, bufnr)
|
|
||||||
vim.notify('[clangd] Attached to buffer ' .. bufnr)
|
|
||||||
if dir then
|
|
||||||
start_watcher(dir, function()
|
|
||||||
client.stop()
|
|
||||||
vim.defer_fn(function()
|
|
||||||
vim.cmd 'edit' -- reloads current buffer to re-trigger LSP attach
|
|
||||||
end, 100)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.api.nvim_create_user_command('ReloadClangd', function()
|
|
||||||
local clients = vim.lsp.get_active_clients()
|
|
||||||
for _, client in ipairs(clients) do
|
|
||||||
if client.name == 'clangd' then
|
|
||||||
client.stop { force = true }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.defer_fn(function()
|
|
||||||
vim.cmd 'edit'
|
|
||||||
end, 100)
|
|
||||||
|
|
||||||
vim.notify '[clangd] Restarted manually via :ReloadClangd'
|
|
||||||
end, { desc = 'manually reload clangd with updated compile_commands.json' })
|
|
||||||
|
|
||||||
return M
|
|
|
@ -1,4 +1,3 @@
|
||||||
return {
|
return {
|
||||||
require 'custom.plugins.lsp.lsp',
|
require 'custom.plugins.lsp.lsp',
|
||||||
require 'custom.plugins.lsp.clangd',
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,25 @@ return {
|
||||||
{
|
{
|
||||||
'neovim/nvim-lspconfig',
|
'neovim/nvim-lspconfig',
|
||||||
-- only load when editing these filetypes (optional)
|
-- only load when editing these filetypes (optional)
|
||||||
ft = { 'python', 'lua', 'nix', 'rust', 'go' },
|
ft = { 'python', 'lua', 'nix', 'rust', 'go', 'c', 'cpp' },
|
||||||
opts = function()
|
opts = function()
|
||||||
local lspconfig = require 'lspconfig'
|
local lspconfig = require 'lspconfig'
|
||||||
local capabilities = require('blink.cmp').get_lsp_capabilities()
|
local capabilities = require('blink.cmp').get_lsp_capabilities()
|
||||||
|
|
||||||
local servers = {
|
local servers = {
|
||||||
|
clangd = {
|
||||||
|
cmd = {
|
||||||
|
'clangd',
|
||||||
|
'--background-index',
|
||||||
|
'--clang-tidy',
|
||||||
|
'--header-insertion=never',
|
||||||
|
'--query-driver=' .. vim.fn.exepath('clang++'),
|
||||||
|
'--resource-dir=' .. vim.fn.systemlist({ 'clang++', '--print-resource-dir' })[1],
|
||||||
|
},
|
||||||
|
filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
|
||||||
|
root_dir = require('lspconfig.util').root_pattern('.git'),
|
||||||
|
single_file_support = true,
|
||||||
|
},
|
||||||
pyright = {
|
pyright = {
|
||||||
settings = {
|
settings = {
|
||||||
python = {
|
python = {
|
||||||
|
@ -32,20 +45,6 @@ return {
|
||||||
filetypes = { 'cmake' },
|
filetypes = { 'cmake' },
|
||||||
root_dir = require('lspconfig.util').root_pattern('CMakeLists.txt', '.git'),
|
root_dir = require('lspconfig.util').root_pattern('CMakeLists.txt', '.git'),
|
||||||
},
|
},
|
||||||
clangd = (function()
|
|
||||||
local cmd = { 'clangd', '--background-index' }
|
|
||||||
return {
|
|
||||||
cmd = cmd,
|
|
||||||
filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
|
|
||||||
root_dir = lspconfig.util.root_pattern('compile_commands.json', '.git'),
|
|
||||||
single_file_support = true,
|
|
||||||
-- on_attach = function(client, bufnr)
|
|
||||||
-- local util = require(custom.plugins.lsp.clangd_helper)
|
|
||||||
-- util.notify_compile_commands(bufnr)
|
|
||||||
-- util.start_compile_commands_watcher(client, bufnr)
|
|
||||||
-- end,
|
|
||||||
}
|
|
||||||
end)(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, config in pairs(servers) do
|
for name, config in pairs(servers) do
|
||||||
|
|
Loading…
Reference in New Issue