Skip to content

Commit

Permalink
Make other command types consistent, polish abnormal alias types
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Jan 31, 2025
1 parent c69d72c commit 9802b18
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions extensions/terminal-suggest/src/shell/pwsh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const pwshCommandTypeToCompletionKind: Map<PwshCommandType, vscode.TerminalCompl
]);

async function getAliases(options: ExecOptionsWithStringEncoding, existingCommands?: Set<string>): Promise<ICompletionResource[]> {
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
});
Expand All @@ -67,28 +67,27 @@ 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}`);
}
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<string>): Promise<ICompletionResource[]> {
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
});
Expand All @@ -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)
};
})
);
}

0 comments on commit 9802b18

Please sign in to comment.