[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:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user