@@ -3,23 +3,35 @@ import { ensurePromise } from "jsr:@core/asyncutil@^1.2.0/ensure-promise";
33import { assert , ensure , is } from "jsr:@core/unknownutil@^4.3.0" ;
44import type { DetailUnit } from "jsr:@vim-fall/core@^0.2.1/item" ;
55
6- import type { GlobalConfig , ItemPickerParams } from "../config.ts" ;
6+ import type { ItemPickerParams } from "../config.ts" ;
77import {
88 getActionPickerParams ,
99 getGlobalConfig ,
1010 getItemPickerParams ,
1111 listItemPickerNames ,
1212 loadUserConfig ,
1313} from "../config.ts" ;
14- import { isOptions , isParams , isStringArray } from "../util/predicate.ts" ;
14+ import {
15+ isGlobalConfig ,
16+ isItemPickerParams ,
17+ isOptions ,
18+ isStringArray ,
19+ } from "../util/predicate.ts" ;
1520import { action as buildActionSource } from "../extension/source/action.ts" ;
1621import { Picker } from "../picker.ts" ;
22+ import type { SubmatchContext } from "./submatch.ts" ;
1723
1824let zindex = 50 ;
1925
2026export const main : Entrypoint = ( denops ) => {
2127 denops . dispatcher = {
2228 ...denops . dispatcher ,
29+ "picker" : ( args , itemPickerParams , options ) => {
30+ assert ( args , isStringArray ) ;
31+ assert ( itemPickerParams , isItemPickerParams ) ;
32+ assert ( options , isOptions ) ;
33+ return startPicker ( denops , args , itemPickerParams , options ) ;
34+ } ,
2335 "picker:command" : async ( args ) => {
2436 await loadUserConfig ( denops ) ;
2537 // Split the command arguments
@@ -43,33 +55,50 @@ export const main: Entrypoint = (denops) => {
4355 assert ( cursorpos , is . Number ) ;
4456 return listItemPickerNames ( ) . filter ( ( name ) => name . startsWith ( arglead ) ) ;
4557 } ,
46- // _screen is not used
47- "picker:start" : async ( args , _screen , params , options ) => {
48- await loadUserConfig ( denops ) ;
49- assert ( args , isStringArray ) ;
50- assert ( params , isParams ) ;
58+ // TODO: Remove this API prior to release v1.0.0
59+ // DEPRECATED: Use "submatch:start" instead
60+ "picker:start" : async ( _args , _screen , params , options ) => {
61+ console . warn (
62+ "The 'picker:start' is deprecated. Use 'submatch:start' instead." ,
63+ "It is probably caused by '@vim-fall/std/builtin/action/submatch' action." ,
64+ ) ;
65+ assert (
66+ params ,
67+ is . IntersectionOf ( [
68+ isGlobalConfig ,
69+ isItemPickerParams ,
70+ ] ) ,
71+ ) ;
5172 assert ( options , isOptions ) ;
52- return await startPicker ( denops , args , params , options ) ;
73+ return await startPicker ( denops , [ ] , params , options ) ;
5374 } ,
5475 } ;
5576} ;
5677
5778async function startPicker (
5879 denops : Denops ,
5980 args : string [ ] ,
60- params : ItemPickerParams < DetailUnit , string > & GlobalConfig ,
81+ itemPickerParams : ItemPickerParams < DetailUnit , string > ,
6182 { signal } : { signal ?: AbortSignal } = { } ,
6283) : Promise < void | true > {
6384 await using stack = new AsyncDisposableStack ( ) ;
64- const itemPicker = stack . use ( new Picker ( { ...params , zindex } ) ) ;
85+ const globalConfig = getGlobalConfig ( ) ;
86+ const itemPicker = stack . use (
87+ new Picker ( {
88+ ...globalConfig ,
89+ ...itemPickerParams ,
90+ zindex,
91+ } ) ,
92+ ) ;
6593 zindex += Picker . ZINDEX_ALLOCATION ;
6694 stack . defer ( ( ) => {
6795 zindex -= Picker . ZINDEX_ALLOCATION ;
6896 } ) ;
6997 const actionPicker = stack . use (
7098 new Picker ( {
7199 name : "@action" ,
72- source : buildActionSource ( params . actions ) ,
100+ source : buildActionSource ( itemPickerParams . actions ) ,
101+ ...globalConfig ,
73102 ...getActionPickerParams ( ) ,
74103 zindex,
75104 } ) ,
@@ -120,27 +149,31 @@ async function startPicker(
120149 actionName = resultItem . action ;
121150 } else {
122151 // Default action
123- actionName = params . defaultAction ;
152+ actionName = itemPickerParams . defaultAction ;
124153 }
125154
126155 // Execute the action
127- const action = params . actions [ actionName ] ;
156+ const action = itemPickerParams . actions [ actionName ] ;
128157 if ( ! action ) {
129158 throw new Error ( `Action "${ actionName } " is not found` ) ;
130159 }
131160 const actionParams = {
132- // for 'submatch' action
161+ // TODO: Drop the following attributes prior to release v1.0.0
162+ // Attributes used before @vim -fall/[email protected] 133163 _submatchContext : {
134- globalConfig : getGlobalConfig ( ) ,
135- pickerParams : params ,
136- // not used
137- screen : {
138- width : 0 ,
139- height : 0 ,
164+ globalConfig,
165+ pickerParams : {
166+ ...globalConfig ,
167+ ...itemPickerParams ,
140168 } ,
169+ screen : { width : 0 , height : 0 } ,
170+ } ,
171+ // Secret attribute for @vim -fall/std/builtin/action/submatch
172+ _submatch : {
173+ itemPickerParams,
141174 } ,
142175 ...resultItem ,
143- } ;
176+ } as const satisfies SubmatchContext & { _submatchContext : unknown } ;
144177 if ( await ensurePromise ( action . invoke ( denops , actionParams , { signal } ) ) ) {
145178 // Picker should not be closed
146179 continue ;
0 commit comments