Skip to content

Commit

Permalink
Merge pull request #9206 from microsoft/coleng/1.9.8-cherry-picks
Browse files Browse the repository at this point in the history
  • Loading branch information
Colengms authored Apr 20, 2022
2 parents 2874fd2 + b5b1c2b commit 0a002db
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 151 deletions.
4 changes: 4 additions & 0 deletions Extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# C/C++ for Visual Studio Code Change Log

## Version 1.9.8: March 20, 2022
### Bug Fixes
* Fix an issue with extension activation failing if `C_Cpp.intelliSenseEngine` was set to `Disabled`. [#9083](https://github.com/microsoft/vscode-cpptools/issues/9083)

## Version 1.9.7: March 23, 2022
### New Features
* Add debugger support for Apple M1 (osx-arm64). [#7035](https://github.com/microsoft/vscode-cpptools/issues/7035)
Expand Down
6 changes: 5 additions & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cpptools",
"displayName": "C/C++",
"description": "C/C++ IntelliSense, debugging, and code browsing.",
"version": "1.9.7-main",
"version": "1.9.8-main",
"publisher": "ms-vscode",
"icon": "LanguageCCPP_color_128x.png",
"readme": "README.md",
Expand Down Expand Up @@ -2755,6 +2755,8 @@
"cpp",
"cuda-cpp"
],
"_aiKeyComment": "Ignore 'Property aiKey is not allowed'. See https://github.com/microsoft/vscode/issues/76493",
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
"variables": {
"pickProcess": "extension.pickNativeProcess",
"pickRemoteProcess": "extension.pickRemoteNativeProcess"
Expand Down Expand Up @@ -3430,6 +3432,8 @@
"cpp",
"cuda-cpp"
],
"_aiKeyComment": "Ignore 'Property aiKey is not allowed'. See https://github.com/microsoft/vscode/issues/76493",
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
"variables": {
"pickProcess": "extension.pickNativeProcess"
},
Expand Down
4 changes: 2 additions & 2 deletions Extension/src/Debugger/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import * as debugUtils from './utils';
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import { CppBuildTask, CppBuildTaskDefinition } from '../LanguageServer/cppBuildTaskProvider';
import { CppBuildTask, CppBuildTaskDefinition, cppBuildTaskProvider } from '../LanguageServer/cppBuildTaskProvider';
import * as util from '../common';
import * as fs from 'fs';
import * as Telemetry from '../telemetry';
import { cppBuildTaskProvider, configPrefix } from '../LanguageServer/extension';
import * as logger from '../logger';
import * as nls from 'vscode-nls';
import { IConfiguration, IConfigurationSnippet, DebuggerType, DebuggerEvent, MIConfigurations, WindowsConfigurations, WSLConfigurations, PipeTransportConfigurations, TaskConfigStatus } from './configurations';
import { parse } from 'comment-json';
import { PlatformInformation } from '../platform';
import { Environment, ParsedEnvironmentFile } from './ParsedEnvironmentFile';
import { configPrefix } from '../LanguageServer/extension';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand Down
6 changes: 2 additions & 4 deletions Extension/src/LanguageServer/cppBuildTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ export class CppBuildTaskProvider implements TaskProvider {
try {
activeClient = ext.getActiveClient();
} catch (errJS) {
const e: Error = errJS as Error;
if (!e || e.message !== ext.intelliSenseDisabledError) {
console.error("Unknown error calling getActiveClient().");
}
return emptyTasks; // Language service features may be disabled.
}

Expand Down Expand Up @@ -347,6 +343,8 @@ export class CppBuildTaskProvider implements TaskProvider {

}

export const cppBuildTaskProvider: CppBuildTaskProvider = new CppBuildTaskProvider();

class CustomBuildTaskTerminal implements Pseudoterminal {
private writeEmitter = new EventEmitter<string>();
private closeEmitter = new EventEmitter<number>();
Expand Down
141 changes: 9 additions & 132 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ import { Readable } from 'stream';
import * as nls from 'vscode-nls';
import { CppBuildTaskProvider } from './cppBuildTaskProvider';
import { UpdateInsidersAccess } from '../main';
import { PlatformInformation } from '../platform';
import * as semver from 'semver';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
export const cppBuildTaskProvider: CppBuildTaskProvider = new CppBuildTaskProvider();
export const CppSourceStr: string = "C/C++";
export const configPrefix: string = "C/C++: ";

Expand All @@ -41,7 +38,6 @@ let ui: UI;
const disposables: vscode.Disposable[] = [];
let languageConfigurations: vscode.Disposable[] = [];
let intervalTimer: NodeJS.Timer;
let taskProvider: vscode.Disposable;
let codeActionProvider: vscode.Disposable;
export const intelliSenseDisabledError: string = "Do not activate the extension when IntelliSense is disabled.";

Expand Down Expand Up @@ -157,129 +153,20 @@ function sendActivationTelemetry(): void {
telemetry.logLanguageServerEvent("Activate", activateEvent);
}

async function checkVsixCompatibility(): Promise<void> {
const ignoreMismatchedCompatibleVsix: PersistentState<boolean> = new PersistentState<boolean>("CPP." + util.packageJson.version + ".ignoreMismatchedCompatibleVsix", false);
let resetIgnoreMismatchedCompatibleVsix: boolean = true;

// Check to ensure the correct platform-specific VSIX was installed.
const vsixManifestPath: string = path.join(util.extensionPath, ".vsixmanifest");
// Skip the check if the file does not exist, such as when debugging cpptools.
if (await util.checkFileExists(vsixManifestPath)) {
const content: string = await util.readFileText(vsixManifestPath);
const matches: RegExpMatchArray | null = content.match(/TargetPlatform="(?<platform>[^"]*)"/);
if (matches && matches.length > 0 && matches.groups) {
const vsixTargetPlatform: string = matches.groups['platform'];
const platformInfo: PlatformInformation = await PlatformInformation.GetPlatformInformation();
let isPlatformCompatible: boolean = true;
let isPlatformMatching: boolean = true;
switch (vsixTargetPlatform) {
case "win32-x64":
isPlatformMatching = platformInfo.platform === "win32" && platformInfo.architecture === "x64";
// x64 binaries can also be run on arm64 Windows 11.
isPlatformCompatible = platformInfo.platform === "win32" && (platformInfo.architecture === "x64" || (platformInfo.architecture === "arm64" && semver.gte(os.release(), "10.0.22000")));
break;
case "win32-ia32":
isPlatformMatching = platformInfo.platform === "win32" && platformInfo.architecture === "x86";
// x86 binaries can also be run on x64 and arm64 Windows.
isPlatformCompatible = platformInfo.platform === "win32" && (platformInfo.architecture === "x86" || platformInfo.architecture === "x64" || platformInfo.architecture === "arm64");
break;
case "win32-arm64":
isPlatformMatching = platformInfo.platform === "win32" && platformInfo.architecture === "arm64";
isPlatformCompatible = isPlatformMatching;
break;
case "linux-x64":
isPlatformMatching = platformInfo.platform === "linux" && platformInfo.architecture === "x64" && platformInfo.distribution?.name !== "alpine";
isPlatformCompatible = isPlatformMatching;
break;
case "linux-arm64":
isPlatformMatching = platformInfo.platform === "linux" && platformInfo.architecture === "arm64" && platformInfo.distribution?.name !== "alpine";
isPlatformCompatible = isPlatformMatching;
break;
case "linux-armhf":
isPlatformMatching = platformInfo.platform === "linux" && platformInfo.architecture === "arm" && platformInfo.distribution?.name !== "alpine";
// armhf binaries can also be run on aarch64 linux.
isPlatformCompatible = platformInfo.platform === "linux" && (platformInfo.architecture === "arm" || platformInfo.architecture === "arm64") && platformInfo.distribution?.name !== "alpine";
break;
case "alpine-x64":
isPlatformMatching = platformInfo.platform === "linux" && platformInfo.architecture === "x64" && platformInfo.distribution?.name === "alpine";
isPlatformCompatible = isPlatformMatching;
break;
case "alpine-arm64":
isPlatformMatching = platformInfo.platform === "linux" && platformInfo.architecture === "arm64" && platformInfo.distribution?.name === "alpine";
isPlatformCompatible = isPlatformMatching;
break;
case "darwin-x64":
isPlatformMatching = platformInfo.platform === "darwin" && platformInfo.architecture === "x64";
isPlatformCompatible = isPlatformMatching;
break;
case "darwin-arm64":
isPlatformMatching = platformInfo.platform === "darwin" && platformInfo.architecture === "arm64";
// x64 binaries can also be run on arm64 macOS.
isPlatformCompatible = platformInfo.platform === "darwin" && (platformInfo.architecture === "x64" || platformInfo.architecture === "arm64");
break;
default:
console.log("Unrecognized TargetPlatform in .vsixmanifest");
break;
}
const moreInfoButton: string = localize("more.info.button", "More Info");
const ignoreButton: string = localize("ignore.button", "Ignore");
let promise: Thenable<string | undefined> | undefined;
if (!isPlatformCompatible) {
promise = vscode.window.showErrorMessage(localize("vsix.platform.incompatible", "The C/C++ extension installed does not match your system.", vsixTargetPlatform), moreInfoButton);
} else if (!isPlatformMatching) {
if (!ignoreMismatchedCompatibleVsix.Value) {
resetIgnoreMismatchedCompatibleVsix = false;
promise = vscode.window.showWarningMessage(localize("vsix.platform.mismatching", "The C/C++ extension installed is compatible with but does not match your system.", vsixTargetPlatform), moreInfoButton, ignoreButton);
}
}
if (promise) {
promise.then(async (value) => {
if (value === moreInfoButton) {
await vscode.commands.executeCommand("markdown.showPreview", vscode.Uri.file(util.getLocalizedHtmlPath("Reinstalling the Extension.md")));
} else if (value === ignoreButton) {
ignoreMismatchedCompatibleVsix.Value = true;
}
});
}
} else {
console.log("Unable to find TargetPlatform in .vsixmanifest");
}
}
if (resetIgnoreMismatchedCompatibleVsix) {
ignoreMismatchedCompatibleVsix.Value = false;
}
}

/**
* activate: set up the extension for language services
*/
export async function activate(): Promise<void> {

await checkVsixCompatibility();

if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
for (let i: number = 0; i < vscode.workspace.workspaceFolders.length; ++i) {
const config: string = path.join(vscode.workspace.workspaceFolders[i].uri.fsPath, ".vscode/c_cpp_properties.json");
if (await util.checkFileExists(config)) {
const doc: vscode.TextDocument = await vscode.workspace.openTextDocument(config);
vscode.languages.setTextDocumentLanguage(doc, "jsonc");
}
}
}

if (new CppSettings((vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) ? vscode.workspace.workspaceFolders[0]?.uri : undefined).intelliSenseEngine === "Disabled") {
throw new Error(intelliSenseDisabledError);
} else {
console.log("activating extension");
sendActivationTelemetry();
const checkForConflictingExtensions: PersistentState<boolean> = new PersistentState<boolean>("CPP." + util.packageJson.version + ".checkForConflictingExtensions", true);
if (checkForConflictingExtensions.Value) {
checkForConflictingExtensions.Value = false;
const clangCommandAdapterActive: boolean = vscode.extensions.all.some((extension: vscode.Extension<any>, index: number, array: Readonly<vscode.Extension<any>[]>): boolean =>
extension.isActive && extension.id === "mitaki28.vscode-clang");
if (clangCommandAdapterActive) {
telemetry.logLanguageServerEvent("conflictingExtension");
}
console.log("activating extension");
sendActivationTelemetry();
const checkForConflictingExtensions: PersistentState<boolean> = new PersistentState<boolean>("CPP." + util.packageJson.version + ".checkForConflictingExtensions", true);
if (checkForConflictingExtensions.Value) {
checkForConflictingExtensions.Value = false;
const clangCommandAdapterActive: boolean = vscode.extensions.all.some((extension: vscode.Extension<any>, index: number, array: Readonly<vscode.Extension<any>[]>): boolean =>
extension.isActive && extension.id === "mitaki28.vscode-clang");
if (clangCommandAdapterActive) {
telemetry.logLanguageServerEvent("conflictingExtension");
}
}

Expand Down Expand Up @@ -311,21 +198,14 @@ export async function activate(): Promise<void> {

registerCommands();

taskProvider = vscode.tasks.registerTaskProvider(CppBuildTaskProvider.CppBuildScriptType, cppBuildTaskProvider);

vscode.tasks.onDidStartTask(event => {
getActiveClient().PauseCodeAnalysis();
if (event.execution.task.definition.type === CppBuildTaskProvider.CppBuildScriptType
|| event.execution.task.name.startsWith(configPrefix)) {
telemetry.logLanguageServerEvent('buildTaskStarted');
}
});

vscode.tasks.onDidEndTask(event => {
getActiveClient().ResumeCodeAnalysis();
if (event.execution.task.definition.type === CppBuildTaskProvider.CppBuildScriptType
|| event.execution.task.name.startsWith(configPrefix)) {
telemetry.logLanguageServerEvent('buildTaskFinished');
if (event.execution.task.scope !== vscode.TaskScope.Global && event.execution.task.scope !== vscode.TaskScope.Workspace) {
const folder: vscode.WorkspaceFolder | undefined = event.execution.task.scope;
if (folder) {
Expand Down Expand Up @@ -1032,9 +912,6 @@ export function deactivate(): Thenable<void> {
disposables.forEach(d => d.dispose());
languageConfigurations.forEach(d => d.dispose());
ui.dispose();
if (taskProvider) {
taskProvider.dispose();
}
if (codeActionProvider) {
codeActionProvider.dispose();
}
Expand Down
Loading

0 comments on commit 0a002db

Please sign in to comment.