Skip to content

Commit

Permalink
refactor: Refactor quickfix action code (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
ic-768 authored Jun 13, 2024
1 parent 237f89d commit 014a048
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/actions/globalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,23 +785,28 @@ export function loadGlobalActions(action: ActionExplorer) {
const argAction = (args[0] ?? 'replace') as QuickfixAction;
const action = { add: 'a', replace: 'r' }[argAction];
const list: { bufnr: number }[] = await nvim.call('getqflist');
const existFullpathes = list
const existFullpaths = list
.map((it) => source.bufManager.getBufferNode(it.bufnr)?.fullpath)
.filter(Boolean) as string[];
await nvim.call('setqflist', [
nodes
.filter((it) => it.fullpath && !it.expandable)
.map((it) => {
const fullpath = it.fullpath!;
if (existFullpathes.includes(fullpath)) return undefined;
const realtive = pathLib.relative(source.root, fullpath);
return {
filename: it.fullpath,
text: realtive,
lnum: 1,
};
})
.filter(Boolean),
nodes.reduce<{ filename: string; text: string; lnum: number }[]>(
(acc, it) => {
if (
it.fullpath &&
!it.expandable &&
!existFullpaths.includes(it.fullpath)
) {
const relative = pathLib.relative(source.root, it.fullpath);
acc.push({
filename: it.fullpath,
text: relative,
lnum: 1,
});
}
return acc;
},
[],
),
action,
]);
const openCommand = (await nvim.getVar(
Expand Down

0 comments on commit 014a048

Please sign in to comment.