Skip to content

Commit

Permalink
Add DduFilterItems
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Jul 18, 2023
1 parent be34096 commit feaa662
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion denops/ddu/base/filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Context,
DduFilterItems,
DduItem,
DduOptions,
FilterOptions,
Expand Down Expand Up @@ -43,7 +44,7 @@ export abstract class BaseFilter<Params extends BaseFilterParams> {

async onRefreshItems(_args: OnRefreshItemsArguments<Params>): Promise<void> {}

abstract filter({}: FilterArguments<Params>): Promise<DduItem[]>;
abstract filter({}: FilterArguments<Params>): Promise<DduFilterItems>;

abstract params(): Params;
}
Expand Down
13 changes: 12 additions & 1 deletion denops/ddu/ddu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
echo,
equal,
fn,
is,
Lock,
pathsep,
} from "./deps.ts";
Expand Down Expand Up @@ -1683,7 +1684,7 @@ export class Ddu {
}

try {
items = await filter.filter({
const ret = await filter.filter({
denops,
context: this.context,
options: this.options,
Expand All @@ -1693,6 +1694,16 @@ export class Ddu {
input,
items,
});

if (is.Array(ret)) {
items = ret;
} else {
if (ret.input) {
// Overwrite current input
input = ret.input;
}
items = ret.items;
}
} catch (e: unknown) {
await errorException(
denops,
Expand Down
6 changes: 6 additions & 0 deletions denops/ddu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ export type ExpandItem = {
search?: TreePath;
};

export type DduFilterItems = DduItem[] | {
items: DduItem[];
input?: string;
postActionCommand?: string;
};

export type ActionArguments<Params extends BaseActionParams> = {
denops: Denops;
context: Context;
Expand Down
11 changes: 11 additions & 0 deletions doc/ddu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,17 @@ FILTER ATTRIBUTES *ddu-filter-attributes*
*ddu-filter-attribute-filter*
filter (function) (Required)
It is called to filter items.
The return type is DduItem[] or following object.

input (string) (Optional)
Overwrite current input.
NOTE: The overwrite is avaiable for current filters list only.

items (DduItem[]) (Required)
Filtered items.

postActionCommand (string) (Optional)
TODO.

*ddu-filter-attribute-onInit*
onInit (function) (Optional)
Expand Down

0 comments on commit feaa662

Please sign in to comment.