Comments (14)
function cmake.create_regenerate_on_save_autocmd()
local cmake_files = file_picker.get_cmake_files()
local others = { "CMakePresets.json", "CMakeUserPresets.json", "cmake-presets.json", "cmake-user-presets.json", "CMakeVariants.json", "CMakeVariants.yaml", "cmake-variants.yaml", "cmake-variants.json", "CMakeKits.json", "cmake-kits.json" }
local pattern = {}
for _, item in ipairs(cmake_files) do
table.insert(pattern, vim.loop.cwd() .. "/" .. item)
end
for _, item in ipairs(others) do
table.insert(pattern, vim.loop.cwd() .. "/" .. item)
end
if #pattern ~= 0 then
-- for cmake files
vim.api.nvim_create_autocmd("BufWritePre", {
group = group,
pattern = pattern,
callback = function()
print("FILE PICKER", vim.inspect(pattern))
local buf = vim.api.nvim_get_current_buf()
-- Check if buffer is actually modified, and only if it is modified,
-- execute the :CMakeGenerate, otherwise return. This is to avoid unnecessary regenerattion
local buf_modified = vim.api.nvim_buf_get_option(buf, "modified")
if buf_modified then
cmake.generate({ bang = false, fargs = {} }, nil)
end
end,
})
end
end
I think we do. Because what happens if new files are added?
Yes, we should re-register every time after CMakeGenerate.
from cmake-tools.nvim.
Is it normal that users manually change contents of .cmake dir?
from cmake-tools.nvim.
I don't mean the files in the cmake cache. But addidional cmake config files are usually .cmake
.
E.g setting.cmake
and coverage.cmake
. They are part of the source.
from cmake-tools.nvim.
Oh, I understand. Ideally, if they are included in CMakeLists.txt, we should register listener for them.
Follows are files or settings that should register contents change event in my opinion:
.cmake
files that are included in CMakeLists.txtpresets
filesvariants
files (if presets not exists)kits
files (if presets not exists)CMakeSettings
(maybe)
@hfn92 What do you think?
from cmake-tools.nvim.
I've confirmed that .cmake
files that are included in CMakeLists.txt will be included in codemodel file.
from cmake-tools.nvim.
It's not just .cmake
files but also files used in configure_file
. And probably some more. But the codemodel file should contain all those files
from cmake-tools.nvim.
Oh, I understand. Ideally, if they are included in CMakeLists.txt, we should register listener for them.
Follows are files or settings that should register contents change event in my opinion:
.cmake
files that are included in CMakeLists.txtpresets
filesvariants
files (if presets not exists)kits
files (if presets not exists)CMakeSettings
(maybe)@hfn92 What do you think?
I think its better to handle content change of each file in the cmake codemodel as those should include all relevant files.
from cmake-tools.nvim.
function cmake.create_regenerate_on_save_autocmd()
local cmake_files = file_picker.get_cmake_files()
-- for cmake files
vim.api.nvim_create_autocmd("BufWritePre", {
group = group,
pattern = cmake_files,
callback = function()
local buf = vim.api.nvim_get_current_buf()
-- Check if buffer is actually modified, and only if it is modified,
-- execute the :CMakeGenerate, otherwise return. This is to avoid unnecessary regenerattion
local buf_modified = vim.api.nvim_buf_get_option(buf, "modified")
if buf_modified then
cmake.generate({ bang = false, fargs = {} }, nil)
end
end,
})
-- For presets, variants and kits
vim.api.nvim_create_autocmd("BufWritePre", {
group = group,
pattern = { "CMakePresets.json", "CMakeUserPresets.json", "cmake-presets.json", "cmake-user-presets.json", "CMakeVariants.json", "CMakeVariants.yaml", "cmake-variants.yaml", "cmake-variants.json", "CMakeKits.json", "cmake-kits.json" },
callback = function()
local buf = vim.api.nvim_get_current_buf()
-- Check if buffer is actually modified, and only if it is modified,
-- execute the :CMakeGenerate, otherwise return. This is to avoid unnecessary regenerattion
local buf_modified = vim.api.nvim_buf_get_option(buf, "modified")
if buf_modified then
cmake.generate({ bang = false, fargs = {} }, nil)
end
end,
})
end
Do you think it is enough? We should re-register it every time after CMakeGenerate
from cmake-tools.nvim.
I'm not sure. I don't know the vim api well enough. You can test it by adding
configure_file(some_file ${CMAKE_BINARY_DIR}/some_file.junk)
to your CMakeLists.txt. Then changing some_file
should trigger re-generate
from cmake-tools.nvim.
regarding
pattern = { "CMakePresets.json", "CMakeUserPresets.json", "cmake-presets.json", "cmake-user-presets.json", "CMakeVariants.json", "CMakeVariants.yaml", "cmake-variants.yaml", "cmake-variants.json", "CMakeKits.json", "cmake-kits.json" }
I'm not sure if this works. I think once configured, changing files like CMakePresets.json
doesn't affect the already created cmake cache. You'd need to delete cache first I think. So this is probably unnecessary.
from cmake-tools.nvim.
configure_file(some_file ${CMAKE_BINARY_DIR}/some_file.junk)
It works! And turns out we don't need re-register it every time, it's dynamic.
from cmake-tools.nvim.
configure_file(some_file ${CMAKE_BINARY_DIR}/some_file.junk)
It works!
Great! 👍
And turns out we don't need re-register it every time, it's dynamic.
I think we do. Because what happens if new files are added?
from cmake-tools.nvim.
I think once configured, changing files like CMakePresets.json doesn't affect the already created cmake cache. You'd need to delete cache first I think. So this is probably unnecessary.
Presets, variants, and kits have some configuration about cmake generation, they kinda like CMakeLists.txt, so I think it is necessary to watch them.
from cmake-tools.nvim.
I think once configured, changing files like CMakePresets.json doesn't affect the already created cmake cache. You'd need to delete cache first I think. So this is probably unnecessary.
Presets, variants, and kits have some configuration about cmake generation, they kinda like CMakeLists.txt, so I think it is necessary to watch them.
ok, I see
from cmake-tools.nvim.
Related Issues (20)
- Symlink compile_commands.json doesn't appear to work on windows HOT 7
- quick start HOT 4
- on_exit in default terminal.lua HOT 1
- How to choose target when every build/run HOT 18
- targets in buildPresets of CMakePresets.json not honored
- Build Directory Creation will Fail if it Requires a Recursive Create on Windows HOT 4
- Build Directory and Build Targets Not Always Found HOT 11
- Support fish shell HOT 4
- CMakeRun No Output on Windows HOT 5
- Slowdown every time cursor is moved HOT 4
- Whitespace makes CMakeGenerate error HOT 3
- Directory path starting with number causes error
- Feature:Easier to use
- neotest-ctest adapter HOT 3
- Presets are not ignored when `cmake_use_preset` is set to false HOT 5
- Copy compile_commands to a user specified directory after CMake Configure
- target filename HOT 2
- Suggestion: provide a stable callback-based lua API HOT 2
- Automatic split size?
- Disable *cmake-tools* scratch buffer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cmake-tools.nvim.