fix: 🥱

This commit is contained in:
dlond 2025-09-03 11:16:05 +12:00 committed by Daniel Lond
parent 2f5b161f71
commit 9e6b01e176
1 changed files with 34 additions and 11 deletions

View File

@ -3,11 +3,23 @@ local M = {}
local util = require 'lspconfig.util' local util = require 'lspconfig.util'
-- Get clang-wrapper resource-root for Nix environments
local function get_clang_resource_dir()
-- Try to find clang-wrapper's resource-root
local handle = io.popen('ls -d /nix/store/*clang-wrapper*/resource-root 2>/dev/null | head -1')
if handle then
local resource_root = handle:read('*l')
handle:close()
if resource_root and resource_root ~= '' then
return resource_root
end
end
return nil -- Let clangd use its default
end
function M.get_servers() function M.get_servers()
return { -- Build clangd command
-- C/C++ Language Server local clangd_cmd = {
clangd = {
cmd = {
'clangd', 'clangd',
'--query-driver=/nix/store/*/bin/clang*', '--query-driver=/nix/store/*/bin/clang*',
'--background-index', '--background-index',
@ -17,7 +29,18 @@ function M.get_servers()
'--function-arg-placeholders', '--function-arg-placeholders',
'--header-insertion-decorators', '--header-insertion-decorators',
'--header-insertion=iwyu', '--header-insertion=iwyu',
}, }
-- Add resource-dir if in Nix environment
local resource_dir = get_clang_resource_dir()
if resource_dir then
table.insert(clangd_cmd, '--resource-dir=' .. resource_dir)
end
return {
-- C/C++ Language Server
clangd = {
cmd = clangd_cmd,
filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda' },
-- Look for project markers - clangd will find compile_commands.json itself -- Look for project markers - clangd will find compile_commands.json itself
root_dir = util.root_pattern( root_dir = util.root_pattern(