Skip to content

Commit

Permalink
Revert "feat: auto compile before debug (#1367)." (#1398)
Browse files Browse the repository at this point in the history
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

If you want to utilize this function, please refer to the previous impl and add it on your own. (a1c76b2)

Co-authored-by: ayamir <[email protected]>
  • Loading branch information
Jint-lzxy and ayamir authored Feb 5, 2025
1 parent 9b68a66 commit 1e5769f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
- uses: actions/checkout@v4
- uses: lunarmodules/luacheck@v1
with:
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
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
36 changes: 0 additions & 36 deletions lua/keymap/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,3 @@ _G._toggle_lazygit = function()
vim.notify("Command [lazygit] not found!", vim.log.levels.ERROR, { title = "toggleterm.nvim" })
end
end
_G._async_compile_and_debug = function()
local file_ext = vim.fn.expand("%:e")
local file_path = vim.fn.expand("%:p")
local out_name = vim.fn.expand("%:p:h") .. "/" .. vim.fn.expand("%:t:r") .. ".out"
local compile_cmd
if file_ext == "cpp" or file_ext == "cc" then
compile_cmd = string.format("g++ -g %s -o %s", file_path, out_name)
elseif file_ext == "c" then
compile_cmd = string.format("gcc -g %s -o %s", file_path, out_name)
elseif file_ext == "go" then
compile_cmd = string.format("go build -o %s %s", out_name, file_path)
else
require("dap").continue()
return
end
local notify_title = "Debug Pre-compile"
vim.fn.jobstart(compile_cmd, {
on_exit = function(_, exit_code, _)
if exit_code == 0 then
vim.notify(
"Compilation succeeded! Executable: " .. out_name,
vim.log.levels.INFO,
{ title = notify_title }
)
require("dap").continue()
return
else
vim.notify(
"Compilation failed with exit code: " .. exit_code,
vim.log.levels.ERROR,
{ title = notify_title }
)
end
end,
})
end
2 changes: 1 addition & 1 deletion lua/keymap/tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ local mappings = {

-- Plugin: dap
["n|<F6>"] = map_callback(function()
_async_compile_and_debug()
require("dap").continue()
end)
:with_noremap()
:with_silent()
Expand Down
6 changes: 1 addition & 5 deletions lua/modules/utils/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ function M.input_args()
end

function M.input_exec_path()
return vim.fn.input(
'Path to executable (default to "filename.out"): ',
vim.fn.expand("%:p:h") .. "/" .. vim.fn.expand("%:t:r") .. ".out",
"file"
)
return vim.fn.input('Path to executable (default to "a.out"): ', vim.fn.expand("%:p:h") .. "/a.out", "file")
end

function M.input_file_path()
Expand Down

0 comments on commit 1e5769f

Please sign in to comment.