@@ -3,21 +3,44 @@ local M = {}
33
44local util = require ' lspconfig.util'
55
6+ -- Get clang-wrapper resource-root for Nix environments
7+ local function get_clang_resource_dir ()
8+ -- Try to find clang-wrapper's resource-root
9+ local handle = io.popen (' ls -d /nix/store/*clang-wrapper*/resource-root 2>/dev/null | head -1' )
10+ if handle then
11+ local resource_root = handle :read (' *l' )
12+ handle :close ()
13+ if resource_root and resource_root ~= ' ' then
14+ return resource_root
15+ end
16+ end
17+ return nil -- Let clangd use its default
18+ end
19+
620function M .get_servers ()
21+ -- Build clangd command
22+ local clangd_cmd = {
23+ ' clangd' ,
24+ ' --query-driver=/nix/store/*/bin/clang*' ,
25+ ' --background-index' ,
26+ ' --clang-tidy' ,
27+ ' --enable-config' ,
28+ ' --fallback-style=llvm' ,
29+ ' --function-arg-placeholders' ,
30+ ' --header-insertion-decorators' ,
31+ ' --header-insertion=iwyu' ,
32+ }
33+
34+ -- Add resource-dir if in Nix environment
35+ local resource_dir = get_clang_resource_dir ()
36+ if resource_dir then
37+ table.insert (clangd_cmd , ' --resource-dir=' .. resource_dir )
38+ end
39+
740 return {
841 -- C/C++ Language Server
942 clangd = {
10- cmd = {
11- ' clangd' ,
12- ' --query-driver=/nix/store/*/bin/clang*' ,
13- ' --background-index' ,
14- ' --clang-tidy' ,
15- ' --enable-config' ,
16- ' --fallback-style=llvm' ,
17- ' --function-arg-placeholders' ,
18- ' --header-insertion-decorators' ,
19- ' --header-insertion=iwyu' ,
20- },
43+ cmd = clangd_cmd ,
2144 filetypes = { ' c' , ' cpp' , ' objc' , ' objcpp' , ' cuda' },
2245 -- Look for project markers - clangd will find compile_commands.json itself
2346 root_dir = util .root_pattern (
0 commit comments