@@ -8,11 +8,6 @@ import { IFeature } from "../feature";
8
8
import { Logger } from "../logging" ;
9
9
import { SessionManager } from "../session" ;
10
10
11
- interface IExternalExtension {
12
- readonly id : string ;
13
- readonly apiVersion : string ;
14
- }
15
-
16
11
export interface IExternalPowerShellDetails {
17
12
exePath : string ;
18
13
version : string ;
@@ -41,33 +36,8 @@ export class ExternalApiFeature implements IFeature {
41
36
RETURNS:
42
37
string session uuid
43
38
*/
44
- vscode . commands . registerCommand ( "PowerShell.RegisterExternalExtension" , ( id : string , apiVersion : string = 'v1' ) : string => {
45
- log . writeDiagnostic ( `Registering extension '${ id } ' for use with API version '${ apiVersion } '.` ) ;
46
-
47
- for ( const [ _ , externalExtension ] of ExternalApiFeature . registeredExternalExtension ) {
48
- if ( externalExtension . id === id ) {
49
- const message = `The extension '${ id } ' is already registered.` ;
50
- log . writeWarning ( message ) ;
51
- throw new Error ( message ) ;
52
- }
53
- }
54
-
55
- if ( ! vscode . extensions . all . some ( ext => ext . id === id ) ) {
56
- throw new Error ( `No extension installed with id '${ id } '. You must use a valid extension id.` ) ;
57
- }
58
-
59
- // If we're in development mode, we allow these to be used for testing purposes.
60
- if ( ! sessionManager . InDevelopmentMode && ( id === "ms-vscode.PowerShell" || id === "ms-vscode.PowerShell-Preview" ) ) {
61
- throw new Error ( "You can't use the PowerShell extension's id in this registration." ) ;
62
- }
63
-
64
- const uuid = uuidv4 ( ) ;
65
- ExternalApiFeature . registeredExternalExtension . set ( uuid , {
66
- id,
67
- apiVersion
68
- } ) ;
69
- return uuid ;
70
- } ) ,
39
+ vscode . commands . registerCommand ( "PowerShell.RegisterExternalExtension" , ( id : string , apiVersion : string = 'v1' ) : string =>
40
+ this . registerExternalExtension ( id , apiVersion ) ) ,
71
41
72
42
/*
73
43
DESCRIPTION:
@@ -82,13 +52,8 @@ export class ExternalApiFeature implements IFeature {
82
52
RETURNS:
83
53
true if it worked, otherwise throws an error.
84
54
*/
85
- vscode . commands . registerCommand ( "PowerShell.UnregisterExternalExtension" , ( uuid : string = "" ) : boolean => {
86
- log . writeDiagnostic ( `Unregistering extension with session UUID: ${ uuid } ` ) ;
87
- if ( ! ExternalApiFeature . registeredExternalExtension . delete ( uuid ) ) {
88
- throw new Error ( `No extension registered with session UUID: ${ uuid } ` ) ;
89
- }
90
- return true ;
91
- } ) ,
55
+ vscode . commands . registerCommand ( "PowerShell.UnregisterExternalExtension" , ( uuid : string = "" ) : boolean =>
56
+ this . unregisterExternalExtension ( uuid ) ) ,
92
57
93
58
/*
94
59
DESCRIPTION:
@@ -109,27 +74,66 @@ export class ExternalApiFeature implements IFeature {
109
74
architecture: string;
110
75
}
111
76
*/
112
- vscode . commands . registerCommand ( "PowerShell.GetPowerShellVersionDetails" , async ( uuid : string = "" ) : Promise < IExternalPowerShellDetails > => {
113
- if ( ! ExternalApiFeature . registeredExternalExtension . has ( uuid ) ) {
114
- throw new Error (
115
- "UUID provided was invalid, make sure you execute the 'PowerShell.GetPowerShellVersionDetails' command and pass in the UUID that it returns to subsequent command executions." ) ;
116
- }
77
+ vscode . commands . registerCommand ( "PowerShell.GetPowerShellVersionDetails" , ( uuid : string = "" ) : Promise < IExternalPowerShellDetails > =>
78
+ this . getPowerShellVersionDetails ( uuid ) ) ,
79
+ ]
80
+ }
117
81
118
- // TODO: When we have more than one API version, make sure to include a check here.
119
- const extension = ExternalApiFeature . registeredExternalExtension . get ( uuid ) ;
120
- log . writeDiagnostic ( `Extension '${ extension . id } ' used command 'PowerShell.GetPowerShellVersionDetails'.` ) ;
82
+ private registerExternalExtension ( id : string , apiVersion : string = 'v1' ) : string {
83
+ this . log . writeDiagnostic ( `Registering extension '${ id } ' for use with API version '${ apiVersion } '.` ) ;
121
84
122
- await sessionManager . waitUntilStarted ( ) ;
123
- const versionDetails = sessionManager . getPowerShellVersionDetails ( ) ;
85
+ for ( const [ _ , externalExtension ] of ExternalApiFeature . registeredExternalExtension ) {
86
+ if ( externalExtension . id === id ) {
87
+ const message = `The extension '${ id } ' is already registered.` ;
88
+ this . log . writeWarning ( message ) ;
89
+ throw new Error ( message ) ;
90
+ }
91
+ }
124
92
125
- return {
126
- exePath : sessionManager . PowerShellExeDetails . exePath ,
127
- version : versionDetails . version ,
128
- displayName : sessionManager . PowerShellExeDetails . displayName , // comes from the Session Menu
129
- architecture : versionDetails . architecture
130
- } ;
131
- } ) ,
132
- ]
93
+ if ( ! vscode . extensions . all . some ( ext => ext . id === id ) ) {
94
+ throw new Error ( `No extension installed with id '${ id } '. You must use a valid extension id.` ) ;
95
+ }
96
+
97
+ // If we're in development mode, we allow these to be used for testing purposes.
98
+ if ( ! this . sessionManager . InDevelopmentMode && ( id === "ms-vscode.PowerShell" || id === "ms-vscode.PowerShell-Preview" ) ) {
99
+ throw new Error ( "You can't use the PowerShell extension's id in this registration." ) ;
100
+ }
101
+
102
+ const uuid = uuidv4 ( ) ;
103
+ ExternalApiFeature . registeredExternalExtension . set ( uuid , {
104
+ id,
105
+ apiVersion
106
+ } ) ;
107
+ return uuid ;
108
+ }
109
+
110
+ private unregisterExternalExtension ( uuid : string = "" ) : boolean {
111
+ this . log . writeDiagnostic ( `Unregistering extension with session UUID: ${ uuid } ` ) ;
112
+ if ( ! ExternalApiFeature . registeredExternalExtension . delete ( uuid ) ) {
113
+ throw new Error ( `No extension registered with session UUID: ${ uuid } ` ) ;
114
+ }
115
+ return true ;
116
+ }
117
+
118
+ private async getPowerShellVersionDetails ( uuid : string = "" ) : Promise < IExternalPowerShellDetails > {
119
+ if ( ! ExternalApiFeature . registeredExternalExtension . has ( uuid ) ) {
120
+ throw new Error (
121
+ "UUID provided was invalid, make sure you execute the 'PowerShell.GetPowerShellVersionDetails' command and pass in the UUID that it returns to subsequent command executions." ) ;
122
+ }
123
+
124
+ // TODO: When we have more than one API version, make sure to include a check here.
125
+ const extension = ExternalApiFeature . registeredExternalExtension . get ( uuid ) ;
126
+ this . log . writeDiagnostic ( `Extension '${ extension . id } ' used command 'PowerShell.GetPowerShellVersionDetails'.` ) ;
127
+
128
+ await this . sessionManager . waitUntilStarted ( ) ;
129
+ const versionDetails = this . sessionManager . getPowerShellVersionDetails ( ) ;
130
+
131
+ return {
132
+ exePath : this . sessionManager . PowerShellExeDetails . exePath ,
133
+ version : versionDetails . version ,
134
+ displayName : this . sessionManager . PowerShellExeDetails . displayName , // comes from the Session Menu
135
+ architecture : versionDetails . architecture
136
+ } ;
133
137
}
134
138
135
139
public dispose ( ) {
@@ -142,3 +146,8 @@ export class ExternalApiFeature implements IFeature {
142
146
this . languageClient = languageclient ;
143
147
}
144
148
}
149
+
150
+ interface IExternalExtension {
151
+ readonly id : string ;
152
+ readonly apiVersion : string ;
153
+ }
0 commit comments