diff --git a/denops/ddu/base/filter.ts b/denops/ddu/base/filter.ts index 6315541..29ff2d8 100644 --- a/denops/ddu/base/filter.ts +++ b/denops/ddu/base/filter.ts @@ -1,5 +1,6 @@ import { Context, + DduFilterItems, DduItem, DduOptions, FilterOptions, @@ -43,7 +44,7 @@ export abstract class BaseFilter { async onRefreshItems(_args: OnRefreshItemsArguments): Promise {} - abstract filter({}: FilterArguments): Promise; + abstract filter({}: FilterArguments): Promise; abstract params(): Params; } diff --git a/denops/ddu/ddu.ts b/denops/ddu/ddu.ts index c29646a..9dd3ba3 100644 --- a/denops/ddu/ddu.ts +++ b/denops/ddu/ddu.ts @@ -5,6 +5,7 @@ import { echo, equal, fn, + is, Lock, pathsep, } from "./deps.ts"; @@ -1683,7 +1684,7 @@ export class Ddu { } try { - items = await filter.filter({ + const ret = await filter.filter({ denops, context: this.context, options: this.options, @@ -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, diff --git a/denops/ddu/types.ts b/denops/ddu/types.ts index 62be6af..204ffb2 100644 --- a/denops/ddu/types.ts +++ b/denops/ddu/types.ts @@ -206,6 +206,12 @@ export type ExpandItem = { search?: TreePath; }; +export type DduFilterItems = DduItem[] | { + items: DduItem[]; + input?: string; + postActionCommand?: string; +}; + export type ActionArguments = { denops: Denops; context: Context; diff --git a/doc/ddu.txt b/doc/ddu.txt index 4ff09e0..cf59292 100644 --- a/doc/ddu.txt +++ b/doc/ddu.txt @@ -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)