mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Migrate vscode to null safety (#79805)
This commit is contained in:
parent
30370c9f99
commit
af164fe559
@ -2,10 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../base/file_system.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/utils.dart';
|
||||
@ -21,7 +17,7 @@ const String extensionMarketplaceUrl =
|
||||
'https://marketplace.visualstudio.com/items?itemName=$extensionIdentifier';
|
||||
|
||||
class VsCode {
|
||||
VsCode._(this.directory, this.extensionDirectory, { Version version, this.edition, @required FileSystem fileSystem})
|
||||
VsCode._(this.directory, this.extensionDirectory, { Version? version, this.edition, required FileSystem fileSystem})
|
||||
: version = version ?? Version.unknown {
|
||||
|
||||
if (!fileSystem.isDirectorySync(directory)) {
|
||||
@ -64,13 +60,13 @@ class VsCode {
|
||||
factory VsCode.fromDirectory(
|
||||
String installPath,
|
||||
String extensionDirectory, {
|
||||
String edition,
|
||||
@required FileSystem fileSystem,
|
||||
String? edition,
|
||||
required FileSystem fileSystem,
|
||||
}) {
|
||||
final String packageJsonPath =
|
||||
fileSystem.path.join(installPath, 'resources', 'app', 'package.json');
|
||||
final String versionString = _getVersionFromPackageJson(packageJsonPath, fileSystem);
|
||||
Version version;
|
||||
final String? versionString = _getVersionFromPackageJson(packageJsonPath, fileSystem);
|
||||
Version? version;
|
||||
if (versionString != null) {
|
||||
version = Version.parse(versionString);
|
||||
}
|
||||
@ -80,9 +76,9 @@ class VsCode {
|
||||
final String directory;
|
||||
final String extensionDirectory;
|
||||
final Version version;
|
||||
final String edition;
|
||||
final String? edition;
|
||||
|
||||
Version _extensionVersion;
|
||||
Version? _extensionVersion;
|
||||
final List<ValidationMessage> _validationMessages = <ValidationMessage>[];
|
||||
|
||||
String get productName => 'VS Code' + (edition != null ? ', $edition' : '');
|
||||
@ -115,35 +111,38 @@ class VsCode {
|
||||
// $HOME/.vscode/extensions
|
||||
// $HOME/.vscode-insiders/extensions
|
||||
static List<VsCode> _installedMacOS(FileSystem fileSystem, Platform platform) {
|
||||
final String? homeDirPath = FileSystemUtils(fileSystem: fileSystem, platform: platform).homeDirPath;
|
||||
return _findInstalled(<_VsCodeInstallLocation>[
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join('/Applications', 'Visual Studio Code.app', 'Contents'),
|
||||
'.vscode',
|
||||
),
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join(
|
||||
FileSystemUtils(fileSystem: fileSystem, platform: platform).homeDirPath,
|
||||
'Applications',
|
||||
'Visual Studio Code.app',
|
||||
'Contents',
|
||||
if (homeDirPath != null)
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join(
|
||||
homeDirPath,
|
||||
'Applications',
|
||||
'Visual Studio Code.app',
|
||||
'Contents',
|
||||
),
|
||||
'.vscode',
|
||||
),
|
||||
'.vscode',
|
||||
),
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join('/Applications', 'Visual Studio Code - Insiders.app', 'Contents'),
|
||||
'.vscode-insiders',
|
||||
isInsiders: true,
|
||||
),
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join(
|
||||
FileSystemUtils(fileSystem: fileSystem, platform: platform).homeDirPath,
|
||||
'Applications',
|
||||
'Visual Studio Code - Insiders.app',
|
||||
'Contents',
|
||||
if (homeDirPath != null)
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join(
|
||||
homeDirPath,
|
||||
'Applications',
|
||||
'Visual Studio Code - Insiders.app',
|
||||
'Contents',
|
||||
),
|
||||
'.vscode-insiders',
|
||||
isInsiders: true,
|
||||
),
|
||||
'.vscode-insiders',
|
||||
isInsiders: true,
|
||||
),
|
||||
], fileSystem, platform);
|
||||
}
|
||||
|
||||
@ -163,9 +162,9 @@ class VsCode {
|
||||
FileSystem fileSystem,
|
||||
Platform platform,
|
||||
) {
|
||||
final String progFiles86 = platform.environment['programfiles(x86)'];
|
||||
final String progFiles = platform.environment['programfiles'];
|
||||
final String localAppData = platform.environment['localappdata'];
|
||||
final String? progFiles86 = platform.environment['programfiles(x86)'];
|
||||
final String? progFiles = platform.environment['programfiles'];
|
||||
final String? localAppData = platform.environment['localappdata'];
|
||||
|
||||
final List<_VsCodeInstallLocation> searchLocations = <_VsCodeInstallLocation>[
|
||||
if (localAppData != null)
|
||||
@ -241,9 +240,10 @@ class VsCode {
|
||||
final List<VsCode> results = <VsCode>[];
|
||||
|
||||
for (final _VsCodeInstallLocation searchLocation in searchLocations) {
|
||||
if (fileSystem.isDirectorySync(searchLocation.installPath)) {
|
||||
final String? homeDirPath = FileSystemUtils(fileSystem: fileSystem, platform: platform).homeDirPath;
|
||||
if (homeDirPath != null && fileSystem.isDirectorySync(searchLocation.installPath)) {
|
||||
final String extensionDirectory = fileSystem.path.join(
|
||||
FileSystemUtils(fileSystem: fileSystem, platform: platform).homeDirPath,
|
||||
homeDirPath,
|
||||
searchLocation.extensionsFolder,
|
||||
'extensions',
|
||||
);
|
||||
@ -263,17 +263,20 @@ class VsCode {
|
||||
String toString() =>
|
||||
'VS Code ($version)${_extensionVersion != Version.unknown ? ', Flutter ($_extensionVersion)' : ''}';
|
||||
|
||||
static String _getVersionFromPackageJson(String packageJsonPath, FileSystem fileSystem) {
|
||||
static String? _getVersionFromPackageJson(String packageJsonPath, FileSystem fileSystem) {
|
||||
if (!fileSystem.isFileSync(packageJsonPath)) {
|
||||
return null;
|
||||
}
|
||||
final String jsonString = fileSystem.file(packageJsonPath).readAsStringSync();
|
||||
try {
|
||||
final Map<String, dynamic> jsonObject = castStringKeyedMap(json.decode(jsonString));
|
||||
return jsonObject['version'] as String;
|
||||
final Map<String, dynamic>? jsonObject = castStringKeyedMap(json.decode(jsonString));
|
||||
if (jsonObject?.containsKey('version') == true) {
|
||||
return jsonObject!['version'] as String;
|
||||
}
|
||||
} on FormatException {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,11 +285,11 @@ class _VsCodeInstallLocation {
|
||||
this.installPath,
|
||||
this.extensionsFolder, {
|
||||
this.edition,
|
||||
bool isInsiders
|
||||
bool? isInsiders
|
||||
}) : isInsiders = isInsiders ?? false;
|
||||
|
||||
final String installPath;
|
||||
final String extensionsFolder;
|
||||
final String edition;
|
||||
final String? edition;
|
||||
final bool isInsiders;
|
||||
}
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import '../base/file_system.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/user_messages.dart';
|
||||
@ -24,7 +22,7 @@ class VsCodeValidator extends DoctorValidator {
|
||||
|
||||
@override
|
||||
Future<ValidationResult> validate() async {
|
||||
final String vsCodeVersionText = _vsCode.version == Version.unknown
|
||||
final String? vsCodeVersionText = _vsCode.version == Version.unknown
|
||||
? null
|
||||
: userMessages.vsCodeVersion(_vsCode.version.toString());
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user