[flutter_tools/dap] Map org-dartlang-sdk URIs to the location of the source files found by the analyzer (#114369)
This commit is contained in:
parent
1f7bacff42
commit
307987339e
@ -19,7 +19,7 @@ import 'mixins.dart';
|
||||
|
||||
/// A DAP Debug Adapter for running and debugging Flutter applications.
|
||||
class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments, FlutterAttachRequestArguments>
|
||||
with PidTracker {
|
||||
with PidTracker, FlutterAdapter {
|
||||
FlutterDebugAdapter(
|
||||
super.channel, {
|
||||
required this.fileSystem,
|
||||
@ -30,14 +30,21 @@ class FlutterDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments
|
||||
super.logger,
|
||||
super.onError,
|
||||
}) : _enableDds = enableDds,
|
||||
flutterSdkRoot = Cache.flutterRoot!,
|
||||
// Always disable in the DAP layer as it's handled in the spawned
|
||||
// 'flutter' process.
|
||||
super(enableDds: false);
|
||||
super(enableDds: false) {
|
||||
configureOrgDartlangSdkMappings();
|
||||
}
|
||||
|
||||
@override
|
||||
FileSystem fileSystem;
|
||||
Platform platform;
|
||||
Process? _process;
|
||||
|
||||
@override
|
||||
final String flutterSdkRoot;
|
||||
|
||||
/// Whether DDS should be enabled in the Flutter process.
|
||||
///
|
||||
/// We never enable DDS in the DAP process for Flutter, so this value is not
|
||||
|
@ -19,7 +19,7 @@ import 'mixins.dart';
|
||||
|
||||
/// A DAP Debug Adapter for running and debugging Flutter tests.
|
||||
class FlutterTestDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArguments, FlutterAttachRequestArguments>
|
||||
with PidTracker, TestAdapter {
|
||||
with PidTracker, FlutterAdapter, TestAdapter {
|
||||
FlutterTestDebugAdapter(
|
||||
super.channel, {
|
||||
required this.fileSystem,
|
||||
@ -30,14 +30,21 @@ class FlutterTestDebugAdapter extends DartDebugAdapter<FlutterLaunchRequestArgum
|
||||
super.logger,
|
||||
super.onError,
|
||||
}) : _enableDds = enableDds,
|
||||
flutterSdkRoot = Cache.flutterRoot!,
|
||||
// Always disable in the DAP layer as it's handled in the spawned
|
||||
// 'flutter' process.
|
||||
super(enableDds: false);
|
||||
super(enableDds: false) {
|
||||
configureOrgDartlangSdkMappings();
|
||||
}
|
||||
|
||||
@override
|
||||
FileSystem fileSystem;
|
||||
Platform platform;
|
||||
Process? _process;
|
||||
|
||||
@override
|
||||
final String flutterSdkRoot;
|
||||
|
||||
/// Whether DDS should be enabled in the Flutter process.
|
||||
///
|
||||
/// We never enable DDS in the DAP process for Flutter, so this value is not
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
|
||||
/// A mixin for tracking additional PIDs that can be shut down at the end of a debug session.
|
||||
@ -22,3 +23,38 @@ mixin PidTracker {
|
||||
pidsToTerminate.forEach(signal.send);
|
||||
}
|
||||
}
|
||||
|
||||
mixin FlutterAdapter {
|
||||
Map<String, Uri> get orgDartlangSdkMappings;
|
||||
String get flutterSdkRoot;
|
||||
FileSystem get fileSystem;
|
||||
|
||||
void configureOrgDartlangSdkMappings() {
|
||||
/// When a user navigates into 'dart:xxx' sources in their editor (via the
|
||||
/// analysis server) they will land in flutter_sdk/bin/cache/pkg/sky_engine.
|
||||
///
|
||||
/// The running VM knows nothing about these paths and will resolve these
|
||||
/// libraries to 'org-dartlang-sdk://' URIs. We need to map between these
|
||||
/// to ensure that if a user puts a breakpoint inside sky_engine the VM can
|
||||
/// apply it to the correct place and once hit, we can navigate the user
|
||||
/// back to the correct file on their disk.
|
||||
///
|
||||
/// The mapping is handled by the base adapter but we need to override the
|
||||
/// paths to match the layout used by Flutter.
|
||||
///
|
||||
/// In future this might become unnecessary if
|
||||
/// https://github.com/dart-lang/sdk/issues/48435 is implemented. Until
|
||||
/// then, providing these mappings improves the debugging experience.
|
||||
|
||||
// Clear original Dart SDK mappings because they're not valid here.
|
||||
orgDartlangSdkMappings.clear();
|
||||
|
||||
// 'dart:ui' maps to /flutter/lib/ui
|
||||
final String flutterRoot = fileSystem.path.join(flutterSdkRoot, 'bin', 'cache', 'pkg', 'sky_engine', 'lib', 'ui');
|
||||
orgDartlangSdkMappings[flutterRoot] = Uri.parse('org-dartlang-sdk:///flutter/lib/ui');
|
||||
|
||||
// The rest of the Dart SDK maps to /third_party/dart/sdk
|
||||
final String dartRoot = fileSystem.path.join(flutterSdkRoot, 'bin', 'cache', 'pkg', 'sky_engine');
|
||||
orgDartlangSdkMappings[dartRoot] = Uri.parse('org-dartlang-sdk:///third_party/dart/sdk');
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,10 @@ import 'dart:async';
|
||||
|
||||
import 'package:dds/dap.dart';
|
||||
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/cache.dart';
|
||||
import 'package:flutter_tools/src/debug_adapters/flutter_adapter.dart';
|
||||
import 'package:flutter_tools/src/debug_adapters/flutter_adapter_args.dart';
|
||||
import 'package:flutter_tools/src/globals.dart' as globals show platform;
|
||||
import 'package:test/fake.dart';
|
||||
@ -20,6 +22,9 @@ void main() {
|
||||
// Use the real platform as a base so that Windows bots test paths.
|
||||
final FakePlatform platform = FakePlatform.fromPlatform(globals.platform);
|
||||
final FileSystemStyle fsStyle = platform.isWindows ? FileSystemStyle.windows : FileSystemStyle.posix;
|
||||
final String flutterRoot = platform.isWindows
|
||||
? r'C:\fake\flutter'
|
||||
: '/fake/flutter';
|
||||
|
||||
group('flutter adapter', () {
|
||||
final String expectedFlutterExecutable = platform.isWindows
|
||||
@ -27,9 +32,7 @@ void main() {
|
||||
: '/fake/flutter/bin/flutter';
|
||||
|
||||
setUpAll(() {
|
||||
Cache.flutterRoot = platform.isWindows
|
||||
? r'C:\fake\flutter'
|
||||
: '/fake/flutter';
|
||||
Cache.flutterRoot = flutterRoot;
|
||||
});
|
||||
|
||||
group('launchRequest', () {
|
||||
@ -314,6 +317,46 @@ void main() {
|
||||
expect(adapter.processArgs, contains('tool_arg'));
|
||||
});
|
||||
|
||||
group('maps org-dartlang-sdk paths', () {
|
||||
late FileSystem fs;
|
||||
late FlutterDebugAdapter adapter;
|
||||
setUp(() {
|
||||
fs = MemoryFileSystem.test(style: fsStyle);
|
||||
adapter = MockFlutterDebugAdapter(
|
||||
fileSystem: fs,
|
||||
platform: platform,
|
||||
);
|
||||
});
|
||||
|
||||
test('dart:ui URI to file path', () async {
|
||||
expect(
|
||||
adapter.convertOrgDartlangSdkToPath(Uri.parse('org-dartlang-sdk:///flutter/lib/ui/ui.dart')),
|
||||
fs.path.join(flutterRoot, 'bin', 'cache', 'pkg', 'sky_engine', 'lib', 'ui', 'ui.dart'),
|
||||
);
|
||||
});
|
||||
|
||||
test('dart:ui file path to URI', () async {
|
||||
expect(
|
||||
adapter.convertPathToOrgDartlangSdk(fs.path.join(flutterRoot, 'bin', 'cache', 'pkg', 'sky_engine', 'lib', 'ui', 'ui.dart')),
|
||||
Uri.parse('org-dartlang-sdk:///flutter/lib/ui/ui.dart'),
|
||||
);
|
||||
});
|
||||
|
||||
test('dart:core URI to file path', () async {
|
||||
expect(
|
||||
adapter.convertOrgDartlangSdkToPath(Uri.parse('org-dartlang-sdk:///third_party/dart/sdk/lib/core/core.dart')),
|
||||
fs.path.join(flutterRoot, 'bin', 'cache', 'pkg', 'sky_engine', 'lib', 'core', 'core.dart'),
|
||||
);
|
||||
});
|
||||
|
||||
test('dart:core file path to URI', () async {
|
||||
expect(
|
||||
adapter.convertPathToOrgDartlangSdk(fs.path.join(flutterRoot, 'bin', 'cache', 'pkg', 'sky_engine', 'lib', 'core', 'core.dart')),
|
||||
Uri.parse('org-dartlang-sdk:///third_party/dart/sdk/lib/core/core.dart'),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('includes customTool', () {
|
||||
test('with no args replaced', () async {
|
||||
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(
|
||||
|
Loading…
x
Reference in New Issue
Block a user