Skip to content

Commit db1a942

Browse files
authored
Show 32/64bit in VS Code headings on Windows (flutter#15018)
* Show 32/64bit in VS Code headings on Windows Fixes flutter#14949.
1 parent d379762 commit db1a942

File tree

3 files changed

+80
-45
lines changed

3 files changed

+80
-45
lines changed

packages/flutter_tools/lib/src/vscode/vscode.dart

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const bool _includeInsiders = false;
1515
class VsCode {
1616
static const String extensionIdentifier = 'Dart-Code.dart-code';
1717

18-
VsCode._(this.directory, this.extensionDirectory, { Version version })
18+
VsCode._(this.directory, this.extensionDirectory, { Version version, this.edition })
1919
: this.version = version ?? Version.unknown {
2020

2121
if (!fs.isDirectorySync(directory)) {
@@ -50,22 +50,25 @@ class VsCode {
5050
final String directory;
5151
final String extensionDirectory;
5252
final Version version;
53+
final String edition;
5354

5455
bool _isValid = false;
5556
Version _extensionVersion;
5657
final List<String> _validationMessages = <String>[];
5758

58-
factory VsCode.fromDirectory(String installPath, String extensionDirectory) {
59+
factory VsCode.fromDirectory(String installPath, String extensionDirectory,
60+
{ String edition }) {
5961
final String packageJsonPath =
6062
fs.path.join(installPath, 'resources', 'app', 'package.json');
6163
final String versionString = _getVersionFromPackageJson(packageJsonPath);
6264
Version version;
6365
if (versionString != null)
6466
version = new Version.parse(versionString);
65-
return new VsCode._(installPath, extensionDirectory, version: version);
67+
return new VsCode._(installPath, extensionDirectory, version: version, edition: edition);
6668
}
6769

6870
bool get isValid => _isValid;
71+
String get productName => 'VS Code' + (edition != null ? ', $edition' : '');
6972

7073
Iterable<String> get validationMessages => _validationMessages;
7174

@@ -90,21 +93,26 @@ class VsCode {
9093
// $HOME/.vscode/extensions
9194
// $HOME/.vscode-insiders/extensions
9295
static List<VsCode> _installedMacOS() {
93-
final Map<String, String> stable = <String, String>{
94-
fs.path.join('/Applications', 'Visual Studio Code.app', 'Contents'):
95-
'.vscode',
96-
fs.path.join(homeDirPath, 'Applications', 'Visual Studio Code.app',
97-
'Contents'): '.vscode'
98-
};
99-
final Map<String, String> insiders = <String, String>{
100-
fs.path.join(
101-
'/Applications', 'Visual Studio Code - Insiders.app', 'Contents'):
102-
'.vscode-insiders',
103-
fs.path.join(homeDirPath, 'Applications',
104-
'Visual Studio Code - Insiders.app', 'Contents'): '.vscode-insiders'
105-
};
106-
107-
return _findInstalled(stable, insiders);
96+
return _findInstalled(<_VsCodeInstallLocation>[
97+
new _VsCodeInstallLocation(
98+
fs.path.join('/Applications', 'Visual Studio Code.app', 'Contents'),
99+
'.vscode',
100+
),
101+
new _VsCodeInstallLocation(
102+
fs.path.join(homeDirPath, 'Applications', 'Visual Studio Code.app', 'Contents'),
103+
'.vscode',
104+
),
105+
new _VsCodeInstallLocation(
106+
fs.path.join('/Applications', 'Visual Studio Code - Insiders.app', 'Contents'),
107+
'.vscode-insiders',
108+
isInsiders: true,
109+
),
110+
new _VsCodeInstallLocation(
111+
fs.path.join(homeDirPath, 'Applications', 'Visual Studio Code - Insiders.app', 'Contents'),
112+
'.vscode-insiders',
113+
isInsiders: true,
114+
)
115+
]);
108116
}
109117

110118
// Windows:
@@ -120,17 +128,16 @@ class VsCode {
120128
final String progFiles86 = platform.environment['programfiles(x86)'];
121129
final String progFiles = platform.environment['programfiles'];
122130

123-
final Map<String, String> stable = <String, String>{
124-
fs.path.join(progFiles86, 'Microsoft VS Code'): '.vscode',
125-
fs.path.join(progFiles, 'Microsoft VS Code'): '.vscode'
126-
};
127-
final Map<String, String> insiders = <String, String>{
128-
fs.path.join(progFiles86, 'Microsoft VS Code Insiders'):
129-
'.vscode-insiders',
130-
fs.path.join(progFiles, 'Microsoft VS Code Insiders'): '.vscode-insiders'
131-
};
132-
133-
return _findInstalled(stable, insiders);
131+
return _findInstalled(<_VsCodeInstallLocation>[
132+
new _VsCodeInstallLocation(fs.path.join(progFiles86, 'Microsoft VS Code'), '.vscode',
133+
edition: '32-bit edition'),
134+
new _VsCodeInstallLocation(fs.path.join(progFiles, 'Microsoft VS Code'), '.vscode',
135+
edition: '64-bit edition'),
136+
new _VsCodeInstallLocation(fs.path.join(progFiles86 , 'Microsoft VS Code Insiders'), '.vscode-insiders',
137+
edition: '32-bit edition', isInsiders: true),
138+
new _VsCodeInstallLocation(fs.path.join(progFiles, 'Microsoft VS Code Insiders'), '.vscode-insiders',
139+
edition: '64-bit edition', isInsiders: true),
140+
]);
134141
}
135142

136143
// Linux:
@@ -140,26 +147,26 @@ class VsCode {
140147
// $HOME/.vscode/extensions
141148
// $HOME/.vscode-insiders/extensions
142149
static List<VsCode> _installedLinux() {
143-
return _findInstalled(
144-
<String, String>{'/usr/share/code': '.vscode'},
145-
<String, String>{'/usr/share/code-insiders': '.vscode-insiders'}
146-
);
150+
return _findInstalled(<_VsCodeInstallLocation>[
151+
const _VsCodeInstallLocation('/usr/share/code', '.vscode'),
152+
const _VsCodeInstallLocation('/usr/share/code-insiders', '.vscode-insiders', isInsiders: true),
153+
]);
147154
}
148155

149156
static List<VsCode> _findInstalled(
150-
Map<String, String> stable, Map<String, String> insiders) {
151-
final Map<String, String> allPaths = <String, String>{};
152-
allPaths.addAll(stable);
153-
if (_includeInsiders)
154-
allPaths.addAll(insiders);
157+
List<_VsCodeInstallLocation> allLocations) {
158+
final Iterable<_VsCodeInstallLocation> searchLocations =
159+
_includeInsiders
160+
? allLocations
161+
: allLocations.where((_VsCodeInstallLocation p) => p.isInsiders != true);
155162

156163
final List<VsCode> results = <VsCode>[];
157164

158-
for (String directory in allPaths.keys) {
159-
if (fs.directory(directory).existsSync()) {
165+
for (_VsCodeInstallLocation searchLocation in searchLocations) {
166+
if (fs.directory(searchLocation.installPath).existsSync()) {
160167
final String extensionDirectory =
161-
fs.path.join(homeDirPath, allPaths[directory], 'extensions');
162-
results.add(new VsCode.fromDirectory(directory, extensionDirectory));
168+
fs.path.join(homeDirPath, searchLocation.extensionsFolder, 'extensions');
169+
results.add(new VsCode.fromDirectory(searchLocation.installPath, extensionDirectory, edition: searchLocation.edition));
163170
}
164171
}
165172

@@ -178,3 +185,12 @@ class VsCode {
178185
return json['version'];
179186
}
180187
}
188+
189+
class _VsCodeInstallLocation {
190+
final String installPath;
191+
final String extensionsFolder;
192+
final String edition;
193+
final bool isInsiders;
194+
const _VsCodeInstallLocation(this.installPath, this.extensionsFolder, { this.edition, bool isInsiders })
195+
: this.isInsiders = isInsiders ?? false;
196+
}

packages/flutter_tools/lib/src/vscode/vscode_validator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class VsCodeValidator extends DoctorValidator {
1313
'https://marketplace.visualstudio.com/items?itemName=Dart-Code.dart-code';
1414
final VsCode _vsCode;
1515

16-
VsCodeValidator(this._vsCode) : super('VS Code');
16+
VsCodeValidator(this._vsCode) : super(_vsCode.productName);
1717

1818
static Iterable<DoctorValidator> get installedValidators {
1919
return VsCode

packages/flutter_tools/test/commands/doctor_test.dart

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ void main() {
5050
expect(message.message, 'Dart Code extension version 4.5.6');
5151
});
5252

53+
testUsingContext('vs code validator when 64bit installed', () async {
54+
expect(VsCodeValidatorTestTargets.installedWithExtension64bit.title, 'VS Code, 64-bit edition');
55+
final ValidationResult result = await VsCodeValidatorTestTargets.installedWithExtension64bit.validate();
56+
expect(result.type, ValidationType.installed);
57+
expect(result.statusInfo, 'version 1.2.3');
58+
expect(result.messages, hasLength(2));
59+
60+
ValidationMessage message = result.messages
61+
.firstWhere((ValidationMessage m) => m.message.startsWith('VS Code '));
62+
expect(message.message, 'VS Code at ${VsCodeValidatorTestTargets.validInstall}');
63+
64+
message = result.messages
65+
.firstWhere((ValidationMessage m) => m.message.startsWith('Dart Code '));
66+
expect(message.message, 'Dart Code extension version 4.5.6');
67+
});
68+
5369
testUsingContext('vs code validator when extension missing', () async {
5470
final ValidationResult result = await VsCodeValidatorTestTargets.installedWithoutExtension.validate();
5571
expect(result.type, ValidationType.partial);
@@ -279,12 +295,15 @@ class VsCodeValidatorTestTargets extends VsCodeValidator {
279295
static final String validInstall = fs.path.join('test', 'data', 'vscode', 'application');
280296
static final String validExtensions = fs.path.join('test', 'data', 'vscode', 'extensions');
281297
static final String missingExtensions = fs.path.join('test', 'data', 'vscode', 'notExtensions');
282-
VsCodeValidatorTestTargets._(String installDirectory, String extensionDirectory)
283-
: super(new VsCode.fromDirectory(installDirectory, extensionDirectory));
298+
VsCodeValidatorTestTargets._(String installDirectory, String extensionDirectory, {String edition})
299+
: super(new VsCode.fromDirectory(installDirectory, extensionDirectory, edition: edition));
284300

285301
static VsCodeValidatorTestTargets get installedWithExtension =>
286302
new VsCodeValidatorTestTargets._(validInstall, validExtensions);
287303

304+
static VsCodeValidatorTestTargets get installedWithExtension64bit =>
305+
new VsCodeValidatorTestTargets._(validInstall, validExtensions, edition: '64-bit edition');
306+
288307
static VsCodeValidatorTestTargets get installedWithoutExtension =>
289308
new VsCodeValidatorTestTargets._(validInstall, missingExtensions);
290309
}

0 commit comments

Comments
 (0)