Skip to content

Commit

Permalink
Prevent language service activation for macOS older than 10.12 (#9328)
Browse files Browse the repository at this point in the history
  • Loading branch information
Colengms authored May 20, 2022
1 parent feb8a64 commit 2238e73
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions Extension/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,43 @@ export async function activate(context: vscode.ExtensionContext): Promise<CppToo
UpdateInsidersAccess();

const settings: CppSettings = new CppSettings((vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) ? vscode.workspace.workspaceFolders[0]?.uri : undefined);
if (settings.intelliSenseEngine === "Disabled") {
languageServiceDisabled = true;
let isOldMacOs: boolean = false;
if (info.platform === 'darwin') {
const releaseParts: string[] = os.release().split(".");
if (releaseParts.length >= 1) {
isOldMacOs = parseInt(releaseParts[0]) < 16;
}
}
let currentIntelliSenseEngineValue: string | undefined = settings.intelliSenseEngine;
disposables.push(vscode.workspace.onDidChangeConfiguration(() => {
const settings: CppSettings = new CppSettings((vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) ? vscode.workspace.workspaceFolders[0]?.uri : undefined);
if (!reloadMessageShown && settings.intelliSenseEngine !== currentIntelliSenseEngineValue) {
if (currentIntelliSenseEngineValue === "Disabled") {
// If switching from disabled to enabled, we can continue activation.
currentIntelliSenseEngineValue = settings.intelliSenseEngine;
languageServiceDisabled = false;
LanguageServer.activate();
} else {
// We can't deactivate or change engines on the fly, so prompt for window reload.
reloadMessageShown = true;
util.promptForReloadWindowDueToSettingsChange();
}

// Read the setting and determine whether we should activate the language server prior to installing callbacks,
// to ensure there is no potential race condition. LanguageServer.activate() is called near the end of this
// function, to allow any further setup to occur here, prior to activation.
const shouldActivateLanguageServer: boolean = (settings.intelliSenseEngine !== "Disabled" && !isOldMacOs);

if (isOldMacOs) {
languageServiceDisabled = true;
vscode.window.showErrorMessage(localize("macos.version.deprecated", "Versions of the C/C++ extension more recent than {0} require at least macOS version {1}.", "1.9.8", "10.12"));
} else {
if (settings.intelliSenseEngine === "Disabled") {
languageServiceDisabled = true;
}
}));
let currentIntelliSenseEngineValue: string | undefined = settings.intelliSenseEngine;
disposables.push(vscode.workspace.onDidChangeConfiguration(() => {
const settings: CppSettings = new CppSettings((vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) ? vscode.workspace.workspaceFolders[0]?.uri : undefined);
if (!reloadMessageShown && settings.intelliSenseEngine !== currentIntelliSenseEngineValue) {
if (currentIntelliSenseEngineValue === "Disabled") {
// If switching from disabled to enabled, we can continue activation.
currentIntelliSenseEngineValue = settings.intelliSenseEngine;
languageServiceDisabled = false;
LanguageServer.activate();
} else {
// We can't deactivate or change engines on the fly, so prompt for window reload.
reloadMessageShown = true;
util.promptForReloadWindowDueToSettingsChange();
}
}
}));
}

if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) {
for (let i: number = 0; i < vscode.workspace.workspaceFolders.length; ++i) {
Expand Down Expand Up @@ -114,7 +132,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CppToo
}
});

if (settings.intelliSenseEngine !== "Disabled") {
if (shouldActivateLanguageServer) {
await LanguageServer.activate();
}

Expand Down

0 comments on commit 2238e73

Please sign in to comment.