From 0703f679c83da5254f50b1e78af1220a3a6882a4 Mon Sep 17 00:00:00 2001 From: Daniil Rozanov Date: Wed, 24 Apr 2024 04:06:35 +0300 Subject: fix: properly run last executable --- lua/cmake/actions.lua | 19 ++++++++++++++++--- lua/cmake/commands.lua | 4 ++++ lua/cmake/config.lua | 7 ------- lua/cmake/terminal.lua | 20 ++++++++++++-------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lua/cmake/actions.lua b/lua/cmake/actions.lua index d330a0a..ff64f95 100644 --- a/lua/cmake/actions.lua +++ b/lua/cmake/actions.lua @@ -1,6 +1,7 @@ local pr = require("cmake.project") local config = require("cmake.config") local t = require("cmake.terminal") +local Path = require("plenary.path") local M = {} @@ -83,7 +84,16 @@ M.build_select = function(opts) end M.run_tagret = function(opts) - return + opts = opts or {} + local _curr_exe_cmd = pr.current_executable_target() + if not _curr_exe_cmd then + M.run_tagret_select(opts) + else + local command = { + cmd = Path:new(pr.current_directory(), _curr_exe_cmd.path):make_relative(vim.loop.cwd()), + } + t.target_execute(command) + end end M.run_tagret_select = function(opts) @@ -101,11 +111,14 @@ M.run_tagret_select = function(opts) end pr.set_current_executable_target(idx) local command = { - cwd = pr.current_directory(), - cmd = choice.path, + cmd = Path:new(pr.current_directory(), choice.path):make_relative(vim.loop.cwd()), } t.target_execute(command) end) end +M.toggle = function() + t.cmake_toggle() +end + return M diff --git a/lua/cmake/commands.lua b/lua/cmake/commands.lua index 78e5bb8..f754b1c 100644 --- a/lua/cmake/commands.lua +++ b/lua/cmake/commands.lua @@ -26,6 +26,10 @@ M.register_commands = function() cmd("CMakeRunSelect", function() require("cmake.actions").run_tagret_select() end, { desc = "Select build option and build" }) + + cmd("CMakeToggle", function() + require("cmake.actions").toggle() + end, { desc = "Toggle CMake terminal" }) end return M diff --git a/lua/cmake/config.lua b/lua/cmake/config.lua index 9a0e5ba..3ce4f98 100644 --- a/lua/cmake/config.lua +++ b/lua/cmake/config.lua @@ -17,13 +17,6 @@ local default_config = { release = { short = "Release", long = "Long release", buildType = "Release" }, }, }, - { - default = "static", - choices = { - static = { short = "Static", long = "Long static", linkage = "static" }, - shared = { short = "Shared", long = "Long shared", linkage = "shared" }, - }, - }, }, parallel_jobs = 0, save_before_build = true, diff --git a/lua/cmake/terminal.lua b/lua/cmake/terminal.lua index 9581297..e086644 100644 --- a/lua/cmake/terminal.lua +++ b/lua/cmake/terminal.lua @@ -61,7 +61,11 @@ M.cmake_execute = function(command, opts) end M.cmake_toggle = function() - cmake:toggle() + if cmake then + cmake:toggle() + else + vim.notify("No CMake terminal") + end end M.target_execute = function(command, opts) @@ -75,16 +79,16 @@ M.target_execute = function(command, opts) if not runnable then runnable = Terminal:new(term_opts) end - local cd = "cd " .. command.cwd - local cmd = "./" .. command.cmd - vim.notify(cd) - vim.notify(cmd) - if not runnable:is_open() then runnable:open() end - runnable:send(cd) - runnable:send(cmd) + vim.notify(vim.inspect(command), vim.log.levels.INFO) + if command.cd then + runnable:send("cd " .. command.cd) + end + if command.cmd then + runnable:send(command.cmd) + end end return M -- cgit v1.2.3