From d36594025727d32b6580f188a4c0476aaeecfd77 Mon Sep 17 00:00:00 2001 From: Daniil Rozanov Date: Thu, 14 Mar 2024 23:42:56 +0300 Subject: feat: initial ability to configure --- lua/cmake-explorer.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 lua/cmake-explorer.lua (limited to 'lua/cmake-explorer.lua') 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 -- cgit v1.2.3