Skip to content

Commit

Permalink
Compiler acquisition (#11286)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbrow authored Sep 13, 2023
1 parent 2cc55ea commit 2715319
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 90 deletions.
77 changes: 73 additions & 4 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,29 @@
"id": "awaiting.activation.windows",
"title": "%c_cpp.walkthrough.set.up.title%",
"description": "%c_cpp.walkthrough.activating.description%",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == false",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == false && cpptools.windowsVersion != 10 && cpptools.windowsVersion != 11",
"media": {
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows.md"
}
},
{
"id": "awaiting.activation.windows10",
"title": "%c_cpp.walkthrough.set.up.title%",
"description": "%c_cpp.walkthrough.activating.description%",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == false && cpptools.windowsVersion == 10",
"media": {
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows10.md"
}
},
{
"id": "awaiting.activation.windows11",
"title": "%c_cpp.walkthrough.set.up.title%",
"description": "%c_cpp.walkthrough.activating.description%",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == false && cpptools.windowsVersion == 11",
"media": {
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows11.md"
}
},
{
"id": "no.compilers.found.mac",
"title": "%c_cpp.walkthrough.set.up.title%",
Expand All @@ -114,12 +132,30 @@
{
"id": "no.compilers.found.windows",
"title": "%c_cpp.walkthrough.set.up.title%",
"description": "%c_cpp.walkthrough.no.compilers.description%",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == true",
"description": "%c_cpp.walkthrough.no.compilers.windows.description%",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == true && cpptools.windowsVersion != 10 && cpptools.windowsVersion != 11",
"media": {
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows.md"
}
},
{
"id": "no.compilers.found.windows10",
"title": "%c_cpp.walkthrough.set.up.title%",
"description": "%c_cpp.walkthrough.no.compilers.windows.description%",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == true && cpptools.windowsVersion == 10",
"media": {
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows10.md"
}
},
{
"id": "no.compilers.found.windows11",
"title": "%c_cpp.walkthrough.set.up.title%",
"description": "%c_cpp.walkthrough.no.compilers.windows.description%",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == true && cpptools.windowsVersion == 11",
"media": {
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows11.md"
}
},
{
"id": "verify.compiler.mac",
"title": "%c_cpp.walkthrough.set.up.title%",
Expand Down Expand Up @@ -148,14 +184,38 @@
"id": "verify.compiler.windows",
"title": "%c_cpp.walkthrough.set.up.title%",
"description": "%c_cpp.walkthrough.compilers.found.description%",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == false",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == false && cpptools.windowsVersion != 10 && cpptools.windowsVersion != 11",
"media": {
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows.md"
},
"completionEvents": [
"onContext:cpptools.trustedCompilerFound"
]
},
{
"id": "verify.compiler.windows10",
"title": "%c_cpp.walkthrough.set.up.title%",
"description": "%c_cpp.walkthrough.compilers.found.description%",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == false && cpptools.windowsVersion == 10",
"media": {
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows10.md"
},
"completionEvents": [
"onContext:cpptools.trustedCompilerFound"
]
},
{
"id": "verify.compiler.windows11",
"title": "%c_cpp.walkthrough.set.up.title%",
"description": "%c_cpp.walkthrough.compilers.found.description%",
"when": "workspacePlatform == windows && cpptools.scanForCompilersDone == true && cpptools.scanForCompilersEmpty == false && cpptools.windowsVersion == 11",
"media": {
"markdown": "dist/walkthrough/installcompiler/install-compiler-windows11.md"
},
"completionEvents": [
"onContext:cpptools.trustedCompilerFound"
]
},
{
"id": "create.cpp.file",
"title": "%c_cpp.walkthrough.create.cpp.file.title%",
Expand Down Expand Up @@ -3025,6 +3085,11 @@
"title": "%c_cpp.command.selectIntelliSenseConfiguration.title%",
"category": "C/C++"
},
{
"command": "C_Cpp.InstallCompiler",
"title": "%c_cpp.command.installCompiler.title%",
"category": "C/C++"
},
{
"command": "C_Cpp.RescanCompilers",
"title": "%c_cpp.command.rescanCompilers.title%",
Expand Down Expand Up @@ -5646,6 +5711,10 @@
"command": "C_Cpp.SelectDefaultCompiler",
"when": "never"
},
{
"command": "C_Cpp.InstallCompiler",
"when": "never"
},
{
"command": "C_Cpp.RescanCompilers",
"when": "never"
Expand Down
4 changes: 3 additions & 1 deletion Extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"c_cpp.command.configurationEditUI.title": "Edit Configurations (UI)",
"c_cpp.command.selectDefaultCompiler.title": "Select Default Compiler...",
"c_cpp.command.selectIntelliSenseConfiguration.title": "Select IntelliSense Configuration...",
"c_cpp.command.installCompiler.title": "Install a C++ Compiler",
"c_cpp.command.rescanCompilers.title": "Rescan for Compilers",
"c_cpp.command.switchHeaderSource.title": "Switch Header/Source",
"c_cpp.command.enableErrorSquiggles.title": "Enable Error Squiggles",
Expand Down Expand Up @@ -976,7 +977,8 @@
"c_cpp.walkthrough.description": "Dive into VS Code's rich C++ development experience.",
"c_cpp.walkthrough.set.up.title": "Set up your C++ Environment",
"c_cpp.walkthrough.activating.description": "Activating the C++ extension to determine whether your C++ Environment has been set up.\nActivating Extension...",
"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)",
"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)",
"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)",
"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)",
"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.",
"c_cpp.walkthrough.create.cpp.file.title": "Create a C++ file",
Expand Down
74 changes: 25 additions & 49 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ import { ManualSignal } from '../Utility/Async/manualSignal';
import { logAndReturn, returns } from '../Utility/Async/returns';
import { is } from '../Utility/System/guards';
import * as util from '../common';
import { isWindows } from '../constants';
import { DebugProtocolParams, Logger, ShowWarningParams, getDiagnosticsChannel, getOutputChannelLogger, logDebugProtocol, logLocalized, showWarning } from '../logger';
import { localizedStringCount, lookupString } from '../nativeStrings';
import { SessionState } from '../sessionState';
import * as telemetry from '../telemetry';
import { TestHook, getTestHook } from '../testHook';
import {
Expand Down Expand Up @@ -97,7 +99,6 @@ interface ConfigStateReceived {

let displayedSelectCompiler: boolean = false;
let secondPromptCounter: number = 0;
let scanForCompilersDone: boolean = false;
let workspaceHash: string = "";

let workspaceDisposables: vscode.Disposable[] = [];
Expand Down Expand Up @@ -1035,7 +1036,14 @@ export class DefaultClient implements Client {
const compilersIndex: number = paths.length;
const compilerCount: number = compilersIndex === compileCommandsIndex ? 0 : compilersIndex - compileCommandsIndex - 1;
paths.push(localize("selectAnotherCompiler.string", "Select another compiler on my machine..."));
paths.push(localize("installCompiler.string", "Help me install a compiler"));
let installShown = true;
if (isWindows && util.getSenderType(sender) !== 'walkthrough') {
paths.push(localize("installCompiler.string", "Help me install a compiler"));
} else if (!isWindows) {
paths.push(localize("installCompiler.string.nix", "Install a compiler"));
} else {
installShown = false;
}
paths.push(localize("noConfig.string", "Do not configure with a compiler (not recommended)"));
const index: number = await this.showSelectIntelliSenseConfiguration(paths, compilersOnly);
let action: string = "";
Expand All @@ -1059,44 +1067,13 @@ export class DefaultClient implements Client {
}
return ui.ShowConfigureIntelliSenseButton(false, this, ConfigurationType.CompilerPath, "disablePrompt");
}
if (index === paths.length - 2) {
action = "help";
// Because we need to conditionally enable/disable steps to alter their contents,
// we need to determine which step is actually visible. If the steps change, this
// logic will need to change to reflect them.
let step: string = "ms-vscode.cpptools#";
if (!scanForCompilersDone) {
step = step + "awaiting.activation.";
} else if (compilerDefaults?.knownCompilers === undefined || !compilerDefaults.knownCompilers.length) {
step = step + "no.compilers.found.";
} else {
step = step + "verify.compiler.";
}
switch (os.platform()) {
case 'win32':
step = step + "windows";
break;
case 'darwin':
step = step + "mac";
break;
default: // Linux
step = step + "linux";
break;
}
void vscode.commands.executeCommand(
"workbench.action.openWalkthrough",
{ category: 'ms-vscode.cpptools#cppWelcome', step },
false)
// Run it twice for now because of VS Code bug #187958
.then(() => vscode.commands.executeCommand(
"workbench.action.openWalkthrough",
{ category: 'ms-vscode.cpptools#cppWelcome', step },
false)
);
if (installShown && index === paths.length - 2) {
action = "install";
void vscode.commands.executeCommand('C_Cpp.InstallCompiler', sender);
return;
}
const showButtonSender: string = "quickPick";
if (index === paths.length - 3) {
if (index === paths.length - 3 || (!installShown && index === paths.length - 2)) {
const result: vscode.Uri[] | undefined = await vscode.window.showOpenDialog();
if (result === undefined || result.length === 0) {
action = "browse dismissed";
Expand All @@ -1109,7 +1086,7 @@ export class DefaultClient implements Client {
action = "compiler browsed";
settings.defaultCompilerPath = result[0].fsPath;
await this.configuration.updateCompilerPathIfSet(settings.defaultCompilerPath);
void vscode.commands.executeCommand('setContext', 'cpptools.trustedCompilerFound', true);
void SessionState.trustedCompilerFound.set(true);
} else {
configurationSelected = true;
if (index < configProvidersIndex && configProviders) {
Expand All @@ -1128,7 +1105,7 @@ export class DefaultClient implements Client {
action = "select compiler";
settings.defaultCompilerPath = util.isCl(paths[index]) ? "cl.exe" : paths[index];
await this.configuration.updateCompilerPathIfSet(settings.defaultCompilerPath);
void vscode.commands.executeCommand('setContext', 'cpptools.trustedCompilerFound', true);
void SessionState.trustedCompilerFound.set(true);
}
}

Expand Down Expand Up @@ -1784,10 +1761,10 @@ export class DefaultClient implements Client {
if (document.uri.scheme === "file") {
const uri: string = document.uri.toString();
openFileVersions.set(uri, document.version);
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isSourceFile', util.isCppOrCFile(document.uri));
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isFolderOpen', util.isFolderOpen(document.uri));
void SessionState.buildAndDebugIsSourceFile.set(util.isCppOrCFile(document.uri));
void SessionState.buildAndDebugIsFolderOpen.set(util.isFolderOpen(document.uri));
} else {
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isSourceFile', false);
void SessionState.buildAndDebugIsSourceFile.set(false);
}
}

Expand Down Expand Up @@ -2841,18 +2818,17 @@ export class DefaultClient implements Client {
newTrustedCompilerPath: newCompilerPath ?? ""
};
const results: configs.CompilerDefaults = await this.languageClient.sendRequest(QueryCompilerDefaultsRequest, params);
scanForCompilersDone = true;
void vscode.commands.executeCommand('setContext', 'cpptools.scanForCompilersDone', true);
void vscode.commands.executeCommand('setContext', 'cpptools.scanForCompilersEmpty', results.knownCompilers === undefined || !results.knownCompilers.length);
void vscode.commands.executeCommand('setContext', 'cpptools.trustedCompilerFound', results.trustedCompilerFound);
void SessionState.scanForCompilersDone.set(true);
void SessionState.scanForCompilersEmpty.set(results.knownCompilers === undefined || !results.knownCompilers.length);
void SessionState.trustedCompilerFound.set(results.trustedCompilerFound);
return results;
}

private updateActiveDocumentTextOptions(): void {
const editor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
if (editor && util.isCpp(editor.document)) {
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isSourceFile', util.isCppOrCFile(editor.document.uri));
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isFolderOpen', util.isFolderOpen(editor.document.uri));
void SessionState.buildAndDebugIsSourceFile.set(util.isCppOrCFile(editor.document.uri));
void SessionState.buildAndDebugIsFolderOpen.set(util.isFolderOpen(editor.document.uri));
// If using vcFormat, check for a ".editorconfig" file, and apply those text options to the active document.
const settings: CppSettings = new CppSettings(this.RootUri);
if (settings.useVcFormat(editor.document)) {
Expand All @@ -2874,7 +2850,7 @@ export class DefaultClient implements Client {
}
}
} else {
void vscode.commands.executeCommand('setContext', 'cpptools.buildAndDebug.isSourceFile', false).then(undefined, logAndReturn.undefined);
void SessionState.buildAndDebugIsSourceFile.set(false);
}
}

Expand Down
Loading

0 comments on commit 2715319

Please sign in to comment.