From 4b273ddb1ff9d1bd21df77a022402f6b5cd1e62d Mon Sep 17 00:00:00 2001 From: Denzel <> Date: Mon, 30 Mar 2026 18:55:35 +0200 Subject: [PATCH] resolve compile commands target lazily --- lua/cmake-tools/const.lua | 3 ++- lua/cmake-tools/init.lua | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lua/cmake-tools/const.lua b/lua/cmake-tools/const.lua index c1f94df..71f0253 100644 --- a/lua/cmake-tools/const.lua +++ b/lua/cmake-tools/const.lua @@ -21,7 +21,8 @@ local const = { -- copy: this will automatically copy compile commands file to target -- lsp: this will automatically set compile commands file location using lsp -- none: this will make this option ignored - target = vim.loop.cwd(), -- path to directory, this is used only if action == "soft_link" or action == "copy" + ---@type string|fun(): string + target = vim.loop.cwd, -- path or function returning path to directory, this is used only if action == "soft_link" or action == "copy" }, cmake_kits_path = nil, -- this is used to specify global cmake kits path, see CMakeKits for detailed usage cmake_variants_message = { diff --git a/lua/cmake-tools/init.lua b/lua/cmake-tools/init.lua index a5397f5..229810a 100644 --- a/lua/cmake-tools/init.lua +++ b/lua/cmake-tools/init.lua @@ -1482,7 +1482,11 @@ function cmake.copy_compile_commands() end local source = config:build_directory_path() .. "/compile_commands.json" - local destination = const.cmake_compile_commands_options.target .. "/compile_commands.json" + local target = const.cmake_compile_commands_options.target + if type(target) == "function" then + target = target() + end + local destination = target .. "/compile_commands.json" utils.copyfile(source, destination) end @@ -1492,7 +1496,11 @@ function cmake.compile_commands_from_soft_link() end local source = config:build_directory_path() .. "/compile_commands.json" - local destination = const.cmake_compile_commands_options.target .. "/compile_commands.json" + local target = const.cmake_compile_commands_options.target + if type(target) == "function" then + target = target() + end + local destination = target .. "/compile_commands.json" utils.softlink(source, destination) end