From 9802b181393a1c82b7115cd9d41f4e4902a5c35e Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:35:40 -0800 Subject: [PATCH] Make other command types consistent, polish abnormal alias types --- extensions/terminal-suggest/src/shell/pwsh.ts | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/extensions/terminal-suggest/src/shell/pwsh.ts b/extensions/terminal-suggest/src/shell/pwsh.ts index d7a3a1954acde..f3b0e371573b5 100644 --- a/extensions/terminal-suggest/src/shell/pwsh.ts +++ b/extensions/terminal-suggest/src/shell/pwsh.ts @@ -55,7 +55,7 @@ const pwshCommandTypeToCompletionKind: Map): Promise { - const output = await execHelper('Get-Command -CommandType Alias | Select-Object Name, CommandType, Definition, ModuleName, @{Name="Version";Expression={$_.Version.ToString()}} | ConvertTo-Json', { + const output = await execHelper('Get-Command -CommandType Alias | Select-Object Name, CommandType, Definition, DisplayName, ModuleName, @{Name="Version";Expression={$_.Version.ToString()}} | ConvertTo-Json', { ...options, maxBuffer: 1024 * 1024 * 100 // This is a lot of content, increase buffer size }); @@ -67,9 +67,11 @@ async function getAliases(options: ExecOptionsWithStringEncoding, existingComman return []; } return (json as any[]).map(e => { + // Aliases sometimes use the same Name and DisplayName, show them as methods in this case. + const isAlias = e.Name !== e.DisplayName; const detailParts: string[] = []; if (e.Definition) { - detailParts.push(e.Definition); + detailParts.push(isAlias ? `→ ${e.Definition}` : e.Definition); } if (e.ModuleName && e.Version) { detailParts.push(`${e.ModuleName} v${e.Version}`); @@ -77,18 +79,15 @@ async function getAliases(options: ExecOptionsWithStringEncoding, existingComman return { label: e.Name, detail: detailParts.join('\n\n'), - // Aliases sometimes don't have a definition and use the same DisplayName, show them as - // a method in this case. - kind: (!e.Definition + kind: (isAlias ? vscode.TerminalCompletionItemKind.Alias : vscode.TerminalCompletionItemKind.Method), }; - } - ); + }); } async function getCommands(options: ExecOptionsWithStringEncoding, existingCommands?: Set): Promise { - const output = await execHelper('Get-Command -All | Select-Object Name, CommandType, DisplayName, Definition | ConvertTo-Json', { + const output = await execHelper('Get-Command -All | Select-Object Name, CommandType, Definition, ModuleName, @{Name="Version";Expression={$_.Version.ToString()}} | ConvertTo-Json', { ...options, maxBuffer: 1024 * 1024 * 100 // This is a lot of content, increase buffer size }); @@ -102,10 +101,19 @@ async function getCommands(options: ExecOptionsWithStringEncoding, existingComma return ( (json as any[]) .filter(e => e.CommandType !== PwshCommandType.Alias) - .map(e => ({ - label: e.Name, - detail: e.Definition, - kind: pwshCommandTypeToCompletionKind.get(e.CommandType) - })) + .map(e => { + const detailParts: string[] = []; + if (e.Definition) { + detailParts.push(e.Definition.trim()); + } + if (e.ModuleName && e.Version) { + detailParts.push(`${e.ModuleName} v${e.Version}`); + } + return { + label: e.Name, + detail: detailParts.join('\n\n'), + kind: pwshCommandTypeToCompletionKind.get(e.CommandType) + }; + }) ); }