Unverified Commit db1a9424 authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

Show 32/64bit in VS Code headings on Windows (#15018)

* Show 32/64bit in VS Code headings on Windows

Fixes #14949.
parent d3797628
...@@ -15,7 +15,7 @@ const bool _includeInsiders = false; ...@@ -15,7 +15,7 @@ const bool _includeInsiders = false;
class VsCode { class VsCode {
static const String extensionIdentifier = 'Dart-Code.dart-code'; static const String extensionIdentifier = 'Dart-Code.dart-code';
VsCode._(this.directory, this.extensionDirectory, { Version version }) VsCode._(this.directory, this.extensionDirectory, { Version version, this.edition })
: this.version = version ?? Version.unknown { : this.version = version ?? Version.unknown {
if (!fs.isDirectorySync(directory)) { if (!fs.isDirectorySync(directory)) {
...@@ -50,22 +50,25 @@ class VsCode { ...@@ -50,22 +50,25 @@ class VsCode {
final String directory; final String directory;
final String extensionDirectory; final String extensionDirectory;
final Version version; final Version version;
final String edition;
bool _isValid = false; bool _isValid = false;
Version _extensionVersion; Version _extensionVersion;
final List<String> _validationMessages = <String>[]; final List<String> _validationMessages = <String>[];
factory VsCode.fromDirectory(String installPath, String extensionDirectory) { factory VsCode.fromDirectory(String installPath, String extensionDirectory,
{ String edition }) {
final String packageJsonPath = final String packageJsonPath =
fs.path.join(installPath, 'resources', 'app', 'package.json'); fs.path.join(installPath, 'resources', 'app', 'package.json');
final String versionString = _getVersionFromPackageJson(packageJsonPath); final String versionString = _getVersionFromPackageJson(packageJsonPath);
Version version; Version version;
if (versionString != null) if (versionString != null)
version = new Version.parse(versionString); version = new Version.parse(versionString);
return new VsCode._(installPath, extensionDirectory, version: version); return new VsCode._(installPath, extensionDirectory, version: version, edition: edition);
} }
bool get isValid => _isValid; bool get isValid => _isValid;
String get productName => 'VS Code' + (edition != null ? ', $edition' : '');
Iterable<String> get validationMessages => _validationMessages; Iterable<String> get validationMessages => _validationMessages;
...@@ -90,21 +93,26 @@ class VsCode { ...@@ -90,21 +93,26 @@ class VsCode {
// $HOME/.vscode/extensions // $HOME/.vscode/extensions
// $HOME/.vscode-insiders/extensions // $HOME/.vscode-insiders/extensions
static List<VsCode> _installedMacOS() { static List<VsCode> _installedMacOS() {
final Map<String, String> stable = <String, String>{ return _findInstalled(<_VsCodeInstallLocation>[
fs.path.join('/Applications', 'Visual Studio Code.app', 'Contents'): new _VsCodeInstallLocation(
fs.path.join('/Applications', 'Visual Studio Code.app', 'Contents'),
'.vscode', '.vscode',
fs.path.join(homeDirPath, 'Applications', 'Visual Studio Code.app', ),
'Contents'): '.vscode' new _VsCodeInstallLocation(
}; fs.path.join(homeDirPath, 'Applications', 'Visual Studio Code.app', 'Contents'),
final Map<String, String> insiders = <String, String>{ '.vscode',
fs.path.join( ),
'/Applications', 'Visual Studio Code - Insiders.app', 'Contents'): new _VsCodeInstallLocation(
fs.path.join('/Applications', 'Visual Studio Code - Insiders.app', 'Contents'),
'.vscode-insiders', '.vscode-insiders',
fs.path.join(homeDirPath, 'Applications', isInsiders: true,
'Visual Studio Code - Insiders.app', 'Contents'): '.vscode-insiders' ),
}; new _VsCodeInstallLocation(
fs.path.join(homeDirPath, 'Applications', 'Visual Studio Code - Insiders.app', 'Contents'),
return _findInstalled(stable, insiders); '.vscode-insiders',
isInsiders: true,
)
]);
} }
// Windows: // Windows:
...@@ -120,17 +128,16 @@ class VsCode { ...@@ -120,17 +128,16 @@ class VsCode {
final String progFiles86 = platform.environment['programfiles(x86)']; final String progFiles86 = platform.environment['programfiles(x86)'];
final String progFiles = platform.environment['programfiles']; final String progFiles = platform.environment['programfiles'];
final Map<String, String> stable = <String, String>{ return _findInstalled(<_VsCodeInstallLocation>[
fs.path.join(progFiles86, 'Microsoft VS Code'): '.vscode', new _VsCodeInstallLocation(fs.path.join(progFiles86, 'Microsoft VS Code'), '.vscode',
fs.path.join(progFiles, 'Microsoft VS Code'): '.vscode' edition: '32-bit edition'),
}; new _VsCodeInstallLocation(fs.path.join(progFiles, 'Microsoft VS Code'), '.vscode',
final Map<String, String> insiders = <String, String>{ edition: '64-bit edition'),
fs.path.join(progFiles86, 'Microsoft VS Code Insiders'): new _VsCodeInstallLocation(fs.path.join(progFiles86 , 'Microsoft VS Code Insiders'), '.vscode-insiders',
'.vscode-insiders', edition: '32-bit edition', isInsiders: true),
fs.path.join(progFiles, 'Microsoft VS Code Insiders'): '.vscode-insiders' new _VsCodeInstallLocation(fs.path.join(progFiles, 'Microsoft VS Code Insiders'), '.vscode-insiders',
}; edition: '64-bit edition', isInsiders: true),
]);
return _findInstalled(stable, insiders);
} }
// Linux: // Linux:
...@@ -140,26 +147,26 @@ class VsCode { ...@@ -140,26 +147,26 @@ class VsCode {
// $HOME/.vscode/extensions // $HOME/.vscode/extensions
// $HOME/.vscode-insiders/extensions // $HOME/.vscode-insiders/extensions
static List<VsCode> _installedLinux() { static List<VsCode> _installedLinux() {
return _findInstalled( return _findInstalled(<_VsCodeInstallLocation>[
<String, String>{'/usr/share/code': '.vscode'}, const _VsCodeInstallLocation('/usr/share/code', '.vscode'),
<String, String>{'/usr/share/code-insiders': '.vscode-insiders'} const _VsCodeInstallLocation('/usr/share/code-insiders', '.vscode-insiders', isInsiders: true),
); ]);
} }
static List<VsCode> _findInstalled( static List<VsCode> _findInstalled(
Map<String, String> stable, Map<String, String> insiders) { List<_VsCodeInstallLocation> allLocations) {
final Map<String, String> allPaths = <String, String>{}; final Iterable<_VsCodeInstallLocation> searchLocations =
allPaths.addAll(stable); _includeInsiders
if (_includeInsiders) ? allLocations
allPaths.addAll(insiders); : allLocations.where((_VsCodeInstallLocation p) => p.isInsiders != true);
final List<VsCode> results = <VsCode>[]; final List<VsCode> results = <VsCode>[];
for (String directory in allPaths.keys) { for (_VsCodeInstallLocation searchLocation in searchLocations) {
if (fs.directory(directory).existsSync()) { if (fs.directory(searchLocation.installPath).existsSync()) {
final String extensionDirectory = final String extensionDirectory =
fs.path.join(homeDirPath, allPaths[directory], 'extensions'); fs.path.join(homeDirPath, searchLocation.extensionsFolder, 'extensions');
results.add(new VsCode.fromDirectory(directory, extensionDirectory)); results.add(new VsCode.fromDirectory(searchLocation.installPath, extensionDirectory, edition: searchLocation.edition));
} }
} }
...@@ -178,3 +185,12 @@ class VsCode { ...@@ -178,3 +185,12 @@ class VsCode {
return json['version']; return json['version'];
} }
} }
class _VsCodeInstallLocation {
final String installPath;
final String extensionsFolder;
final String edition;
final bool isInsiders;
const _VsCodeInstallLocation(this.installPath, this.extensionsFolder, { this.edition, bool isInsiders })
: this.isInsiders = isInsiders ?? false;
}
...@@ -13,7 +13,7 @@ class VsCodeValidator extends DoctorValidator { ...@@ -13,7 +13,7 @@ class VsCodeValidator extends DoctorValidator {
'https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code'; 'https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code';
final VsCode _vsCode; final VsCode _vsCode;
VsCodeValidator(this._vsCode) : super('VS Code'); VsCodeValidator(this._vsCode) : super(_vsCode.productName);
static Iterable<DoctorValidator> get installedValidators { static Iterable<DoctorValidator> get installedValidators {
return VsCode return VsCode
......
...@@ -50,6 +50,22 @@ void main() { ...@@ -50,6 +50,22 @@ void main() {
expect(message.message, 'Dart Code extension version 4.5.6'); expect(message.message, 'Dart Code extension version 4.5.6');
}); });
testUsingContext('vs code validator when 64bit installed', () async {
expect(VsCodeValidatorTestTargets.installedWithExtension64bit.title, 'VS Code, 64-bit edition');
final ValidationResult result = await VsCodeValidatorTestTargets.installedWithExtension64bit.validate();
expect(result.type, ValidationType.installed);
expect(result.statusInfo, 'version 1.2.3');
expect(result.messages, hasLength(2));
ValidationMessage message = result.messages
.firstWhere((ValidationMessage m) => m.message.startsWith('VS Code '));
expect(message.message, 'VS Code at ${VsCodeValidatorTestTargets.validInstall}');
message = result.messages
.firstWhere((ValidationMessage m) => m.message.startsWith('Dart Code '));
expect(message.message, 'Dart Code extension version 4.5.6');
});
testUsingContext('vs code validator when extension missing', () async { testUsingContext('vs code validator when extension missing', () async {
final ValidationResult result = await VsCodeValidatorTestTargets.installedWithoutExtension.validate(); final ValidationResult result = await VsCodeValidatorTestTargets.installedWithoutExtension.validate();
expect(result.type, ValidationType.partial); expect(result.type, ValidationType.partial);
...@@ -279,12 +295,15 @@ class VsCodeValidatorTestTargets extends VsCodeValidator { ...@@ -279,12 +295,15 @@ class VsCodeValidatorTestTargets extends VsCodeValidator {
static final String validInstall = fs.path.join('test', 'data', 'vscode', 'application'); static final String validInstall = fs.path.join('test', 'data', 'vscode', 'application');
static final String validExtensions = fs.path.join('test', 'data', 'vscode', 'extensions'); static final String validExtensions = fs.path.join('test', 'data', 'vscode', 'extensions');
static final String missingExtensions = fs.path.join('test', 'data', 'vscode', 'notExtensions'); static final String missingExtensions = fs.path.join('test', 'data', 'vscode', 'notExtensions');
VsCodeValidatorTestTargets._(String installDirectory, String extensionDirectory) VsCodeValidatorTestTargets._(String installDirectory, String extensionDirectory, {String edition})
: super(new VsCode.fromDirectory(installDirectory, extensionDirectory)); : super(new VsCode.fromDirectory(installDirectory, extensionDirectory, edition: edition));
static VsCodeValidatorTestTargets get installedWithExtension => static VsCodeValidatorTestTargets get installedWithExtension =>
new VsCodeValidatorTestTargets._(validInstall, validExtensions); new VsCodeValidatorTestTargets._(validInstall, validExtensions);
static VsCodeValidatorTestTargets get installedWithExtension64bit =>
new VsCodeValidatorTestTargets._(validInstall, validExtensions, edition: '64-bit edition');
static VsCodeValidatorTestTargets get installedWithoutExtension => static VsCodeValidatorTestTargets get installedWithoutExtension =>
new VsCodeValidatorTestTargets._(validInstall, missingExtensions); new VsCodeValidatorTestTargets._(validInstall, missingExtensions);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment