aboutsummaryrefslogtreecommitdiff
path: root/lua/cmake-explorer.lua
diff options
context:
space:
mode:
authorDaniil Rozanov <daniilrozzanov@gmail.com>2024-03-14 23:42:56 +0300
committerDaniil Rozanov <daniilrozzanov@gmail.com>2024-03-14 23:42:56 +0300
commitd36594025727d32b6580f188a4c0476aaeecfd77 (patch)
treeb9f7d1f8942e93b7f75fb1391dc9060332cb4f41 /lua/cmake-explorer.lua
parenta60cc7fcc6375350e9f7720d0ae095aed7f24b67 (diff)
feat: initial ability to configure
Diffstat (limited to 'lua/cmake-explorer.lua')
-rw-r--r--lua/cmake-explorer.lua68
1 files changed, 68 insertions, 0 deletions
diff --git a/lua/cmake-explorer.lua b/lua/cmake-explorer.lua
new file mode 100644
index 0000000..8e01a57
--- /dev/null
+++ b/lua/cmake-explorer.lua
@@ -0,0 +1,68 @@
+local globals = require("cmake-explorer.globals")
+local config = require("cmake-explorer.config")
+local runner = require("cmake-explorer.runner")
+local Project = require("cmake-explorer.project")
+local Build = require("cmake-explorer.build")
+
+local M = {}
+
+local projects = {}
+
+local current_project = nil
+
+local function set_current_project(path)
+ if path then
+ for _, v in ipairs(projects) do
+ -- print(v.path:absolute() .. " ? " .. path)
+ if v.path:absolute() == path then
+ current_project = v
+ return
+ end
+ end
+ end
+ if #projects ~= 0 then
+ current_project = projects[1]
+ else
+ print("set_current_project. no projects available")
+ end
+end
+
+function M.list_build_dirs()
+ if current_project then
+ vim.print(current_project:list_build_dirs_names())
+ end
+end
+
+function M.configure(opts)
+ print("configure. #projects " .. #projects)
+ if current_project then
+ runner.start(current_project:configure(opts))
+ end
+end
+
+M.setup = function(cfg)
+ cfg = cfg or {}
+ globals.setup()
+ config.setup(cfg)
+
+ projects = { Project:new(vim.loop.cwd()) }
+ set_current_project()
+
+ local cmd = vim.api.nvim_create_user_command
+
+ cmd("CMakeConfigure", function(opts)
+ if #opts.fargs ~= 0 then
+ M.configure({ build_type = opts.fargs[1] })
+ else
+ M.configure()
+ end
+ end, { -- opts
+ nargs = "*",
+ bang = true,
+ desc = "CMake configure",
+ })
+
+ cmd("CMakeListBuildDirs", M.list_build_dirs, { nargs = 0 })
+end
+
+return M