Skip to content

Commit

Permalink
Merge pull request #241 from Std-Enigma/dev-trouble
Browse files Browse the repository at this point in the history
feat: added trouble.nvim integration
  • Loading branch information
EpsilonKu authored Jun 25, 2024
2 parents ec67d4b + 9770e20 commit 49fae98
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ You may also need to install the following:
- [BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) (finder)
- [devicons](https://github.com/kyazdani42/nvim-web-devicons) (icons)
- [sed](https://www.gnu.org/software/sed/) (replace tool)
- [trouble.nvim](https://github.com/folke/trouble.nvim) (improved quickfix list)

### MacOs

Expand Down Expand Up @@ -282,6 +283,7 @@ require('spectre').setup({
}
},
replace_vim_cmd = "cdo",
use_trouble_qf = false, -- use trouble.nvim as quickfix list
is_open_target_win = true, --open file on opener window
is_insert_mode = false, -- start open panel on is_insert_mode
is_block_ui_break = false -- mapping backspace and enter key to avoid ui break
Expand Down
91 changes: 44 additions & 47 deletions lua/spectre/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,17 @@ end

M.send_to_qf = function()
local entries = M.get_all_entries()
vim.cmd([[copen]])
vim.fn.setqflist(entries, 'r')
vim.fn.setqflist({}, 'r', {
title = string.format('Result Search: [%s]', state.query.search_query),
})
local trouble_avail, _ = pcall(require, 'trouble')
local status = trouble_avail and state.user_config.use_trouble_qf
if status then
vim.cmd([[Trouble quickfix win.relative=win focus=true]])
else
vim.cmd([[copen]])
end
return entries
end

Expand Down Expand Up @@ -223,61 +229,53 @@ M.run_delete_line = function(entries)
local error_item = 0
state.status_line = 'Run Replace.'
local replacer_creator = state_utils.get_replace_creator()
local replacer = replacer_creator:new(state_utils.get_replace_engine_config(),
{
on_done = function(result)
if result.ref then
done_item = done_item + 1
local value = result.ref
state.status_line = 'Delete line: ' .. done_item .. ' Error:' .. error_item
for _, display_lnum in ipairs(value.display_lnums) do
M.set_entry_finish(display_lnum)
api.nvim_buf_set_extmark(
state.bufnr,
config.namespace,
display_lnum,
0,
{ virt_text = { { '󰄲 DONE', 'String' } }, virt_text_pos = 'eol' }
)
end
local replacer = replacer_creator:new(state_utils.get_replace_engine_config(), {
on_done = function(result)
if result.ref then
done_item = done_item + 1
local value = result.ref
state.status_line = 'Delete line: ' .. done_item .. ' Error:' .. error_item
for _, display_lnum in ipairs(value.display_lnums) do
M.set_entry_finish(display_lnum)
api.nvim_buf_set_extmark(
state.bufnr,
config.namespace,
display_lnum,
0,
{ virt_text = { { '󰄲 DONE', 'String' } }, virt_text_pos = 'eol' }
)
end
end,
on_error = function(result)
if result.ref then
error_item = error_item + 1
local value = result.ref
state.status_line = 'Delete line: ' .. done_item .. ' Error:' .. error_item
for _, display_lnum in ipairs(value.display_lnums) do
M.set_entry_finish(display_lnum)
api.nvim_buf_set_extmark(
state.bufnr,
config.namespace,
display_lnum,
0,
{ virt_text = { { '󰄱 ERROR', 'Error' } }, virt_text_pos = 'eol' }
)
end
end
end,
on_error = function(result)
if result.ref then
error_item = error_item + 1
local value = result.ref
state.status_line = 'Delete line: ' .. done_item .. ' Error:' .. error_item
for _, display_lnum in ipairs(value.display_lnums) do
M.set_entry_finish(display_lnum)
api.nvim_buf_set_extmark(
state.bufnr,
config.namespace,
display_lnum,
0,
{ virt_text = { { '󰄱 ERROR', 'Error' } }, virt_text_pos = 'eol' }
)
end
end,
}
)
end
end,
})
local groupby_filename = {}
for _, value in pairs(entries) do
if not groupby_filename[value.filename] then
groupby_filename[value.filename] = {
filename = value.filename,
lnums = { value.lnum },
display_lnums = { value.display_lnum }
display_lnums = { value.display_lnum },
}
else
table.insert(
groupby_filename[value.filename].lnums,
value.lnum
)
table.insert(
groupby_filename[value.filename].display_lnums,
value.display_lnum
)
table.insert(groupby_filename[value.filename].lnums, value.lnum)
table.insert(groupby_filename[value.filename].display_lnums, value.display_lnum)
end
end

Expand All @@ -291,7 +289,6 @@ M.run_delete_line = function(entries)
end
end


M.select_template = function()
if not state.user_config.open_template or #state.user_config.open_template == 0 then
vim.notify('You need to set open_template on setup function.')
Expand Down
5 changes: 3 additions & 2 deletions lua/spectre/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local config = {
namespace_status = api.nvim_create_namespace('SEARCH_PANEL_STATUS'),
namespace_result = api.nvim_create_namespace('SEARCH_PANEL_RESULT'),

lnum_UI = 8, -- total line for ui you can edit it
lnum_UI = 8, -- total line for ui you can edit it
line_result = 10, -- line begin result

-- result_padding = '│ ',
Expand Down Expand Up @@ -126,7 +126,7 @@ local config = {
map = '<leader>rd',
cmd = "<cmd>lua require('spectre.actions').run_delete_line()<CR>",
desc = 'delete line',
}
},
},
find_engine = {
['rg'] = {
Expand Down Expand Up @@ -216,6 +216,7 @@ local config = {
},
},
replace_vim_cmd = 'cdo',
use_trouble_qf = false,
is_open_target_win = true,
is_insert_mode = false,
is_block_ui_break = false,
Expand Down

0 comments on commit 49fae98

Please sign in to comment.