diff --git a/extensions/terminal-suggest/src/terminalSuggestMain.ts b/extensions/terminal-suggest/src/terminalSuggestMain.ts index faf868e3a6c..cd6d1483320 100644 --- a/extensions/terminal-suggest/src/terminalSuggestMain.ts +++ b/extensions/terminal-suggest/src/terminalSuggestMain.ts @@ -21,6 +21,23 @@ const enum PwshCommandType { Alias = 1 } +// TODO: remove once API is finalized +export enum TerminalShellType { + Sh = 1, + Bash = 2, + Fish = 3, + Csh = 4, + Ksh = 5, + Zsh = 6, + CommandPrompt = 7, + GitBash = 8, + PowerShell = 9, + Python = 10, + Julia = 11, + NuShell = 12, + Node = 13 +} + const isWindows = osIsWindows(); let cachedAvailableCommandsPath: string | undefined; let cachedWindowsExecutableExtensions: { [key: string]: boolean | undefined } | undefined; @@ -37,6 +54,14 @@ for (const spec of upstreamSpecs) { availableSpecs.push(require(`./completions/upstream/${spec}`).default); } +const getShellGlobals: Map) => Promise<(string | ICompletionResource)[]>> = new Map([ + [TerminalShellType.Bash, getBashGlobals], + [TerminalShellType.Zsh, getZshGlobals], + // TODO: Ghost text in the command line prevents completions from working ATM for fish + [TerminalShellType.Fish, getFishGlobals], + // [TerminalShellType.PowerShell]: getPwshGlobals, +]); + async function getBuiltinCommands(shellType: TerminalShellType, existingCommands?: Set): Promise { try { const cachedCommands = cachedBuiltinCommands.get(shellType); @@ -50,19 +75,6 @@ async function getBuiltinCommands(shellType: TerminalShellType, existingCommands const options: ExecOptionsWithStringEncoding = { encoding: 'utf-8', shell }; let commands: (string | ICompletionResource)[] | undefined; switch (shellType) { - case TerminalShellType.Bash: { - commands = await getBashGlobals(options, existingCommands); - break; - } - case TerminalShellType.Zsh: { - commands = await getZshGlobals(options, existingCommands); - break; - } - case TerminalShellType.Fish: { - // TODO: Ghost text in the command line prevents completions from working ATM for fish - commands = await getFishGlobals(options, existingCommands); - break; - } case TerminalShellType.PowerShell: { const output = await new Promise((resolve, reject) => { exec('Get-Command -All | Select-Object Name, CommandType, DisplayName, Definition | ConvertTo-Json', { @@ -103,6 +115,10 @@ async function getBuiltinCommands(shellType: TerminalShellType, existingCommands cachedBuiltinCommands.set(shellType, commandResources); return commandResources; } + default: { + commands = await getShellGlobals.get(shellType)?.(options, existingCommands); + break; + } } const commandResources = commands?.map(command => typeof command === 'string' ? ({ label: command }) : command); @@ -561,24 +577,6 @@ function getFriendlyResourcePath(uri: vscode.Uri, pathSeparator: string, kind?: return path; } -// TODO: remove once API is finalized -export enum TerminalShellType { - Sh = 1, - Bash = 2, - Fish = 3, - Csh = 4, - Ksh = 5, - Zsh = 6, - CommandPrompt = 7, - GitBash = 8, - PowerShell = 9, - Python = 10, - Julia = 11, - NuShell = 12, - Node = 13 -} - - function getShell(shellType: TerminalShellType): string | undefined { switch (shellType) { case TerminalShellType.Bash: