Skip to content

Commit 540537a

Browse files
committed
cleanup in devcmd.ts
1 parent 6c97412 commit 540537a

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

Extension/src/LanguageServer/devcmd.ts

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,34 @@ import { CppSettings } from './settings';
1515
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
1616
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
1717

18-
const ERROR_NO_CONTEXT = localize('no.context.provided', 'No context provided');
19-
const ERROR_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');
18+
const errorNoContext = localize('no.context.provided', 'No context provided');
19+
const errorNotWindows = localize('not.windows', 'This command is only available on Windows');
20+
const errorNoVSFound = localize('error.no.vs', 'A Visual Studio installation with the C++ compiler was not found');
21+
const errorOperationCancelled = localize('operation.cancelled', 'The operation was cancelled');
22+
const errorNoHostsFound = localize('no.hosts', 'No hosts found');
23+
const configuringDevEnv = localize('config.dev.env', 'Configuring Developer Environment...');
24+
const selectVSInstallation = localize('select.vs.install', 'Select a Visual Studio installation');
25+
const advancedOptions = localize('advanced.options', 'Advanced options...');
26+
const advancedOptionsDescription = localize('advanced.options.desc', 'Select a specific host/target architecture, toolset version, etc.');
27+
const selectToolsetVersion = localize('select.toolset', 'Select a toolset version');
28+
const selectHostTargetArch = localize('select.host.target', 'Select a host and target architecture');
2929

3030
export function isEnvironmentOverrideApplied(context?: vscode.ExtensionContext) {
3131
return context?.environmentVariableCollection.get('VCToolsInstallDir') !== undefined;
3232
}
3333

3434
export async function setEnvironment(context?: vscode.ExtensionContext) {
3535
if (!isWindows) {
36-
throw new Error(ERROR_NOT_WINDOWS);
36+
throw new Error(errorNotWindows);
3737
}
3838

3939
if (!context) {
40-
throw new Error(ERROR_NO_CONTEXT);
40+
throw new Error(errorNoContext);
4141
}
4242

4343
const vses = await getVSInstallations();
4444
if (!vses) {
45-
throw new Error(ERROR_NO_VS_FOUND);
45+
throw new Error(errorNoVSFound);
4646
}
4747

4848
let vs = await chooseVSInstallation(vses);
@@ -55,7 +55,7 @@ export async function setEnvironment(context?: vscode.ExtensionContext) {
5555
const vars = await vscode.window.withProgress({
5656
cancellable: false,
5757
location: vscode.ProgressLocation.Notification,
58-
title: CONFIGURING_DEV_ENV
58+
title: configuringDevEnv
5959
}, () => vcvars.getVCVars(vs, options));
6060

6161
if (!vars || !vars['INCLUDE']) {
@@ -89,7 +89,7 @@ async function getVSInstallations() {
8989
});
9090

9191
if (installations.length === 0) {
92-
throw new Error(ERROR_NO_VS_FOUND);
92+
throw new Error(errorNoVSFound);
9393
}
9494
return installations;
9595
}
@@ -100,34 +100,34 @@ async function chooseVSInstallation(installations: vswhere.Installation[]): Prom
100100
description: localize('default.settings', 'Default settings for {0}', installation.displayName)
101101
});
102102
items.push({
103-
label: ADVANCED_OPTIONS,
104-
description: ADVANCED_OPTIONS_DESCRIPTION
103+
label: advancedOptions,
104+
description: advancedOptionsDescription
105105
});
106106
const selection = await vscode.window.showQuickPick(items, {
107-
placeHolder: SELECT_VS_INSTALLATION
107+
placeHolder: selectVSInstallation
108108
});
109109
if (!selection) {
110-
throw new Error(ERROR_OPERATION_CANCELLED);
110+
throw new Error(errorOperationCancelled);
111111
}
112112

113113
return installations.find(installation => installation.displayName === selection.label);
114114
}
115115

116+
interface Compiler {
117+
version: string;
118+
vs: vswhere.Installation;
119+
options: vcvars.Options;
120+
}
121+
116122
async function getAdvancedConfiguration(vses: vswhere.Installation[]): Promise<Compiler> {
117123
const compiler = await chooseCompiler(vses);
118124
if (!compiler) {
119-
throw new Error(ERROR_OPERATION_CANCELLED);
125+
throw new Error(errorOperationCancelled);
120126
}
121127
await setOptions(compiler);
122128
return compiler;
123129
}
124130

125-
interface Compiler {
126-
version: string;
127-
vs: vswhere.Installation;
128-
options: vcvars.Options;
129-
}
130-
131131
async function chooseCompiler(vses: vswhere.Installation[]): Promise<Compiler | undefined> {
132132
const compilers: Compiler[] = [];
133133
for (const vs of vses) {
@@ -146,10 +146,10 @@ async function chooseCompiler(vses: vswhere.Installation[]): Promise<Compiler |
146146
description: compiler.vs.displayName
147147
});
148148
const selection = await vscode.window.showQuickPick(items, {
149-
placeHolder: SELECT_TOOLSET_VERSION
149+
placeHolder: selectToolsetVersion
150150
});
151151
if (!selection) {
152-
throw new Error(ERROR_OPERATION_CANCELLED);
152+
throw new Error(errorOperationCancelled);
153153
}
154154
return compilers.find(compiler => compiler.version === selection.label && compiler.vs.displayName === selection.description);
155155
}
@@ -163,10 +163,10 @@ async function setOptions(compiler: Compiler): Promise<void> {
163163
description: localize('host.target', 'host = {0}, target = {1}', ht.host, ht.target)
164164
});
165165
const selection = await vscode.window.showQuickPick(items, {
166-
placeHolder: SELECT_HOST_TARGET_ARCH
166+
placeHolder: selectHostTargetArch
167167
});
168168
if (!selection) {
169-
throw new Error(ERROR_OPERATION_CANCELLED);
169+
throw new Error(errorOperationCancelled);
170170
}
171171
compiler.options.arch = <vcvars.Architecture>selection.label;
172172
}
@@ -175,7 +175,7 @@ async function setOptions(compiler: Compiler): Promise<void> {
175175
async function getHostsAndTargets(vcPath: string): Promise<vcvars.HostTarget[]> {
176176
const hosts = await fs.readdir(vcPath);
177177
if (hosts.length === 0) {
178-
throw new Error(ERROR_NO_HOSTS_FOUND);
178+
throw new Error(errorNoHostsFound);
179179
}
180180
const hostTargets: vcvars.HostTarget[] = [];
181181
for (const host of hosts) {
@@ -195,9 +195,6 @@ async function getHostsAndTargets(vcPath: string): Promise<vcvars.HostTarget[]>
195195
return hostTargets;
196196
}
197197

198-
export function deactivate() {
199-
}
200-
201198
function match<T>(item: string, cases: { [key: string]: T }): T | undefined {
202199
return cases[item];
203200
}

0 commit comments

Comments
 (0)