Skip to content

Commit 1ee065c

Browse files
BenLeadbetterBen Leadbetter
andauthored
feat: adds command to open the cmake cache file (#309)
Co-authored-by: Ben Leadbetter <[email protected]>
1 parent a5d5bf0 commit 1ee065c

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

docs/all_commands.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| CMakeSelectCwd | Opens an input popup to select a directory with the main CMakeLists.txt file. If there's an argument given, that will be treated as the path to the main directory. Attention if you change current working dir, the build directory will still be as before, to change build directory, you should use `CMakeSelectBuildDir`. |
2121
| CMakeSelectBuildDir | Opens an input popup to select a directory where should the build files in. If there's an argument given, that will be treated as the path to the build directory. |
2222
| CMakeOpen(Executor/Runner) | Open CMake Executor/Runner window |
23+
| CMakeOpenCache | Open CMakeCache.txt |
2324
| CMakeClose(Executor/Runner) | Close CMake Executor/Runner window |
2425
| CMakeInstall | Install CMake targets. Additional arguments will be passed to "cmake" command. |
2526
| CMakeClean | Cleans All targets, intermediates and deps |

lua/cmake-tools/init.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,17 @@ function cmake.open_runner()
463463
utils.show_runner(config.runner)
464464
end
465465

466+
function cmake.open_cache()
467+
local path = cmake.get_build_directory() .. "/CMakeCache.txt"
468+
local file = io.open(path, "r")
469+
if file then
470+
file:close()
471+
vim.cmd("edit " .. path)
472+
else
473+
vim.notify("CMakeCache.txt not found", vim.log.levels.ERROR)
474+
end
475+
end
476+
466477
function cmake.substitute_path(path, vars)
467478
for key, value in pairs(vars) do
468479
if type(value) == "string" or type(value) == "number" then

plugin/cmake-tools.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ vim.api.nvim_create_user_command(
108108
}
109109
)
110110

111+
--- CMake open cache
112+
vim.api.nvim_create_user_command(
113+
"CMakeOpenCache", -- name
114+
cmake_tools.open_cache, -- command
115+
{ -- opts
116+
desc = "Open CMakeCache.txt",
117+
}
118+
)
119+
111120
--- CMake run
112121
vim.api.nvim_create_user_command(
113122
"CMakeRun", -- name

0 commit comments

Comments
 (0)