Skip to content

Commit

Permalink
fix(redo): Now also work for bau (build automation utilities)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeioth committed Nov 15, 2023
1 parent c08b32d commit 29635e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
13 changes: 9 additions & 4 deletions lua/compiler/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
local cmd = vim.api.nvim_create_user_command
local M = {}

M.setup = function(ctx)
M.setup = function(opts)
cmd("CompilerOpen", function()
require("compiler.telescope").show()
end, { desc = "Open the compiler" })
Expand All @@ -26,15 +26,20 @@ M.setup = function(ctx)
-- If filetype is not the same as when the option was selected, send a notification.
local current_filetype = vim.bo.filetype
if _G.compiler_redo_filetype ~= current_filetype then
vim.notify("You are on a different language now. Open the compiler and select an option before doing redo.", vim.log.levels.INFO, {
title = "Compiler.nvim"
})
vim.notify("You are on a different language now. Open the compiler and select an option before doing redo.",
vim.log.levels.INFO, { title = "Compiler.nvim" }
)
return
end
-- Redo
local language = require('compiler.utils').require_language(current_filetype)
if not language then language = require("compiler.languages.make") end
language.action(_G.compiler_redo)
-- Redo (bau)
local bau = _G.compiler_redo_bau
local bau_selection = _G.compiler_redo_bau_selection
if bau and bau_selection then bau.action(bau_selection) end

end, { desc = "Redo the last selected compiler option" })

cmd("CompilerStop", function()
Expand Down
16 changes: 11 additions & 5 deletions lua/compiler/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ function M.show()
actions.close(prompt_bufnr) -- Close Telescope on selection
local selection = state.get_selected_entry()
if selection.value == "" then return end -- Ignore separators
_G.compiler_redo = selection.value -- Save redo
_G.compiler_redo_filetype = filetype -- Save redo


if selection then
-- Do the selected option belong to a build automation utility?
Expand All @@ -80,13 +77,22 @@ function M.show()
end
end

-- If any → call the bau backend.
-- If nil → call the language backend.
-- If bau → call the bau backend.
-- If ~=bau → call the language backend.
if bau then
bau = utils_bau.require_bau(bau)
if bau then bau.action(selection.value) end
-- save redo (bau)
_G.compiler_redo_bau = bau
_G.compiler_redo_bau_selection = selection.value
else
language.action(selection.value)
-- save redo (language)
_G.compiler_redo = selection.value
_G.compiler_redo_filetype = filetype
-- clean redo (bau)
_G.compiler_redo_bau = nil
_G.compiler_redo_bau_selection = nil
end

end
Expand Down

0 comments on commit 29635e9

Please sign in to comment.