| 24 | |
| 25 | // The quick open command |
| 26 | class QuickOpenCommand { |
| 27 | id: string |
| 28 | description: string |
| 29 | placeholder: string |
| 30 | shortcut: string | null |
| 31 | subcommands: QuickOpenSubcommand[] |
| 32 | subcommandSelectedIndex: number |
| 33 | private _editorState: EditorState |
| 34 | private _folderState: FolderState |
| 35 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 36 | private _directorySearcher: any |
| 37 | private _cancelFn: CancelFn |
| 38 | |
| 39 | constructor(rootState: RootState) { |
| 40 | this.id = 'file.quick-open' |
| 41 | this.description = getCommandDescriptionById('file.quick-open') |
| 42 | this.placeholder = t('commandPalette.placeholders.searchFileToOpen') |
| 43 | this.shortcut = null |
| 44 | |
| 45 | this.subcommands = [] |
| 46 | this.subcommandSelectedIndex = -1 |
| 47 | |
| 48 | // Reference to folder and editor and project state. |
| 49 | this._editorState = rootState.editor |
| 50 | this._folderState = rootState.project |
| 51 | |
| 52 | this._directorySearcher = new FileSearcher() |
| 53 | this._cancelFn = null |
| 54 | } |
| 55 | |
| 56 | search = async(query: string): Promise<QuickOpenSubcommand[]> => { |
| 57 | // Show opened files when no query given. |
| 58 | if (!query) { |
| 59 | return this.subcommands |
| 60 | } |
| 61 | |
| 62 | const { _cancelFn } = this |
| 63 | if (_cancelFn) { |
| 64 | _cancelFn() |
| 65 | this._cancelFn = null |
| 66 | } |
| 67 | |
| 68 | const timeout = delay(300) |
| 69 | this._cancelFn = () => { |
| 70 | // `delay` returns a promise with a `cancel` attached. |
| 71 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 72 | ;(timeout as any).cancel() |
| 73 | this._cancelFn = null |
| 74 | } |
| 75 | |
| 76 | await timeout |
| 77 | return this._doSearch(query) |
| 78 | } |
| 79 | |
| 80 | run = async(): Promise<void> => { |
| 81 | const { _editorState, _folderState } = this |
| 82 | if (!_folderState.projectTree && _editorState.tabs.length === 0) { |
| 83 | throw new Error(null as unknown as string) |
nothing calls this directly
no test coverage detected