try simplify clangd lsp

This commit is contained in:
dlond 2025-05-21 19:03:46 +12:00
parent a5ece39d80
commit e3507c1e65
1 changed files with 26 additions and 26 deletions

View File

@ -19,12 +19,12 @@ return {
-- It sets up the LSP servers. -- It sets up the LSP servers.
-- Load Nix-provided paths from the generated Lua file -- Load Nix-provided paths from the generated Lua file
package.loaded['custom.nix_paths'] = nil -- package.loaded['custom.nix_paths'] = nil
local nix_paths_status, nix_paths = pcall(require, 'custom.nix_paths') -- local nix_paths_status, nix_paths = pcall(require, 'custom.nix_paths')
if not nix_paths_status then -- if not nix_paths_status then
vim.notify('Error loading custom.nix_paths: ' .. (nix_paths or 'Unknown error'), vim.log.levels.ERROR) -- vim.notify('Error loading custom.nix_paths: ' .. (nix_paths or 'Unknown error'), vim.log.levels.ERROR)
nix_paths = {} -- Provide an empty table to avoid further errors -- nix_paths = {} -- Provide an empty table to avoid further errors
end -- end
-- print('DEBUG: nix_paths content: ' .. vim.inspect(nix_paths)) -- print('DEBUG: nix_paths content: ' .. vim.inspect(nix_paths))
@ -48,26 +48,26 @@ return {
}, },
}, },
clangd = { clangd = {
cmd = (function() -- cmd = (function()
if nix_paths.clang_driver_path then -- if nix_paths.clang_driver_path then
return { -- return {
'clangd', -- 'clangd',
'--query-driver=' .. nix_paths.clang_driver_path, -- '--query-driver=' .. nix_paths.clang_driver_path,
-- No other compiler flags like -isysroot or -isystem should be passed directly here. -- -- No other compiler flags like -isysroot or -isystem should be passed directly here.
-- Clangd gets those from compile_commands.json or by querying the driver. -- -- Clangd gets those from compile_commands.json or by querying the driver.
'--compile-commands-dir=' -- '--compile-commands-dir='
.. vim.fn.getcwd() -- .. vim.fn.getcwd()
.. '/build', -- Ensure clangd finds compile_commands.json -- .. '/build', -- Ensure clangd finds compile_commands.json
} -- }
else -- else
vim.notify( -- vim.notify(
'Warning: Nix path for clang_driver_path not defined in custom.nix_paths.lua. Clangd might use system clangd or have issues.', -- 'Warning: Nix path for clang_driver_path not defined in custom.nix_paths.lua. Clangd might use system clangd or have issues.',
vim.log.levels.WARN -- vim.log.levels.WARN
) -- )
return { 'clangd' } -- Fallback -- return { 'clangd' } -- Fallback
end -- end
end)(), -- end)(),
root_dir = require('lspconfig.util').root_pattern('compile_commands.json', '.git'), -- Helps find project root root_dir = require('lspconfig.util').root_pattern('compile_commands.json', '.git', '.clangd'), -- Helps find project root
}, },
pyright = { pyright = {
settings = { settings = {