add some bugs

This commit is contained in:
dlond 2025-05-27 03:50:02 +12:00
parent 0a859f314e
commit 2113b33a58
4 changed files with 62 additions and 9 deletions

View File

@ -20,6 +20,7 @@ vim.keymap.set('n', '<C-j>', '<C-w><C-j>', { desc = 'Move focus to the lower win
vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' }) vim.keymap.set('n', '<C-k>', '<C-w><C-k>', { desc = 'Move focus to the upper window' })
-- Add any other general-purpose keymaps you want here -- Add any other general-purpose keymaps you want here
vim.keymap.set('n', '
-- 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 {}

View File

@ -74,7 +74,8 @@ return {
type = 'lldb', type = 'lldb',
request = 'launch', request = 'launch',
program = function() program = function()
return require('custom.utils').pick_executable(vim.fn.getcwd() .. '/build') local target = require('custom.target'):get_target()
return require('custom.utils').pick_executable(vim.fn.getcwd() .. / .. target)
end, end,
cwd = '${workspaceFolder}', cwd = '${workspaceFolder}',
stopOnEntry = false, stopOnEntry = false,

View File

@ -13,8 +13,6 @@ return {
'hrsh7th/cmp-nvim-lsp', -- LSP completion source for nvim-cmp 'hrsh7th/cmp-nvim-lsp', -- LSP completion source for nvim-cmp
}, },
config = function(_, opts) config = function(_, opts)
-- local query_driver = vim.fn.trim(vim.fn.system 'which clang++')
-- local resource_dir = vim.fn.trim(vim.fn.system 'clang++ --print-resource-dir')
-- This config function runs AFTER the plugin and its dependencies are loaded. -- This config function runs AFTER the plugin and its dependencies are loaded.
-- It sets up the LSP servers. -- It sets up the LSP servers.
@ -23,6 +21,8 @@ return {
-- Define the list of LSP servers you want to configure. -- Define the list of LSP servers you want to configure.
-- These servers must be installed via Nix/Home Manager and be in your PATH. -- These servers must be installed via Nix/Home Manager and be in your PATH.
local utils = require 'custom.utils'
local target = utils:get_target()
local servers = { local servers = {
lua_ls = { lua_ls = {
-- cmd = { ... } -- cmd = { ... }
@ -38,12 +38,7 @@ return {
}, },
}, },
clangd = { clangd = {
cmd = { cmd = utils.make_clangd_cmd(target),
'clangd',
'--compile-commands-dir=build/debug',
'--query-driver=' .. vim.fn.trim(vim.fn.system 'which clang++'),
'--resource-dir=' .. vim.fn.trim(vim.fn.system 'clang++ --print-resource-dir'),
},
filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
root_dir = require('lspconfig.util').root_pattern('CMakeLists.txt', '.git'), root_dir = require('lspconfig.util').root_pattern('CMakeLists.txt', '.git'),
}, },

View File

@ -66,4 +66,60 @@ end
return { return {
pick_executable = pick_executable, pick_executable = pick_executable,
clangd_base_cmd = {
'clangd',
'--background-index',
'--clang-tidy',
'--header-insertion=never',
'--query-driver=' .. vim.fn.trim(vim.fn.system 'which clang++'),
'--resource-dir=' .. vim.fn.trim(vim.fn.system 'clang++ --print-resource-dir'),
},
make_clangd_cmd = function(self, compile_commands_dir)
local cmd = vim.deepcopy(self.clangd_base_cmd)
table.insert(cmd, '--compile-commands-dir=' .. compile_commands_dir)
return cmd
end,
find_targets = function()
return vim.fn.systemlist 'fd -u compile_commands.json -x dirname {}'
end,
get_target = function(self)
return vim.g.current_target_dir or 'build/debug'
end,
set_target = function(self, dir)
vim.g.current_target_dir = dir
self:reload_clangd()
end,
pick_target = function(self)
local targets = self.find_targets()
if vim.tbl_isempty(targets) then
vim.notify('No build targets found.', vim.log.WARN)
return
end
vim.ui.select(targets, { prompt = 'Select build target:' }, function(choice)
if choice then
self:set_target(choice)
end
end)
end,
reload_clangd = function(self)
local lspconfig = require 'lspconfig'
local clients = vim.lsp.get_active_clients { name = 'clangd' }
for _, cliet in ipairs(clients) do
client.stop()
end
vim.defer_fn(function()
lspconfig.clangd.setup {
cmd = self:make_clangd_cmd(self:get_target()),
}
vim.cmd 'edit'
end, 200)
end,
} }