mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[ Tool ] Fix failed VSCode version lookup on Linux (#169949)
VSCode installations on Linux appear to place the packages.json file at `$VSCODE_INSTALL/resources/app/package.json` rather than at the expected `$VSCODE_INSTALL/Resources/app/package.json`, causing the VSCode version to not be reported correctly on Linux. Fixes https://github.com/flutter/flutter/issues/169812
This commit is contained in:
parent
d3e8dc3df9
commit
94e9a2ca8d
@ -68,10 +68,11 @@ class VsCode {
|
||||
String extensionDirectory, {
|
||||
String? edition,
|
||||
required FileSystem fileSystem,
|
||||
required Platform platform,
|
||||
}) {
|
||||
final String packageJsonPath = fileSystem.path.join(
|
||||
installPath,
|
||||
'Resources',
|
||||
platform.isLinux ? 'resources' : 'Resources',
|
||||
'app',
|
||||
'package.json',
|
||||
);
|
||||
@ -311,6 +312,7 @@ class VsCode {
|
||||
extensionDirectory,
|
||||
edition: searchLocation.edition,
|
||||
fileSystem: fileSystem,
|
||||
platform: platform,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -1428,6 +1428,7 @@ class VsCodeValidatorTestTargets extends VsCodeValidator {
|
||||
extensionDirectory,
|
||||
edition: edition,
|
||||
fileSystem: globals.fs,
|
||||
platform: globals.platform,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "fake-vs-code-install-for-tests",
|
||||
"version": "1.2.3"
|
||||
}
|
||||
@ -5,6 +5,7 @@
|
||||
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/base/version.dart';
|
||||
import 'package:flutter_tools/src/vscode/vscode.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
@ -55,11 +56,35 @@ void main() {
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{');
|
||||
|
||||
final VsCode vsCode = VsCode.fromDirectory('', '', fileSystem: fileSystem);
|
||||
final VsCode vsCode = VsCode.fromDirectory(
|
||||
'',
|
||||
'',
|
||||
fileSystem: fileSystem,
|
||||
platform: const LocalPlatform(),
|
||||
);
|
||||
|
||||
expect(vsCode.version, null);
|
||||
});
|
||||
|
||||
testWithoutContext('VsCode.fromDirectory finds packages.json on Linux', () {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/169812
|
||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||
// Installations on Linux appear to use $VSCODE_INSTALL/resources/app/package.json rather than
|
||||
// $VSCODE_INSTALL/Resources/app/package.json.
|
||||
fileSystem.file(fileSystem.path.join('', 'resources', 'app', 'package.json'))
|
||||
..createSync(recursive: true)
|
||||
..writeAsStringSync('{"version":"1.2.3"}');
|
||||
|
||||
final VsCode vsCode = VsCode.fromDirectory(
|
||||
'',
|
||||
'',
|
||||
fileSystem: fileSystem,
|
||||
platform: FakePlatform(),
|
||||
);
|
||||
|
||||
expect(vsCode.version, Version(1, 2, 3));
|
||||
});
|
||||
|
||||
testWithoutContext('can locate VS Code installed via Snap', () {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
const String home = '/home/me';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user