Skip to content

Commit 2eff96c

Browse files
committed
Revert "feat: auto compile before debug (#1367). (#1368)"
This PR reverts commit a1c76b2. The main rationale behind this is IMO the current implementation of this function has several limitations that need to be addressed: 1. It works with only a single file, which is not typical for most use cases 2. It only supports gcc as the compiler, whereas other compilers (most notably clang, xlc, cl.exe and friends) are not supported 3. There's no way to control compile and/or build flags. 4. File type detection is too restrictive and doesn't cover all cases (using vim's ftplugins may be more effective) and 5. Violating any of these assumptions results in errors, rendering this keymap completely ineffective.
1 parent a02472d commit 2eff96c

File tree

4 files changed

+3
-44
lines changed

4 files changed

+3
-44
lines changed

.github/workflows/lint_code.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ jobs:
88
- uses: actions/checkout@v4
99
- uses: lunarmodules/luacheck@v1
1010
with:
11-
args: . --std luajit --globals vim _debugging _command_panel _flash_esc_or_noh _telescope_collections _toggle_lazygit _toggle_diagnostic _toggle_inlayhint _async_compile_and_debug --max-line-length 150 --no-config
11+
args: . --std luajit --globals vim _debugging _command_panel _flash_esc_or_noh _telescope_collections _toggle_lazygit _toggle_diagnostic _toggle_inlayhint --max-line-length 150 --no-config

lua/keymap/helpers.lua

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -90,40 +90,3 @@ _G._toggle_diagnostic = function()
9090
end
9191
end
9292
end
93-
94-
_G._async_compile_and_debug = function()
95-
local file_ext = vim.fn.expand("%:e")
96-
local file_path = vim.fn.expand("%:p")
97-
local out_name = vim.fn.expand("%:p:h") .. "/" .. vim.fn.expand("%:t:r") .. ".out"
98-
local compile_cmd
99-
if file_ext == "cpp" or file_ext == "cc" then
100-
compile_cmd = string.format("g++ -g %s -o %s", file_path, out_name)
101-
elseif file_ext == "c" then
102-
compile_cmd = string.format("gcc -g %s -o %s", file_path, out_name)
103-
elseif file_ext == "go" then
104-
compile_cmd = string.format("go build -o %s %s", out_name, file_path)
105-
else
106-
require("dap").continue()
107-
return
108-
end
109-
local notify_title = "Debug Pre-compile"
110-
vim.fn.jobstart(compile_cmd, {
111-
on_exit = function(_, exit_code, _)
112-
if exit_code == 0 then
113-
vim.notify(
114-
"Compilation succeeded! Executable: " .. out_name,
115-
vim.log.levels.INFO,
116-
{ title = notify_title }
117-
)
118-
require("dap").continue()
119-
return
120-
else
121-
vim.notify(
122-
"Compilation failed with exit code: " .. exit_code,
123-
vim.log.levels.ERROR,
124-
{ title = notify_title }
125-
)
126-
end
127-
end,
128-
})
129-
end

lua/keymap/tool.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ local plug_map = {
141141

142142
-- Plugin: dap
143143
["n|<F6>"] = map_callback(function()
144-
_async_compile_and_debug()
144+
require("dap").continue()
145145
end)
146146
:with_noremap()
147147
:with_silent()

lua/modules/utils/dap.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ function M.input_args()
66
end
77

88
function M.input_exec_path()
9-
return vim.fn.input(
10-
'Path to executable (default to "filename.out"): ',
11-
vim.fn.expand("%:p:h") .. "/" .. vim.fn.expand("%:t:r") .. ".out",
12-
"file"
13-
)
9+
return vim.fn.input('Path to executable (default to "a.out"): ', vim.fn.expand("%:p:h") .. "/a.out", "file")
1410
end
1511

1612
function M.input_file_path()

0 commit comments

Comments
 (0)