aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Rozanov <daniilrozzanov@gmail.com>2024-04-24 04:06:35 +0300
committerDaniil Rozanov <daniilrozzanov@gmail.com>2024-04-24 04:06:35 +0300
commit0703f679c83da5254f50b1e78af1220a3a6882a4 (patch)
treed56bb692b3a2652cc1e727872d3f7f496051aa8c
parentf9b36bf730fda5488be87b91fd03a6f7cbf64e73 (diff)
fix: properly run last executable
-rw-r--r--lua/cmake/actions.lua19
-rw-r--r--lua/cmake/commands.lua4
-rw-r--r--lua/cmake/config.lua7
-rw-r--r--lua/cmake/terminal.lua20
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