Skip to content

Commit 2715319

Browse files
authored
Compiler acquisition (#11286)
1 parent 2cc55ea commit 2715319

File tree

11 files changed

+348
-90
lines changed

11 files changed

+348
-90
lines changed

Extension/package.json

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,29 @@
8888
"id": "awaiting.activation.windows",
8989
"title": "%c_cpp.walkthrough.set.up.title%",
9090
"description": "%c_cpp.walkthrough.activating.description%",
91-
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == false",
91+
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == false && cpptools.windowsVersion != 10 && cpptools.windowsVersion != 11",
9292
"media": {
9393
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows.md"
9494
}
9595
},
96+
{
97+
"id": "awaiting.activation.windows10",
98+
"title": "%c_cpp.walkthrough.set.up.title%",
99+
"description": "%c_cpp.walkthrough.activating.description%",
100+
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == false && cpptools.windowsVersion == 10",
101+
"media": {
102+
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows10.md"
103+
}
104+
},
105+
{
106+
"id": "awaiting.activation.windows11",
107+
"title": "%c_cpp.walkthrough.set.up.title%",
108+
"description": "%c_cpp.walkthrough.activating.description%",
109+
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == false && cpptools.windowsVersion == 11",
110+
"media": {
111+
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows11.md"
112+
}
113+
},
96114
{
97115
"id": "no.compilers.found.mac",
98116
"title": "%c_cpp.walkthrough.set.up.title%",
@@ -114,12 +132,30 @@
114132
{
115133
"id": "no.compilers.found.windows",
116134
"title": "%c_cpp.walkthrough.set.up.title%",
117-
"description": "%c_cpp.walkthrough.no.compilers.description%",
118-
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == true",
135+
"description": "%c_cpp.walkthrough.no.compilers.windows.description%",
136+
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == true && cpptools.windowsVersion != 10 && cpptools.windowsVersion != 11",
119137
"media": {
120138
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows.md"
121139
}
122140
},
141+
{
142+
"id": "no.compilers.found.windows10",
143+
"title": "%c_cpp.walkthrough.set.up.title%",
144+
"description": "%c_cpp.walkthrough.no.compilers.windows.description%",
145+
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == true && cpptools.windowsVersion == 10",
146+
"media": {
147+
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows10.md"
148+
}
149+
},
150+
{
151+
"id": "no.compilers.found.windows11",
152+
"title": "%c_cpp.walkthrough.set.up.title%",
153+
"description": "%c_cpp.walkthrough.no.compilers.windows.description%",
154+
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == true && cpptools.windowsVersion == 11",
155+
"media": {
156+
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows11.md"
157+
}
158+
},
123159
{
124160
"id": "verify.compiler.mac",
125161
"title": "%c_cpp.walkthrough.set.up.title%",
@@ -148,14 +184,38 @@
148184
"id": "verify.compiler.windows",
149185
"title": "%c_cpp.walkthrough.set.up.title%",
150186
"description": "%c_cpp.walkthrough.compilers.found.description%",
151-
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == false",
187+
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == false && cpptools.windowsVersion != 10 && cpptools.windowsVersion != 11",
152188
"media": {
153189
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows.md"
154190
},
155191
"completionEvents": [
156192
"onContext:cpptools.trustedCompilerFound"
157193
]
158194
},
195+
{
196+
"id": "verify.compiler.windows10",
197+
"title": "%c_cpp.walkthrough.set.up.title%",
198+
"description": "%c_cpp.walkthrough.compilers.found.description%",
199+
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == false && cpptools.windowsVersion == 10",
200+
"media": {
201+
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows10.md"
202+
},
203+
"completionEvents": [
204+
"onContext:cpptools.trustedCompilerFound"
205+
]
206+
},
207+
{
208+
"id": "verify.compiler.windows11",
209+
"title": "%c_cpp.walkthrough.set.up.title%",
210+
"description": "%c_cpp.walkthrough.compilers.found.description%",
211+
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == false && cpptools.windowsVersion == 11",
212+
"media": {
213+
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows11.md"
214+
},
215+
"completionEvents": [
216+
"onContext:cpptools.trustedCompilerFound"
217+
]
218+
},
159219
{
160220
"id": "create.cpp.file",
161221
"title": "%c_cpp.walkthrough.create.cpp.file.title%",
@@ -3025,6 +3085,11 @@
30253085
"title": "%c_cpp.command.selectIntelliSenseConfiguration.title%",
30263086
"category": "C/C++"
30273087
},
3088+
{
3089+
"command": "C_Cpp.InstallCompiler",
3090+
"title": "%c_cpp.command.installCompiler.title%",
3091+
"category": "C/C++"
3092+
},
30283093
{
30293094
"command": "C_Cpp.RescanCompilers",
30303095
"title": "%c_cpp.command.rescanCompilers.title%",
@@ -5646,6 +5711,10 @@
56465711
"command": "C_Cpp.SelectDefaultCompiler",
56475712
"when": "never"
56485713
},
5714+
{
5715+
"command": "C_Cpp.InstallCompiler",
5716+
"when": "never"
5717+
},
56495718
{
56505719
"command": "C_Cpp.RescanCompilers",
56515720
"when": "never"

Extension/package.nls.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"c_cpp.command.configurationEditUI.title": "Edit Configurations (UI)",
1414
"c_cpp.command.selectDefaultCompiler.title": "Select Default Compiler...",
1515
"c_cpp.command.selectIntelliSenseConfiguration.title": "Select IntelliSense Configuration...",
16+
"c_cpp.command.installCompiler.title": "Install a C++ Compiler",
1617
"c_cpp.command.rescanCompilers.title": "Rescan for Compilers",
1718
"c_cpp.command.switchHeaderSource.title": "Switch Header/Source",
1819
"c_cpp.command.enableErrorSquiggles.title": "Enable Error Squiggles",
@@ -976,7 +977,8 @@
976977
"c_cpp.walkthrough.description": "Dive into VS Code's rich C++ development experience.",
977978
"c_cpp.walkthrough.set.up.title": "Set up your C++ Environment",
978979
"c_cpp.walkthrough.activating.description": "Activating the C++ extension to determine whether your C++ Environment has been set up.\nActivating Extension...",
979-
"c_cpp.walkthrough.no.compilers.description": "We could not find a C++ compiler on your machine, which is required to use the C++ extension. Follow the instructions on the right to install one, then click “Find my new Compiler” below.\n[Find my new Compiler](command:C_Cpp.RescanCompilers?%7B%22sender%22%3A%22walkthrough%22%7D)",
980+
"c_cpp.walkthrough.no.compilers.windows.description": "We could not find a C++ compiler on your machine, which is required to use the C++ extension. Follow the instructions on the right to install one, then click “Find my new Compiler” below.\n[Find my new Compiler](command:C_Cpp.RescanCompilers?%7B%22sender%22%3A%22walkthrough%22%7D)",
981+
"c_cpp.walkthrough.no.compilers.description": "We could not find a C++ compiler on your machine, which is required to use the C++ extension. Either select “Install a C++ Compiler” to have a compiler installed for you or follow the instructions on the right to install one, then click “Find my new Compiler” below.\n[Install a C++ Compiler](command:C_Cpp.InstallCompiler?%7B%22sender%22%3A%22walkthrough%22%7D)\n[Find my new Compiler](command:C_Cpp.RescanCompilers?%7B%22sender%22%3A%22walkthrough%22%7D)",
980982
"c_cpp.walkthrough.compilers.found.description": "The C++ extension works with a C++ compiler. Select one from those already on your machine by clicking the button below.\n[Select my Default Compiler](command:C_Cpp.SelectDefaultCompiler?%7B%22sender%22%3A%22walkthrough%22%7D)",
981983
"c_cpp.walkthrough.compilers.found.altText": "Image showing the select a default compiler quickpick and the list of compilers found on the users machine, one of which is selected.",
982984
"c_cpp.walkthrough.create.cpp.file.title": "Create a C++ file",

Extension/src/LanguageServer/client.ts

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ import { ManualSignal } from '../Utility/Async/manualSignal';
3737
import { logAndReturn, returns } from '../Utility/Async/returns';
3838
import { is } from '../Utility/System/guards';
3939
import * as util from '../common';
40+
import { isWindows } from '../constants';
4041
import { DebugProtocolParams, Logger, ShowWarningParams, getDiagnosticsChannel, getOutputChannelLogger, logDebugProtocol, logLocalized, showWarning } from '../logger';
4142
import { localizedStringCount, lookupString } from '../nativeStrings';
43+
import { SessionState } from '../sessionState';
4244
import * as telemetry from '../telemetry';
4345
import { TestHook, getTestHook } from '../testHook';
4446
import {
@@ -97,7 +99,6 @@ interface ConfigStateReceived {
9799

98100
let displayedSelectCompiler: boolean = false;
99101
let secondPromptCounter: number = 0;
100-
let scanForCompilersDone: boolean = false;
101102
let workspaceHash: string = "";
102103

103104
let workspaceDisposables: vscode.Disposable[] = [];
@@ -1035,7 +1036,14 @@ export class DefaultClient implements Client {
10351036
const compilersIndex: number = paths.length;
10361037
const compilerCount: number = compilersIndex === compileCommandsIndex ? 0 : compilersIndex - compileCommandsIndex - 1;
10371038
paths.push(localize("selectAnotherCompiler.string", "Select another compiler on my machine..."));
1038-
paths.push(localize("installCompiler.string", "Help me install a compiler"));
1039+
let installShown = true;
1040+
if (isWindows && util.getSenderType(sender) !== 'walkthrough') {
1041+
paths.push(localize("installCompiler.string", "Help me install a compiler"));
1042+
} else if (!isWindows) {
1043+
paths.push(localize("installCompiler.string.nix", "Install a compiler"));
1044+
} else {
1045+
installShown = false;
1046+
}
10391047
paths.push(localize("noConfig.string", "Do not configure with a compiler (not recommended)"));
10401048
const index: number = await this.showSelectIntelliSenseConfiguration(paths, compilersOnly);
10411049
let action: string = "";
@@ -1059,44 +1067,13 @@ export class DefaultClient implements Client {
10591067
}
10601068
return ui.ShowConfigureIntelliSenseButton(false, this, ConfigurationType.CompilerPath, "disablePrompt");
10611069
}
1062-
if (index === paths.length - 2) {
1063-
action = "help";
1064-
// Because we need to conditionally enable/disable steps to alter their contents,
1065-
// we need to determine which step is actually visible. If the steps change, this
1066-
// logic will need to change to reflect them.
1067-
let step: string = "ms-vscode.cpptools#";
1068-
if (!scanForCompilersDone) {
1069-
step = step + "awaiting.activation.";
1070-
} else if (compilerDefaults?.knownCompilers === undefined || !compilerDefaults.knownCompilers.length) {
1071-
step = step + "no.compilers.found.";
1072-
} else {
1073-
step = step + "verify.compiler.";
1074-
}
1075-
switch (os.platform()) {
1076-
case 'win32':
1077-
step = step + "windows";
1078-
break;
1079-
case 'darwin':
1080-
step = step + "mac";
1081-
break;
1082-
default: // Linux
1083-
step = step + "linux";
1084-
break;
1085-
}
1086-
void vscode.commands.executeCommand(
1087-
"workbench.action.openWalkthrough",
1088-
{ category: 'ms-vscode.cpptools#cppWelcome', step },
1089-
false)
1090-
// Run it twice for now because of VS Code bug #187958
1091-
.then(() => vscode.commands.executeCommand(
1092-
"workbench.action.openWalkthrough",
1093-
{ category: 'ms-vscode.cpptools#cppWelcome', step },
1094-
false)
1095-
);
1070+
if (installShown && index === paths.length - 2) {
1071+
action = "install";
1072+
void vscode.commands.executeCommand('C_Cpp.InstallCompiler', sender);
10961073
return;
10971074
}
10981075
const showButtonSender: string = "quickPick";
1099-
if (index === paths.length - 3) {
1076+
if (index === paths.length - 3 || (!installShown && index === paths.length - 2)) {
11001077
const result: vscode.Uri[] | undefined = await vscode.window.showOpenDialog();
11011078
if (result === undefined || result.length === 0) {
11021079
action = "browse dismissed";
@@ -1109,7 +1086,7 @@ export class DefaultClient implements Client {
11091086
action = "compiler browsed";
11101087
settings.defaultCompilerPath = result[0].fsPath;
11111088
await this.configuration.updateCompilerPathIfSet(settings.defaultCompilerPath);
1112-
void vscode.commands.executeCommand('setContext', 'cpptools.trustedCompilerFound', true);
1089+
void SessionState.trustedCompilerFound.set(true);
11131090
} else {
11141091
configurationSelected = true;
11151092
if (index < configProvidersIndex && configProviders) {
@@ -1128,7 +1105,7 @@ export class DefaultClient implements Client {
11281105
action = "select compiler";
11291106
settings.defaultCompilerPath = util.isCl(paths[index]) ? "cl.exe" : paths[index];
11301107
await this.configuration.updateCompilerPathIfSet(settings.defaultCompilerPath);
1131-
void vscode.commands.executeCommand('setContext', 'cpptools.trustedCompilerFound', true);
1108+
void SessionState.trustedCompilerFound.set(true);
11321109
}
11331110
}
11341111

@@ -1784,10 +1761,10 @@ export class DefaultClient implements Client {
17841761
if (document.uri.scheme === "file") {
17851762
const uri: string = document.uri.toString();
17861763
openFileVersions.set(uri, document.version);
1787-
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isSourceFile', util.isCppOrCFile(document.uri));
1788-
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isFolderOpen', util.isFolderOpen(document.uri));
1764+
void SessionState.buildAndDebugIsSourceFile.set(util.isCppOrCFile(document.uri));
1765+
void SessionState.buildAndDebugIsFolderOpen.set(util.isFolderOpen(document.uri));
17891766
} else {
1790-
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isSourceFile', false);
1767+
void SessionState.buildAndDebugIsSourceFile.set(false);
17911768
}
17921769
}
17931770

@@ -2841,18 +2818,17 @@ export class DefaultClient implements Client {
28412818
newTrustedCompilerPath: newCompilerPath ?? ""
28422819
};
28432820
const results: configs.CompilerDefaults = await this.languageClient.sendRequest(QueryCompilerDefaultsRequest, params);
2844-
scanForCompilersDone = true;
2845-
void vscode.commands.executeCommand('setContext', 'cpptools.scanForCompilersDone', true);
2846-
void vscode.commands.executeCommand('setContext', 'cpptools.scanForCompilersEmpty', results.knownCompilers === undefined || !results.knownCompilers.length);
2847-
void vscode.commands.executeCommand('setContext', 'cpptools.trustedCompilerFound', results.trustedCompilerFound);
2821+
void SessionState.scanForCompilersDone.set(true);
2822+
void SessionState.scanForCompilersEmpty.set(results.knownCompilers === undefined || !results.knownCompilers.length);
2823+
void SessionState.trustedCompilerFound.set(results.trustedCompilerFound);
28482824
return results;
28492825
}
28502826

28512827
private updateActiveDocumentTextOptions(): void {
28522828
const editor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
28532829
if (editor && util.isCpp(editor.document)) {
2854-
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isSourceFile', util.isCppOrCFile(editor.document.uri));
2855-
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isFolderOpen', util.isFolderOpen(editor.document.uri));
2830+
void SessionState.buildAndDebugIsSourceFile.set(util.isCppOrCFile(editor.document.uri));
2831+
void SessionState.buildAndDebugIsFolderOpen.set(util.isFolderOpen(editor.document.uri));
28562832
// If using vcFormat, check for a ".editorconfig" file, and apply those text options to the active document.
28572833
const settings: CppSettings = new CppSettings(this.RootUri);
28582834
if (settings.useVcFormat(editor.document)) {
@@ -2874,7 +2850,7 @@ export class DefaultClient implements Client {
28742850
}
28752851
}
28762852
} else {
2877-
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isSourceFile', false).then(undefined, logAndReturn.undefined);
2853+
void SessionState.buildAndDebugIsSourceFile.set(false);
28782854
}
28792855
}
28802856

0 commit comments

Comments
 (0)