@@ -8,20 +8,41 @@ import { vcvars } from 'node-vcvarsall';
8
8
import { vswhere } from 'node-vswhere' ;
9
9
import * as path from 'path' ;
10
10
import * as vscode from 'vscode' ;
11
+ import * as nls from 'vscode-nls' ;
12
+ import { isWindows } from '../constants' ;
11
13
import { CppSettings } from './settings' ;
12
14
15
+ nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone } ) ( ) ;
16
+ const localize : nls . LocalizeFunc = nls . loadMessageBundle ( ) ;
17
+
18
+ const ERROR_NO_CONTEXT = localize ( 'no.context.provided' , 'No context provided' ) ;
19
+ const NOT_WINDOWS = localize ( 'not.windows' , 'This command is only available on Windows' ) ;
20
+ const ERROR_NO_VS_FOUND = localize ( 'error.no.vs' , 'A Visual Studio installation with the C++ compiler was not found' ) ;
21
+ const ERROR_OPERATION_CANCELLED = localize ( 'operation.cancelled' , 'The operation was cancelled' ) ;
22
+ const ERROR_NO_HOSTS_FOUND = localize ( 'no.hosts' , 'No hosts found' ) ;
23
+ const CONFIGURING_DEV_ENV = localize ( 'config.dev.env' , 'Configuring Developer Environment...' ) ;
24
+ const SELECT_VS_INSTALLATION = localize ( 'select.vs.install' , 'Select a Visual Studio installation' ) ;
25
+ const ADVANCED_OPTIONS = localize ( 'advanced.options' , 'Advanced options...' ) ;
26
+ const ADVANCED_OPTIONS_DESCRIPTION = localize ( 'advanced.options.desc' , 'Select a specific host/target architecture, toolset version, etc.' ) ;
27
+ const SELECT_TOOLSET_VERSION = localize ( 'select.toolset' , 'Select a toolset version' ) ;
28
+ const SELECT_HOST_TARGET_ARCH = localize ( 'select.host.target' , 'Select a host and target architecture' ) ;
29
+
13
30
export function isEnvironmentOverrideApplied ( context ?: vscode . ExtensionContext ) {
14
31
return context ?. environmentVariableCollection . get ( 'VCToolsInstallDir' ) !== undefined ;
15
32
}
16
33
17
34
export async function setEnvironment ( context ?: vscode . ExtensionContext ) {
35
+ if ( ! isWindows ) {
36
+ throw new Error ( NOT_WINDOWS ) ;
37
+ }
38
+
18
39
if ( ! context ) {
19
- throw new Error ( 'No context provided' ) ;
40
+ throw new Error ( ERROR_NO_CONTEXT ) ;
20
41
}
21
42
22
43
const vses = await getVSInstallations ( ) ;
23
44
if ( ! vses ) {
24
- throw new Error ( 'A Visual Studio installation with the C++ compiler was not found' ) ;
45
+ throw new Error ( ERROR_NO_VS_FOUND ) ;
25
46
}
26
47
27
48
let vs = await chooseVSInstallation ( vses ) ;
@@ -34,11 +55,11 @@ export async function setEnvironment(context?: vscode.ExtensionContext) {
34
55
const vars = await vscode . window . withProgress ( {
35
56
cancellable : false ,
36
57
location : vscode . ProgressLocation . Notification ,
37
- title : 'Configuring Developer Environment...'
58
+ title : CONFIGURING_DEV_ENV
38
59
} , ( ) => vcvars . getVCVars ( vs , options ) ) ;
39
60
40
61
if ( ! vars || ! vars [ 'INCLUDE' ] ) {
41
- throw new Error ( ` Something went wrong: ${ JSON . stringify ( vars ) } ` ) ;
62
+ throw new Error ( localize ( 'something.wrong' , ' Something went wrong: {0}' , JSON . stringify ( vars ) ) ) ;
42
63
}
43
64
44
65
const host = vars [ 'VSCMD_ARG_HOST_ARCH' ] ;
@@ -53,7 +74,7 @@ export async function setEnvironment(context?: vscode.ExtensionContext) {
53
74
for ( const key of Object . keys ( vars ) ) {
54
75
context . environmentVariableCollection . replace ( key , vars [ key ] . replace ( `%${ key } %` , '${env:' + key + '}' ) ) ;
55
76
}
56
- context . environmentVariableCollection . description = ( arch ? ` ${ arch } ` : '' ) + ' Developer Command Prompt for ' + vs . displayName ;
77
+ context . environmentVariableCollection . description = localize ( 'dev.env.for' , '{0} Developer Environment for {1}' , arch , vs . displayName ) ;
57
78
context . environmentVariableCollection . persistent = settings . persistDevEnvironment ;
58
79
59
80
return true ;
@@ -68,25 +89,25 @@ async function getVSInstallations() {
68
89
} ) ;
69
90
70
91
if ( installations . length === 0 ) {
71
- throw new Error ( 'A Visual Studio installation with the C++ compiler was not found' ) ;
92
+ throw new Error ( ERROR_NO_VS_FOUND ) ;
72
93
}
73
94
return installations ;
74
95
}
75
96
76
97
async function chooseVSInstallation ( installations : vswhere . Installation [ ] ) : Promise < vswhere . Installation | undefined > {
77
98
const items : vscode . QuickPickItem [ ] = installations . map ( installation => < vscode . QuickPickItem > {
78
99
label : installation . displayName ,
79
- description : ` Default settings for ${ installation . displayName } `
100
+ description : localize ( 'default.settings' , ' Default settings for {0}' , installation . displayName )
80
101
} ) ;
81
102
items . push ( {
82
- label : 'Advanced options...' ,
83
- description : 'Select a specific host/target architecture, toolset version, etc.'
103
+ label : ADVANCED_OPTIONS ,
104
+ description : ADVANCED_OPTIONS_DESCRIPTION
84
105
} ) ;
85
106
const selection = await vscode . window . showQuickPick ( items , {
86
- placeHolder : 'Select a Visual Studio installation'
107
+ placeHolder : SELECT_VS_INSTALLATION
87
108
} ) ;
88
109
if ( ! selection ) {
89
- throw new Error ( 'The operation was cancelled' ) ;
110
+ throw new Error ( ERROR_OPERATION_CANCELLED ) ;
90
111
}
91
112
92
113
return installations . find ( installation => installation . displayName === selection . label ) ;
@@ -95,7 +116,7 @@ async function chooseVSInstallation(installations: vswhere.Installation[]): Prom
95
116
async function getAdvancedConfiguration ( vses : vswhere . Installation [ ] ) : Promise < Compiler > {
96
117
const compiler = await chooseCompiler ( vses ) ;
97
118
if ( ! compiler ) {
98
- throw new Error ( 'The operation was cancelled' ) ;
119
+ throw new Error ( ERROR_OPERATION_CANCELLED ) ;
99
120
}
100
121
await setOptions ( compiler ) ;
101
122
return compiler ;
@@ -125,10 +146,10 @@ async function chooseCompiler(vses: vswhere.Installation[]): Promise<Compiler |
125
146
description : compiler . vs . displayName
126
147
} ) ;
127
148
const selection = await vscode . window . showQuickPick ( items , {
128
- placeHolder : 'Select a toolset version'
149
+ placeHolder : SELECT_TOOLSET_VERSION
129
150
} ) ;
130
151
if ( ! selection ) {
131
- throw new Error ( 'The operation was cancelled' ) ;
152
+ throw new Error ( ERROR_OPERATION_CANCELLED ) ;
132
153
}
133
154
return compilers . find ( compiler => compiler . version === selection . label && compiler . vs . displayName === selection . description ) ;
134
155
}
@@ -139,13 +160,13 @@ async function setOptions(compiler: Compiler): Promise<void> {
139
160
if ( hostTargets . length > 1 ) {
140
161
const items = hostTargets . map ( ht => < vscode . QuickPickItem > {
141
162
label : vcvars . getArchitecture ( ht ) ,
142
- description : ` host = ${ ht . host } , target = ${ ht . target } `
163
+ description : localize ( ' host.target' , 'host = {0 }, target = {1}' , ht . host , ht . target )
143
164
} ) ;
144
165
const selection = await vscode . window . showQuickPick ( items , {
145
- placeHolder : 'Select a host and target architecture'
166
+ placeHolder : SELECT_HOST_TARGET_ARCH
146
167
} ) ;
147
168
if ( ! selection ) {
148
- throw new Error ( 'The operation was cancelled' ) ;
169
+ throw new Error ( ERROR_OPERATION_CANCELLED ) ;
149
170
}
150
171
compiler . options . arch = < vcvars . Architecture > selection . label ;
151
172
}
@@ -154,7 +175,7 @@ async function setOptions(compiler: Compiler): Promise<void> {
154
175
async function getHostsAndTargets ( vcPath : string ) : Promise < vcvars . HostTarget [ ] > {
155
176
const hosts = await fs . readdir ( vcPath ) ;
156
177
if ( hosts . length === 0 ) {
157
- throw new Error ( 'No hosts found' ) ;
178
+ throw new Error ( ERROR_NO_HOSTS_FOUND ) ;
158
179
}
159
180
const hostTargets : vcvars . HostTarget [ ] = [ ] ;
160
181
for ( const host of hosts ) {
0 commit comments