diff --git a/.gitignore b/.gitignore index abb1cdbf..721c83d6 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ nvim spell/ # Project status tracking (local only) +CLAUDE.md STATUS.md VIDINTEL.md diff --git a/init.lua b/init.lua index 34059228..fe6d8a1f 100644 --- a/init.lua +++ b/init.lua @@ -665,7 +665,19 @@ require('lazy').setup({ -- - 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/ 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 = {}, -- pyright = {}, -- rust_analyzer = {}, diff --git a/lua/custom/keymaps.lua b/lua/custom/keymaps.lua index cac73572..f32998b0 100644 --- a/lua/custom/keymaps.lua +++ b/lua/custom/keymaps.lua @@ -1,10 +1,26 @@ -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` --- Add any other general-purpose keymaps you want here -vim.keymap.set('n', 'T', function() - require('custom.lsp.clangd'):pick_target() -end, { desc = 'Choose [T]arget' }) +-- LSP reload function +local function reload_lsp() + local clients = vim.lsp.get_clients() + 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', 'lr', reload_lsp, { desc = '[L]SP [R]eload all servers' }) -- Standard practice for Lua modules that don't need to return complex data return {} diff --git a/lua/custom/options.lua b/lua/custom/options.lua index 4b7a7fb2..c746b294 100644 --- a/lua/custom/options.lua +++ b/lua/custom/options.lua @@ -18,4 +18,3 @@ vim.o.softtabstop = 2 -- 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. --- print 'Custom options loaded!' -- Optional: Add print statement for debugging diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index b73c04ef..0f699e4a 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -3,14 +3,6 @@ -- -- See the kickstart.nvim README for more information 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.debug' }, -- { import = 'custom.plugins.formatting' }, diff --git a/lua/custom/plugins/lsp/clangd_helper.lua b/lua/custom/plugins/lsp/clangd_helper.lua deleted file mode 100644 index 4ebaa5a5..00000000 --- a/lua/custom/plugins/lsp/clangd_helper.lua +++ /dev/null @@ -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 diff --git a/lua/custom/plugins/lsp/init.lua b/lua/custom/plugins/lsp/init.lua index 3606ccbf..000e2c96 100644 --- a/lua/custom/plugins/lsp/init.lua +++ b/lua/custom/plugins/lsp/init.lua @@ -1,4 +1,3 @@ return { require 'custom.plugins.lsp.lsp', - require 'custom.plugins.lsp.clangd', } diff --git a/lua/custom/plugins/lsp/lsp.lua b/lua/custom/plugins/lsp/lsp.lua index f74ab686..cd330778 100644 --- a/lua/custom/plugins/lsp/lsp.lua +++ b/lua/custom/plugins/lsp/lsp.lua @@ -5,12 +5,25 @@ return { { 'neovim/nvim-lspconfig', -- only load when editing these filetypes (optional) - ft = { 'python', 'lua', 'nix', 'rust', 'go' }, + ft = { 'python', 'lua', 'nix', 'rust', 'go', 'c', 'cpp' }, opts = function() local lspconfig = require 'lspconfig' local capabilities = require('blink.cmp').get_lsp_capabilities() 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 = { settings = { python = { @@ -32,20 +45,6 @@ return { filetypes = { 'cmake' }, 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