@@ -10,6 +10,7 @@ import { execHelper } from './common';
1010
1111export async function getPwshGlobals ( options : ExecOptionsWithStringEncoding , existingCommands ?: Set < string > ) : Promise < ( string | ICompletionResource ) [ ] > {
1212 return [
13+ ...await getAliases ( options , existingCommands ) ,
1314 ...await getCommands ( options , existingCommands ) ,
1415 ] ;
1516}
@@ -53,6 +54,37 @@ const pwshCommandTypeToCompletionKind: Map<PwshCommandType, vscode.TerminalCompl
5354 [ PwshCommandType . Configuration , vscode . TerminalCompletionItemKind . Argument ] ,
5455] ) ;
5556
57+ async function getAliases ( options : ExecOptionsWithStringEncoding , existingCommands ?: Set < string > ) : Promise < ICompletionResource [ ] > {
58+ const output = await execHelper ( 'Get-Command -CommandType Alias | Select-Object Name, CommandType, Definition, ModuleName, @{Name="Version";Expression={$_.Version.ToString()}} | ConvertTo-Json' , {
59+ ...options ,
60+ maxBuffer : 1024 * 1024 * 100 // This is a lot of content, increase buffer size
61+ } ) ;
62+ let json : any ;
63+ try {
64+ json = JSON . parse ( output ) ;
65+ } catch ( e ) {
66+ console . error ( 'Error parsing output:' , e ) ;
67+ return [ ] ;
68+ }
69+ return ( json as any [ ] ) . map ( e => {
70+ const detailParts : string [ ] = [ ] ;
71+ if ( e . Definition ) {
72+ detailParts . push ( e . Definition ) ;
73+ }
74+ if ( e . ModuleName && e . Version ) {
75+ detailParts . push ( `${ e . ModuleName } v${ e . Version } ` ) ;
76+ }
77+ return {
78+ label : e . Name ,
79+ detail : detailParts . join ( '\n\n' ) ,
80+ // Aliases sometimes return the same DisplayName, show as a method in this case.
81+ kind : ( e . Name === e . DisplayName
82+ ? vscode . TerminalCompletionItemKind . Method
83+ : vscode . TerminalCompletionItemKind . Alias ) ,
84+ } ;
85+ }
86+ ) ;
87+ }
5688
5789async function getCommands ( options : ExecOptionsWithStringEncoding , existingCommands ?: Set < string > ) : Promise < ICompletionResource [ ] > {
5890 const output = await execHelper ( 'Get-Command -All | Select-Object Name, CommandType, DisplayName, Definition | ConvertTo-Json' , {
@@ -66,25 +98,13 @@ async function getCommands(options: ExecOptionsWithStringEncoding, existingComma
6698 console . error ( 'Error parsing pwsh output:' , e ) ;
6799 return [ ] ;
68100 }
69- return ( json as any [ ] ) . map ( e => {
70- switch ( e . CommandType ) {
71- case PwshCommandType . Alias : {
72- return {
73- label : e . Name ,
74- detail : e . DisplayName ,
75- // Aliases sometimes return the same DisplayName, show as a method in this case.
76- kind : ( e . Name === e . DisplayName
77- ? vscode . TerminalCompletionItemKind . Method
78- : vscode . TerminalCompletionItemKind . Alias ) ,
79- } ;
80- }
81- default : {
82- return {
83- label : e . Name ,
84- detail : e . Definition ,
85- kind : pwshCommandTypeToCompletionKind . get ( e . CommandType )
86- } ;
87- }
88- }
89- } ) ;
101+ return (
102+ ( json as any [ ] )
103+ . filter ( e => e . CommandType !== PwshCommandType . Alias )
104+ . map ( e => ( {
105+ label : e . Name ,
106+ detail : e . Definition ,
107+ kind : pwshCommandTypeToCompletionKind . get ( e . CommandType )
108+ } ) )
109+ ) ;
90110}
0 commit comments