Skip to content

Commit 4216aa4

Browse files
Elaheh RashediElaheh Rashedibobbrow
authored
check offline/insiders VSIX (#5341)
* check offline/insiders VSIX * draft * add offline url, modify warning message * check offline/insiders VSIX * draft * add offline url, modify warning message * modify warning message * fix reviewers comments * changing the approach to determine the platform * fixing the integration test * testing Co-authored-by: Elaheh Rashedi <[email protected]> Co-authored-by: Bob Brown <[email protected]>
1 parent 118bed1 commit 4216aa4

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

Extension/src/common.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,20 @@ export function checkInstallLockFile(): Promise<boolean> {
534534
return checkFileExists(getInstallLockPath());
535535
}
536536

537+
/** Get the platform that the installed binaries belong to.*/
538+
export function getInstalledBinaryPlatform(): string | undefined {
539+
// the LLVM/bin folder is utilized to identify the platform
540+
let installedPlatform: string = "";
541+
if (checkFileExistsSync(path.join(extensionPath, "LLVM/bin/clang-format.exe"))) {
542+
installedPlatform = "win32";
543+
} else if (checkFileExistsSync(path.join(extensionPath, "LLVM/bin/clang-format.darwin"))) {
544+
installedPlatform = "darwin";
545+
} else if (checkFileExistsSync(path.join(extensionPath, "LLVM/bin/clang-format"))) {
546+
installedPlatform = "linux";
547+
}
548+
return installedPlatform;
549+
}
550+
537551
/** Reads the content of a text file */
538552
export function readFileText(filePath: string, encoding: string = "utf8"): Promise<string> {
539553
return new Promise<string>((resolve, reject) => {

Extension/src/githubAPI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as vscode from 'vscode';
1212
import * as telemetry from './telemetry';
1313

1414
const testingInsidersVsixInstall: boolean = false; // Change this to true to enable testing of the Insiders vsix installation.
15-
15+
export const releaseDownloadUrl: string = "https://github.com/microsoft/vscode-cpptools/releases";
1616
/**
1717
* The object representation of a Build Asset. Each Asset corresponds to information about a release file on GitHub.
1818
*/
@@ -96,7 +96,7 @@ function isArrayOfBuilds(input: any): input is Build[] {
9696
* @param info Information about the user's operating system.
9797
* @return VSIX filename for the extension's releases matched to the user's platform.
9898
*/
99-
function vsixNameForPlatform(info: PlatformInformation): string {
99+
export function vsixNameForPlatform(info: PlatformInformation): string {
100100
const vsixName: string | undefined = function(platformInfo): string | undefined {
101101
switch (platformInfo.platform) {
102102
case 'win32': return 'cpptools-win32.vsix';

Extension/src/main.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import { PersistentState } from './LanguageServer/persistentState';
1717

1818
import { CppToolsApi, CppToolsExtension } from 'vscode-cpptools';
1919
import { getTemporaryCommandRegistrarInstance, initializeTemporaryCommandRegistrar } from './commands';
20-
import { PlatformInformation } from './platform';
20+
import { PlatformInformation, GetOSName } from './platform';
2121
import { PackageManager, PackageManagerError, IPackage, VersionsMatch, ArchitecturesMatch, PlatformsMatch } from './packageManager';
2222
import { getInstallationInformation, InstallationInformation, setInstallationStage, setInstallationType, InstallationType } from './installationInformation';
2323
import { Logger, getOutputChannelLogger, showOutputChannel } from './logger';
2424
import { CppTools1, NullCppTools } from './cppTools1';
2525
import { CppSettings } from './LanguageServer/settings';
26+
import { vsixNameForPlatform, releaseDownloadUrl } from './githubAPI';
2627

2728
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
2829
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
@@ -49,6 +50,20 @@ export async function activate(context: vscode.ExtensionContext): Promise<CppToo
4950
Telemetry.activate();
5051
util.setProgress(0);
5152

53+
// check if the correct offline/insiders vsix is installed on the correct platform
54+
let installedPlatform: string | undefined = util.getInstalledBinaryPlatform();
55+
if (!installedPlatform || (process.platform !== installedPlatform)) {
56+
const platformInfo: PlatformInformation = await PlatformInformation.GetPlatformInformation();
57+
const vsixName: string = vsixNameForPlatform(platformInfo);
58+
errMsg = localize("native.binaries.not.supported", "This {0} version of the extension is incompatible with your OS. Please download and install the \"{1}\" version of the extension.", GetOSName(installedPlatform), vsixName);
59+
const downloadLink: string = localize("download.button", "Go to Download Page");
60+
vscode.window.showErrorMessage(errMsg, downloadLink).then(async (selection) => {
61+
if (selection === downloadLink) {
62+
vscode.env.openExternal(vscode.Uri.parse(releaseDownloadUrl));
63+
}
64+
});
65+
}
66+
5267
// Register a protocol handler to serve localized versions of the schema for c_cpp_properties.json
5368
class SchemaProvider implements vscode.TextDocumentContentProvider {
5469
public async provideTextDocumentContent(uri: vscode.Uri): Promise<string> {
@@ -317,7 +332,7 @@ function handleError(error: any): void {
317332
outputChannelLogger.appendLine(localize('failed.at.stage', "Failed at stage: {0}", installationInformation.stage));
318333
outputChannelLogger.appendLine(errorMessage);
319334
outputChannelLogger.appendLine("");
320-
outputChannelLogger.appendLine(localize('failed.at.stage2', 'If you work in an offline environment or repeatedly see this error, try downloading a version of the extension with all the dependencies pre-included from https://github.com/Microsoft/vscode-cpptools/releases, then use the "Install from VSIX" command in VS Code to install it.'));
335+
outputChannelLogger.appendLine(localize('failed.at.stage2', 'If you work in an offline environment or repeatedly see this error, try downloading a version of the extension with all the dependencies pre-included from {0}, then use the "Install from VSIX" command in VS Code to install it.', releaseDownloadUrl));
321336
showOutputChannel();
322337
}
323338

Extension/src/platform.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ import * as nls from 'vscode-nls';
1414
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
1515
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
1616

17+
export function GetOSName(processPlatform: string | undefined): string | undefined {
18+
switch (processPlatform) {
19+
case "win32": return "Windows";
20+
case "darwin": return "MacOS";
21+
case "linux": return "Linux";
22+
default: return undefined;
23+
}
24+
}
25+
1726
export class PlatformInformation {
1827
constructor(public platform: string, public architecture?: string, public distribution?: LinuxDistribution, public version?: string) { }
1928

0 commit comments

Comments
 (0)