From 0660a9446d4515c9755573152ce944ebf2f019fc Mon Sep 17 00:00:00 2001 From: Daniil Rozanov Date: Fri, 26 Apr 2024 03:33:49 +0300 Subject: 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 --- lua/cmake/project.lua | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'lua/cmake/project.lua') 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 -- cgit v1.2.3