Skip to content

Commit

Permalink
Use DTD project roots instead of workspace roots for Deep links tool (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll committed Mar 26, 2024
1 parent 49db46d commit 0223a32
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import 'dart:async';

import 'package:devtools_app_shared/ui.dart';
import 'package:dtd/dtd.dart';
import 'package:flutter/material.dart';

import '../../shared/analytics/analytics.dart' as ga;
import '../../shared/analytics/constants.dart' as gac;
import '../../shared/directory_picker.dart';
import '../../shared/globals.dart';
import '../../shared/primitives/utils.dart';
import '../../shared/server/server.dart' as server;
import '../../shared/utils.dart';
import 'deep_links_controller.dart';
Expand All @@ -31,7 +31,7 @@ class _SelectProjectViewState extends State<SelectProjectView>
with ProvidedControllerMixin<DeepLinksController, SelectProjectView> {
bool _retrievingFlutterProject = false;

IDEWorkspaceRoots? workspaceRoots;
List<Uri>? projectRoots;

@override
void initState() {
Expand All @@ -40,13 +40,9 @@ class _SelectProjectViewState extends State<SelectProjectView>
}

Future<void> _initWorkspaceRoots() async {
// TODO(kenz): this does not work well for mono-repos. What we really need
// to do is add a DevTools server API that looks through the DevTools
// project roots and returns all subdirectories that contain a pubspec.yaml
// file (maybe with a Flutter dependency?).
final roots = await dtdManager.workspaceRoots();
final roots = await dtdManager.projectRoots();
setState(() {
workspaceRoots = roots;
projectRoots = roots?.uris;
});
}

Expand Down Expand Up @@ -127,10 +123,9 @@ class _SelectProjectViewState extends State<SelectProjectView>
style: Theme.of(context).textTheme.titleSmall,
),
),
if (workspaceRoots != null &&
workspaceRoots!.ideWorkspaceRoots.isNotEmpty) ...[
if (!projectRoots.isNullOrEmpty) ...[
ProjectRootsDropdown(
workspaceRoots: workspaceRoots!,
projectRoots: projectRoots!,
onValidatePressed: _handleValidateProject,
),
const SizedBox(height: largeSpacing),
Expand Down
12 changes: 5 additions & 7 deletions packages/devtools_app/lib/src/shared/directory_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'package:devtools_app_shared/ui.dart';
import 'package:devtools_app_shared/utils.dart';
import 'package:dtd/dtd.dart';
import 'package:flutter/material.dart';

import 'common_widgets.dart';
Expand Down Expand Up @@ -86,12 +85,12 @@ class _ProjectRootTextFieldState extends State<ProjectRootTextField>

class ProjectRootsDropdown extends StatefulWidget {
ProjectRootsDropdown({
required this.workspaceRoots,
required this.projectRoots,
required this.onValidatePressed,
super.key,
}) : assert(workspaceRoots.ideWorkspaceRoots.isNotEmpty);
}) : assert(projectRoots.isNotEmpty);

final IDEWorkspaceRoots workspaceRoots;
final List<Uri> projectRoots;

final void Function(String) onValidatePressed;

Expand All @@ -105,7 +104,7 @@ class _ProjectRootsDropdownState extends State<ProjectRootsDropdown> {
@override
void initState() {
super.initState();
selectedUri = widget.workspaceRoots.ideWorkspaceRoots.safeFirst;
selectedUri = widget.projectRoots.safeFirst;
}

@override
Expand All @@ -116,8 +115,7 @@ class _ProjectRootsDropdownState extends State<ProjectRootsDropdown> {
RoundedDropDownButton<Uri>(
value: selectedUri,
items: [
for (final uri in widget.workspaceRoots.ideWorkspaceRoots)
_buildMenuItem(uri),
for (final uri in widget.projectRoots) _buildMenuItem(uri),
],
onChanged: (uri) => setState(() {
selectedUri = uri;
Expand Down
7 changes: 7 additions & 0 deletions packages/devtools_app/lib/src/shared/primitives/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,13 @@ extension ListExtension<T> on List<T> {
}
}

extension NullableListExtension<T> on List<T>? {
bool get isNullOrEmpty {
final self = this;
return self == null || self.isEmpty;
}
}

extension SetExtension<T> on Set<T> {
bool containsWhere(bool Function(T element) test) {
for (var e in this) {
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
devtools_app_shared: ^0.1.0
devtools_extensions: ^0.0.10
devtools_shared: ^6.0.1
dtd: ^2.0.0
dtd: ^2.1.0
file: ">=6.0.0 <8.0.0"
file_selector: ^1.0.0
fixnum: ^1.1.0
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TODO: Remove this section if there are not any general updates.
## Deep Links tool updates

* Automatically populate a list of Flutter projects from the connected
IDE. - [#7415](https://github.com/flutter/devtools/pull/7415)
IDE. - [#7415](https://github.com/flutter/devtools/pull/7415), [#7431](https://github.com/flutter/devtools/pull/7431)

## App size tool updates

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ void main() {
final mockDtdManager = MockDTDManager();
final rootUri1 = Uri.parse('file:///Users/me/package_root_1');
final rootUri2 = Uri.parse('file:///Users/me/package_root_2');
when(mockDtdManager.workspaceRoots()).thenAnswer((_) async {
return IDEWorkspaceRoots(ideWorkspaceRoots: [rootUri1, rootUri2]);
when(mockDtdManager.projectRoots()).thenAnswer((_) async {
return UriList(uris: [rootUri1, rootUri2]);
});
setGlobal(DTDManager, mockDtdManager);
});
Expand Down
11 changes: 11 additions & 0 deletions packages/devtools_app/test/primitives/utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,17 @@ void main() {
});
});

group('NullableListExtension', () {
test('isNullOrEmpty', () {
List<int>? nullableList;
expect(nullableList.isNullOrEmpty, true);
nullableList = [];
expect(nullableList.isNullOrEmpty, true);
nullableList.add(1);
expect(nullableList.isNullOrEmpty, false);
});
});

group('SetExtension', () {
test('containsWhere', () {
final set = {1, 2, 3, 4};
Expand Down
5 changes: 5 additions & 0 deletions packages/devtools_app_shared/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.1-dev.0
* Update `package:dtd` to `^2.1.0`
* Add `DTDManager.projectRoots` method.

## 0.1.0
* Remove deprecated `background` and `onBackground` values for `lightColorScheme`
and `darkColorScheme`.
Expand All @@ -6,6 +10,7 @@ and `darkColorScheme`.
* Update readme to use `pub add` instead of explicit package version.
* Update `package:dtd` to `^2.0.0`
* Update `package:devtools_shared` to `^8.1.0`
* Add `DTDManager.workspaceRoots` method.

## 0.0.10
* Add `DTDManager` class and export from `service.dart`.
Expand Down
50 changes: 50 additions & 0 deletions packages/devtools_app_shared/lib/src/service/dtd_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,25 @@ class DTDManager {

_connection.value = null;
_uri = null;
_workspaceRoots = null;
_projectRoots = null;
}

/// Returns the workspace roots for the Dart Tooling Daemon connection.
///
/// These roots are set by the tool that started DTD, which may be the IDE,
/// DevTools server, or DDS (the Dart Development Service managed by the Dart
/// or Flutter CLI tools).
///
/// A workspace root is considered any directory that is at the root of the
/// IDE's open project or workspace, or in the case where the Dart Tooling
/// Daemon was started from the DevTools server or DDS (e.g. an app ran from
/// the CLI), a workspace root is the root directory for the Dart or Flutter
/// program connected to DevTools.
///
/// By default, the cached value [_workspaceRoots] will be returned when
/// available. When [forceRefresh] is true, the cached value will be cleared
/// and recomputed.
Future<IDEWorkspaceRoots?> workspaceRoots({bool forceRefresh = false}) async {
if (hasConnection) {
if (_workspaceRoots != null && forceRefresh) {
Expand All @@ -67,4 +84,37 @@ class DTDManager {
}

IDEWorkspaceRoots? _workspaceRoots;

/// Returns the project roots for the Dart Tooling Daemon connection.
///
/// A project root is any directory, contained within the current set of
/// [workspaceRoots], that contains a 'pubspec.yaml' file.
///
/// By default, the cached value [_projectRoots] will be returned when
/// available. When [forceRefresh] is true, the cached value will be cleared
/// and recomputed.
///
/// [depth] is the maximum depth that each workspace root directory tree will
/// will be searched for project roots. Setting [depth] to a large number
/// may have performance implications when traversing large trees.
Future<UriList?> projectRoots({
int? depth = defaultGetProjectRootsDepth,
bool forceRefresh = false,
}) async {
if (hasConnection) {
if (_projectRoots != null && forceRefresh) {
_projectRoots = null;
}
try {
return _projectRoots ??=
await _connection.value!.getProjectRoots(depth: depth!);
} catch (e) {
_log.fine('Error fetching project roots: $e');
return null;
}
}
return null;
}

UriList? _projectRoots;
}
4 changes: 2 additions & 2 deletions packages/devtools_app_shared/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: devtools_app_shared
description: Package of Dart & Flutter structures shared between devtools_app and devtools extensions.
version: 0.1.0
version: 0.1.1-dev.0
repository: https://github.com/flutter/devtools/tree/master/packages/devtools_app_shared

environment:
Expand All @@ -10,7 +10,7 @@ environment:
dependencies:
collection: ^1.15.0
devtools_shared: ^8.1.0
dtd: ^2.0.0
dtd: ^2.1.0
flutter:
sdk: flutter
logging: ^1.1.1
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_extensions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.1.1-wip
## 0.1.1-dev.0
* Update the simulated environment help dialogs with information about the
new `--print-dtd` CLI flag.

Expand Down
2 changes: 1 addition & 1 deletion packages/devtools_extensions/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: devtools_extensions
description: A package for building and supporting extensions for Dart DevTools.
version: 0.1.1-wip
version: 0.1.1-dev.0

repository: https://github.com/flutter/devtools/tree/master/packages/devtools_extensions

Expand Down
7 changes: 5 additions & 2 deletions packages/devtools_shared/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# 8.1.1-wip
* Update `package:dtd` to `2.1.0`.

# 8.1.0
* Update `package:dtd` to `2.0.0`
* Update `package:unified_analytics` to `5.8.8`
* Update `package:dtd` to `2.0.0`.
* Update `package:unified_analytics` to `5.8.8`.

# 8.0.1
* **Breaking change:** rename `ServerApi.getCompleted` to `ServerApi.success` and make the
Expand Down
4 changes: 2 additions & 2 deletions packages/devtools_shared/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: devtools_shared
description: Package of shared Dart structures between devtools_app, dds, and other tools.

version: 8.1.0
version: 8.1.1-wip

repository: https://github.com/flutter/devtools/tree/master/packages/devtools_shared

Expand All @@ -11,7 +11,7 @@ environment:
dependencies:
args: ^2.4.2
collection: ^1.15.0
dtd: ^2.0.0
dtd: ^2.1.0
extension_discovery: ^2.0.0
meta: ^1.9.1
path: ^1.8.0
Expand Down

0 comments on commit 0223a32

Please sign in to comment.