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

Make doctor output consistent between VS Code/IntelliJ/Android Studio when...

Make doctor output consistent between VS Code/IntelliJ/Android Studio when plugins are missing (#25269)

* Update VS Code validator to match Android Studio

- Now shows a tick (instead of partial) if installed
- Now shows a cross (instead of dot) if extension is not installed

Fixes #22931.
parent 9150b3f0
...@@ -44,7 +44,7 @@ class AndroidStudioValidator extends DoctorValidator { ...@@ -44,7 +44,7 @@ class AndroidStudioValidator extends DoctorValidator {
plugins.validatePackage(messages, <String>['Dart'], 'Dart'); plugins.validatePackage(messages, <String>['Dart'], 'Dart');
if (_studio.isValid) { if (_studio.isValid) {
type = ValidationType.installed; type = _hasIssues(messages) ? ValidationType.partial : ValidationType.installed;
messages.addAll(_studio.validationMessages messages.addAll(_studio.validationMessages
.map<ValidationMessage>((String m) => ValidationMessage(m))); .map<ValidationMessage>((String m) => ValidationMessage(m)));
} else { } else {
...@@ -61,6 +61,10 @@ class AndroidStudioValidator extends DoctorValidator { ...@@ -61,6 +61,10 @@ class AndroidStudioValidator extends DoctorValidator {
return ValidationResult(type, messages, statusInfo: studioVersionText); return ValidationResult(type, messages, statusInfo: studioVersionText);
} }
bool _hasIssues(List<ValidationMessage> messages) {
return messages.any((ValidationMessage message) => message.isError);
}
} }
class NoAndroidStudioValidator extends DoctorValidator { class NoAndroidStudioValidator extends DoctorValidator {
......
...@@ -8,22 +8,33 @@ import '../base/common.dart'; ...@@ -8,22 +8,33 @@ import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/version.dart'; import '../base/version.dart';
import '../doctor.dart';
// Include VS Code insiders (useful for debugging). // Include VS Code insiders (useful for debugging).
const bool _includeInsiders = false; const bool _includeInsiders = false;
const String extensionIdentifier = 'Dart-Code.flutter';
const String extensionMarketplaceUrl =
'https://marketplace.visualstudio.com/items?itemName=$extensionIdentifier';
class VsCode { class VsCode {
VsCode._(this.directory, this.extensionDirectory, { Version version, this.edition }) VsCode._(this.directory, this.extensionDirectory, { Version version, this.edition })
: version = version ?? Version.unknown { : version = version ?? Version.unknown {
if (!fs.isDirectorySync(directory)) { if (!fs.isDirectorySync(directory)) {
_validationMessages.add('VS Code not found at $directory'); _validationMessages.add(ValidationMessage.error('VS Code not found at $directory'));
return; return;
} else {
_validationMessages.add(ValidationMessage('VS Code at $directory'));
} }
// If the extensions directory doesn't exist at all, the listSync() // If the extensions directory doesn't exist at all, the listSync()
// below will fail, so just bail out early. // below will fail, so just bail out early.
final ValidationMessage notInstalledMessage = ValidationMessage.error(
'Flutter extension not installed; install from\n$extensionMarketplaceUrl');
if (!fs.isDirectorySync(extensionDirectory)) { if (!fs.isDirectorySync(extensionDirectory)) {
_validationMessages.add(notInstalledMessage);
return; return;
} }
...@@ -41,7 +52,9 @@ class VsCode { ...@@ -41,7 +52,9 @@ class VsCode {
_isValid = true; _isValid = true;
_extensionVersion = Version.parse( _extensionVersion = Version.parse(
extensionDir.basename.substring('$extensionIdentifier-'.length)); extensionDir.basename.substring('$extensionIdentifier-'.length));
_validationMessages.add('Flutter extension version $_extensionVersion'); _validationMessages.add(ValidationMessage('Flutter extension version $_extensionVersion'));
} else {
_validationMessages.add(notInstalledMessage);
} }
} }
...@@ -61,16 +74,14 @@ class VsCode { ...@@ -61,16 +74,14 @@ class VsCode {
final Version version; final Version version;
final String edition; final String edition;
static const String extensionIdentifier = 'Dart-Code.flutter';
bool _isValid = false; bool _isValid = false;
Version _extensionVersion; Version _extensionVersion;
final List<String> _validationMessages = <String>[]; final List<ValidationMessage> _validationMessages = <ValidationMessage>[];
bool get isValid => _isValid; bool get isValid => _isValid;
String get productName => 'VS Code' + (edition != null ? ', $edition' : ''); String get productName => 'VS Code' + (edition != null ? ', $edition' : '');
Iterable<String> get validationMessages => _validationMessages; Iterable<ValidationMessage> get validationMessages => _validationMessages;
static List<VsCode> allInstalled() { static List<VsCode> allInstalled() {
if (platform.isMacOS) if (platform.isMacOS)
......
...@@ -13,8 +13,6 @@ class VsCodeValidator extends DoctorValidator { ...@@ -13,8 +13,6 @@ class VsCodeValidator extends DoctorValidator {
final VsCode _vsCode; final VsCode _vsCode;
static const String extensionMarketplaceUrl =
'https://marketplace.visualstudio.com/items?itemName=${VsCode.extensionIdentifier}';
static Iterable<DoctorValidator> get installedValidators { static Iterable<DoctorValidator> get installedValidators {
return VsCode return VsCode
...@@ -24,24 +22,18 @@ class VsCodeValidator extends DoctorValidator { ...@@ -24,24 +22,18 @@ class VsCodeValidator extends DoctorValidator {
@override @override
Future<ValidationResult> validate() async { Future<ValidationResult> validate() async {
final List<ValidationMessage> messages = <ValidationMessage>[];
ValidationType type = ValidationType.missing;
final String vsCodeVersionText = _vsCode.version == Version.unknown final String vsCodeVersionText = _vsCode.version == Version.unknown
? null ? null
: 'version ${_vsCode.version}'; : 'version ${_vsCode.version}';
messages.add(ValidationMessage('VS Code at ${_vsCode.directory}'));
if (_vsCode.isValid) {
type = ValidationType.installed;
messages.addAll(_vsCode.validationMessages
.map<ValidationMessage>((String m) => ValidationMessage(m)));
} else {
type = ValidationType.partial;
messages.addAll(_vsCode.validationMessages
.map<ValidationMessage>((String m) => ValidationMessage.error(m)));
messages.add(ValidationMessage(
'Flutter extension not installed; install from\n$extensionMarketplaceUrl'));
}
return ValidationResult(type, messages, statusInfo: vsCodeVersionText); final ValidationType validationType = _vsCode.isValid
? ValidationType.installed
: ValidationType.partial;
return ValidationResult(
validationType,
_vsCode.validationMessages,
statusInfo: vsCodeVersionText,
);
} }
} }
...@@ -55,6 +55,7 @@ void main() { ...@@ -55,6 +55,7 @@ void main() {
message = result.messages message = result.messages
.firstWhere((ValidationMessage m) => m.message.startsWith('Flutter ')); .firstWhere((ValidationMessage m) => m.message.startsWith('Flutter '));
expect(message.message, 'Flutter extension version 4.5.6'); expect(message.message, 'Flutter extension version 4.5.6');
expect(message.isError, isFalse);
}, overrides: noColorTerminalOverride); }, overrides: noColorTerminalOverride);
testUsingContext('vs code validator when 64bit installed', () async { testUsingContext('vs code validator when 64bit installed', () async {
...@@ -86,6 +87,7 @@ void main() { ...@@ -86,6 +87,7 @@ void main() {
message = result.messages message = result.messages
.firstWhere((ValidationMessage m) => m.message.startsWith('Flutter ')); .firstWhere((ValidationMessage m) => m.message.startsWith('Flutter '));
expect(message.message, startsWith('Flutter extension not installed')); expect(message.message, startsWith('Flutter extension not installed'));
expect(message.isError, isTrue);
}, overrides: noColorTerminalOverride); }, overrides: noColorTerminalOverride);
}); });
......
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