Skip to content

Commit 2068d8a

Browse files
committed
better error handling
~ updated printed error to display more information about what's missing + added missing error check for xxxBG calls ~ updated readme with Debug commands, and more clarification on config
1 parent c33ce39 commit 2068d8a

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@ require('tmux-compile').setup({
3434
extension = {'c', 'cpp', 'h'},
3535
build = 'make',
3636
run = 'make run',
37+
debug = 'lldb',
3738
},
3839
{
3940
extension = {'rs'},
4041
build = 'cargo build',
4142
run = 'cargo run',
43+
-- not all properties are required for all extensions
4244
},
4345
{
4446
extension = {'go'},
45-
build = 'go build',
4647
run = 'go run .',
48+
-- Run would work for golang
49+
-- but Build and Debug will return errors informing configs are
50+
-- missing
4751
}
4852
}
4953
}},
@@ -74,6 +78,10 @@ vim.keymap.set('n','<F5>', ':TMUXcompile Run<CR>', {silent=true})
7478
| Run program in a tmux new window | `:TMUXcompile RunBG` |
7579
| Run program in a new pane next to current nvim pane | `:TMUXcompile RunV` |
7680
| Run program in a new pane bellow current nvim pane | `:TMUXcompile RunH` |
81+
| Start debugger in an overlay terminal window | `:TMUXcompile Debug` |
82+
| Start debugger in a tmux new window | `:TMUXcompile DebugBG`|
83+
| Start debugger in a new pane next to current nvim pane | `:TMUXcompile DebugV` |
84+
| Start debugger in a new pane bellow current nvim pane | `:TMUXcompile DebugH` |
7785
| Open lazygit in overlay | `:TMUXcompile lazygit`|
7886

7987
\* **Run** here includes both compiling and running the program, depending on the

lua/tmux-compile/init.lua

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,15 @@ end
6969
--# CALL FUNCTIONS #------------------------------------------------------------
7070

7171
-- run command in a new or existing tmux window
72-
local function new_window(cmd)
72+
local function new_window(cmd, error_name)
7373
local window_name = M.config.build_run_window_title
7474

75+
if not cmd then
76+
local extension = get_file_extension()
77+
print("Error: " .. error_name .. " command not found for " .. extension)
78+
return 1
79+
end
80+
7581
if tmux_window_exists(window_name) then
7682
local proj_dir = vim.fn.trim(vim.fn.system("pwd"))
7783
local win_dir = vim.fn.trim(vim.fn.system("tmux display -p -t " .. window_name .. " '#{pane_current_path}'"))
@@ -89,29 +95,33 @@ local function new_window(cmd)
8995
end
9096

9197
-- run command in an overlay pane
92-
local function overlay(cmd, sleep_duration)
93-
if cmd then
94-
local proj_dir = vim.fn.trim(vim.fn.system("pwd"))
95-
local cmd_head = "silent !tmux display-popup -E -d" .. proj_dir
98+
local function overlay(cmd, sleep_duration, error_name)
99+
if not cmd then
100+
local extension = get_file_extension()
101+
print("Error: " .. error_name .. " command not found for " .. extension)
102+
return 1
103+
end
96104

97-
local dimensions = " -w " .. M.config.overlay_width_percent .. "\\% -h " .. M.config.overlay_height_percent .. "\\% '"
105+
local proj_dir = vim.fn.trim(vim.fn.system("pwd"))
106+
local cmd_head = "silent !tmux display-popup -E -d" .. proj_dir
98107

99-
local sleep = "; sleep " .. sleep_duration .. "'"
108+
local dimensions = " -w " .. M.config.overlay_width_percent .. "\\% -h " .. M.config.overlay_height_percent .. "\\% '"
100109

101-
vim.cmd(cmd_head .. dimensions .. cmd .. sleep)
102-
else
103-
print("Error: Command not found for this extension")
104-
end
110+
local sleep = "; sleep " .. sleep_duration .. "'"
111+
112+
vim.cmd(cmd_head .. dimensions .. cmd .. sleep)
105113
end
106114

107115
-- run command in same window on a new pane
108-
local function split_window(cmd, side)
109-
if cmd then
110-
local cmd_head = "silent !tmux split-window " .. side
111-
vim.cmd(cmd_head .. " '" .. cmd .. "; exec zsh'")
112-
else
113-
print("Error: Command not found for this extension")
116+
local function split_window(cmd, side, error_name)
117+
if not cmd then
118+
local extension = get_file_extension()
119+
print("Error: " .. error_name .. " command not found for " .. extension)
120+
return 1
114121
end
122+
123+
local cmd_head = "silent !tmux split-window " .. side
124+
vim.cmd(cmd_head .. " '" .. cmd .. "; exec zsh'")
115125
end
116126

117127
-- run lazygit in an overlay pane

0 commit comments

Comments
 (0)