diff options
author | Daniil Rozanov <daniilrozzanov@gmail.com> | 2024-04-26 03:33:49 +0300 |
---|---|---|
committer | Daniil Rozanov <daniilrozzanov@gmail.com> | 2024-04-26 03:33:49 +0300 |
commit | 0660a9446d4515c9755573152ce944ebf2f019fc (patch) | |
tree | b587c6de58d6475feadade022fa918d15a3eba74 /lua/cmake/project.lua | |
parent | a21a7207041754efdc811493ea131b6dd2d0f944 (diff) |
fix: better autocmds
Correctly process case when neovim opened witn nvim CMakeLists.txt command. At the moment of first setup CMakeLists.txt does not exists, so we need to setup project on BufEnter if it was not inisialized before
Diffstat (limited to 'lua/cmake/project.lua')
-rw-r--r-- | lua/cmake/project.lua | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/lua/cmake/project.lua b/lua/cmake/project.lua index 3b7ed04..6f5a21e 100644 --- a/lua/cmake/project.lua +++ b/lua/cmake/project.lua @@ -7,6 +7,8 @@ local uv = vim.uv or vim.loop local Project = {} +local initialised = false + local configs = {} local current_config = nil local fileapis = {} @@ -15,6 +17,7 @@ local reset_internals = function() configs = {} current_config = nil fileapis = {} + initialised = true end local append_after_success_actions = function() @@ -188,9 +191,7 @@ function Project.create_fileapi_query(opts, callback) end) end -function Project.setup(opts) - opts = opts or {} - reset_internals() +local do_setup = function(opts) local variants_path = vim.fs.joinpath(uv.cwd(), constants.variants_yaml_filename) utils.file_exists(variants_path, function(variants_exists) if variants_exists then @@ -204,4 +205,27 @@ function Project.setup(opts) end) end +function Project.setup(opts) + opts = opts or {} + vim.notify( + "Start setup. " .. vim.inspect(opts.first_time_only) .. " " .. tostring(initialised), + vim.log.levels.INFO + ) + if opts.first_time_only and initialised then + vim.notify( + "Setup abort. " .. vim.inspect(opts.first_time_only) .. " " .. tostring(initialised), + vim.log.levels.INFO + ) + return + end + reset_internals() + if not initialised then + require("cmake.capabilities").setup(function() + do_setup(opts) + end) + else + do_setup(opts) + end +end + return Project |