forked from firka/flutter
[flutter_tools] fix windows vscode lookup (#56491)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import '../base/file_system.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../base/version.dart';
|
||||
import '../convert.dart';
|
||||
@@ -86,15 +87,18 @@ class VsCode {
|
||||
|
||||
Iterable<ValidationMessage> get validationMessages => _validationMessages;
|
||||
|
||||
static List<VsCode> allInstalled() {
|
||||
if (globals.platform.isMacOS) {
|
||||
return _installedMacOS();
|
||||
static List<VsCode> allInstalled(
|
||||
FileSystem fileSystem,
|
||||
Platform platform,
|
||||
) {
|
||||
if (platform.isMacOS) {
|
||||
return _installedMacOS(fileSystem);
|
||||
}
|
||||
if (globals.platform.isWindows) {
|
||||
return _installedWindows();
|
||||
if (platform.isWindows) {
|
||||
return _installedWindows(fileSystem, platform);
|
||||
}
|
||||
if (globals.platform.isLinux) {
|
||||
return _installedLinux();
|
||||
if (platform.isLinux) {
|
||||
return _installedLinux(fileSystem);
|
||||
}
|
||||
// VS Code isn't supported on the other platforms.
|
||||
return <VsCode>[];
|
||||
@@ -108,14 +112,14 @@ class VsCode {
|
||||
// macOS Extensions:
|
||||
// $HOME/.vscode/extensions
|
||||
// $HOME/.vscode-insiders/extensions
|
||||
static List<VsCode> _installedMacOS() {
|
||||
static List<VsCode> _installedMacOS(FileSystem fileSystem) {
|
||||
return _findInstalled(<_VsCodeInstallLocation>[
|
||||
_VsCodeInstallLocation(
|
||||
globals.fs.path.join('/Applications', 'Visual Studio Code.app', 'Contents'),
|
||||
fileSystem.path.join('/Applications', 'Visual Studio Code.app', 'Contents'),
|
||||
'.vscode',
|
||||
),
|
||||
_VsCodeInstallLocation(
|
||||
globals.fs.path.join(
|
||||
fileSystem.path.join(
|
||||
globals.fsUtils.homeDirPath,
|
||||
'Applications',
|
||||
'Visual Studio Code.app',
|
||||
@@ -124,12 +128,12 @@ class VsCode {
|
||||
'.vscode',
|
||||
),
|
||||
_VsCodeInstallLocation(
|
||||
globals.fs.path.join('/Applications', 'Visual Studio Code - Insiders.app', 'Contents'),
|
||||
fileSystem.path.join('/Applications', 'Visual Studio Code - Insiders.app', 'Contents'),
|
||||
'.vscode-insiders',
|
||||
isInsiders: true,
|
||||
),
|
||||
_VsCodeInstallLocation(
|
||||
globals.fs.path.join(
|
||||
fileSystem.path.join(
|
||||
globals.fsUtils.homeDirPath,
|
||||
'Applications',
|
||||
'Visual Studio Code - Insiders.app',
|
||||
@@ -138,7 +142,7 @@ class VsCode {
|
||||
'.vscode-insiders',
|
||||
isInsiders: true,
|
||||
),
|
||||
]);
|
||||
], fileSystem);
|
||||
}
|
||||
|
||||
// Windows:
|
||||
@@ -153,51 +157,56 @@ class VsCode {
|
||||
// Windows Extensions:
|
||||
// $HOME/.vscode/extensions
|
||||
// $HOME/.vscode-insiders/extensions
|
||||
static List<VsCode> _installedWindows() {
|
||||
final String progFiles86 = globals.platform.environment['programfiles(x86)'];
|
||||
final String progFiles = globals.platform.environment['programfiles'];
|
||||
final String localAppData = globals.platform.environment['localappdata'];
|
||||
static List<VsCode> _installedWindows(
|
||||
FileSystem fileSystem,
|
||||
Platform platform,
|
||||
) {
|
||||
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) {
|
||||
searchLocations.add(_VsCodeInstallLocation(
|
||||
globals.fs.path.join(localAppData, r'Programs\Microsoft VS Code'),
|
||||
'.vscode',
|
||||
));
|
||||
}
|
||||
searchLocations.add(_VsCodeInstallLocation(
|
||||
globals.fs.path.join(progFiles86, 'Microsoft VS Code'),
|
||||
'.vscode',
|
||||
edition: '32-bit edition',
|
||||
));
|
||||
searchLocations.add(_VsCodeInstallLocation(
|
||||
globals.fs.path.join(progFiles, 'Microsoft VS Code'),
|
||||
'.vscode',
|
||||
edition: '64-bit edition',
|
||||
));
|
||||
if (localAppData != null) {
|
||||
searchLocations.add(_VsCodeInstallLocation(
|
||||
globals.fs.path.join(localAppData, r'Programs\Microsoft VS Code Insiders'),
|
||||
'.vscode-insiders',
|
||||
isInsiders: true,
|
||||
));
|
||||
}
|
||||
searchLocations.add(_VsCodeInstallLocation(
|
||||
globals.fs.path.join(progFiles86, 'Microsoft VS Code Insiders'),
|
||||
'.vscode-insiders',
|
||||
edition: '32-bit edition',
|
||||
isInsiders: true,
|
||||
));
|
||||
searchLocations.add(_VsCodeInstallLocation(
|
||||
globals.fs.path.join(progFiles, 'Microsoft VS Code Insiders'),
|
||||
'.vscode-insiders',
|
||||
edition: '64-bit edition',
|
||||
isInsiders: true,
|
||||
));
|
||||
|
||||
return _findInstalled(searchLocations);
|
||||
final List<_VsCodeInstallLocation> searchLocations = <_VsCodeInstallLocation>[
|
||||
if (localAppData != null)
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join(localAppData, r'Programs\Microsoft VS Code'),
|
||||
'.vscode',
|
||||
),
|
||||
if (progFiles86 != null)
|
||||
...<_VsCodeInstallLocation>[
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join(progFiles86, 'Microsoft VS Code'),
|
||||
'.vscode',
|
||||
edition: '32-bit edition',
|
||||
),
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join(progFiles86, 'Microsoft VS Code Insiders'),
|
||||
'.vscode-insiders',
|
||||
edition: '32-bit edition',
|
||||
isInsiders: true,
|
||||
),
|
||||
],
|
||||
if (progFiles != null)
|
||||
...<_VsCodeInstallLocation>[
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join(progFiles, 'Microsoft VS Code'),
|
||||
'.vscode',
|
||||
edition: '64-bit edition',
|
||||
),
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join(progFiles, 'Microsoft VS Code Insiders'),
|
||||
'.vscode-insiders',
|
||||
edition: '64-bit edition',
|
||||
isInsiders: true,
|
||||
),
|
||||
],
|
||||
if (localAppData != null)
|
||||
_VsCodeInstallLocation(
|
||||
fileSystem.path.join(localAppData, r'Programs\Microsoft VS Code Insiders'),
|
||||
'.vscode-insiders',
|
||||
isInsiders: true,
|
||||
),
|
||||
];
|
||||
return _findInstalled(searchLocations, fileSystem);
|
||||
}
|
||||
|
||||
// Linux:
|
||||
@@ -206,7 +215,7 @@ class VsCode {
|
||||
// Linux Extensions:
|
||||
// $HOME/.vscode/extensions
|
||||
// $HOME/.vscode-insiders/extensions
|
||||
static List<VsCode> _installedLinux() {
|
||||
static List<VsCode> _installedLinux(FileSystem fileSystem) {
|
||||
return _findInstalled(<_VsCodeInstallLocation>[
|
||||
const _VsCodeInstallLocation('/usr/share/code', '.vscode'),
|
||||
const _VsCodeInstallLocation(
|
||||
@@ -214,10 +223,13 @@ class VsCode {
|
||||
'.vscode-insiders',
|
||||
isInsiders: true,
|
||||
),
|
||||
]);
|
||||
], fileSystem);
|
||||
}
|
||||
|
||||
static List<VsCode> _findInstalled(List<_VsCodeInstallLocation> allLocations) {
|
||||
static List<VsCode> _findInstalled(
|
||||
List<_VsCodeInstallLocation> allLocations,
|
||||
FileSystem fileSystem,
|
||||
) {
|
||||
final Iterable<_VsCodeInstallLocation> searchLocations =
|
||||
_includeInsiders
|
||||
? allLocations
|
||||
@@ -226,8 +238,8 @@ class VsCode {
|
||||
final List<VsCode> results = <VsCode>[];
|
||||
|
||||
for (final _VsCodeInstallLocation searchLocation in searchLocations) {
|
||||
if (globals.fs.isDirectorySync(searchLocation.installPath)) {
|
||||
final String extensionDirectory = globals.fs.path.join(
|
||||
if (fileSystem.isDirectorySync(searchLocation.installPath)) {
|
||||
final String extensionDirectory = fileSystem.path.join(
|
||||
globals.fsUtils.homeDirPath,
|
||||
searchLocation.extensionsFolder,
|
||||
'extensions',
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'dart:async';
|
||||
import '../base/user_messages.dart';
|
||||
import '../base/version.dart';
|
||||
import '../doctor.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import 'vscode.dart';
|
||||
|
||||
class VsCodeValidator extends DoctorValidator {
|
||||
@@ -16,7 +17,7 @@ class VsCodeValidator extends DoctorValidator {
|
||||
|
||||
static Iterable<DoctorValidator> get installedValidators {
|
||||
return VsCode
|
||||
.allInstalled()
|
||||
.allInstalled(globals.fs, globals.platform)
|
||||
.map<DoctorValidator>((VsCode vsCode) => VsCodeValidator(vsCode));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import 'package:flutter_tools/src/base/version.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals;
|
||||
import 'package:flutter_tools/src/vscode/vscode.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
||||
void main() {
|
||||
testUsingContext('VsCode.fromDirectory does not crash when packages.json is malformed', () {
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/vscode/vscode.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
|
||||
void main() {
|
||||
testWithoutContext('VsCode search locations on windows supports an empty environment', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows);
|
||||
final Platform platform = FakePlatform(
|
||||
operatingSystem: 'windows',
|
||||
environment: <String, String>{},
|
||||
);
|
||||
|
||||
expect(VsCode.allInstalled(fileSystem, platform), isEmpty);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user