Skip to content

[ Widget Preview ] Use analysis server for widget preview detection - #184473

Merged
auto-submit[bot] merged 4 commits into
flutter:masterfrom
bkonyi:widget_preview_analysis_server_implementation
Apr 2, 2026
Merged

auto-submit[bot] merged 4 commits into
flutter:masterfrom
bkonyi:widget_preview_analysis_server_implementation

Conversation

@bkonyi

@bkonyi bkonyi commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

This change ports the flutter widget-preview start command to utilize the Dart Analysis Server to detect widget previews in projects. When launched from an IDE, the widget previewer will use the existing DAS and DTD instances, greatly reducing the amount of memory consumed by the widget previewer.

A --legacy-preview-detection flag has also been added to fall back to the previous in-process preview detection logic. This flag will be removed in a future release once the DAS implementation is proven to be stable.

Fixes #179584

This change ports the `flutter widget-preview start` command to utilize
the Dart Analysis Server to detect widget previews in projects. When
launched from an IDE, the widget previewer will use the existing DAS
and DTD instances, greatly reducing the amount of memory consumed by the
widget previewer.

A `--legacy-preview-detection` flag has also been added to fall back to
the previous in-process preview detection logic. This flag will be
removed in a future release once the DAS implementation is proven to be
stable.

Fixes flutter#179584
@bkonyi bkonyi added the CICD Run CI/CD label Apr 1, 2026
@bkonyi
bkonyi requested a review from jyameo April 1, 2026 18:30
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 1, 2026

/// The set of widget previews defined in a script of an analyzed Flutter
/// project.
class FlutterWidgetPreviews {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces LSP-based preview detection for the widget previewer, allowing it to leverage the analysis server for more robust preview discovery. Key changes include the addition of LspPreviewDetector and FlutterWidgetPreviews data structures, updates to WidgetPreviewStartCommand to support both legacy and LSP-based detection modes, and the addition of necessary DTD service methods. Several improvements were suggested to ensure data consistency, null safety, and adherence to Dart best practices for class definitions.

Comment thread packages/flutter_tools/lib/src/widget_preview/dtd_types.dart
Comment thread packages/flutter_tools/lib/src/widget_preview/dtd_types.dart Outdated
Comment thread packages/flutter_tools/lib/src/widget_preview/dtd_types.dart Outdated
Comment thread packages/flutter_tools/lib/src/widget_preview/dtd_types.dart Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Apr 1, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Apr 1, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Apr 1, 2026

@jyameo jyameo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall lgtm!

);
}
_imports.addAll({
for (final MapEntry(:key, :value) in imports.entries) key: int.parse(value.substring(2)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it might safer to use tryParse or a check to avoid throwing an exception if value doesn't follow the expected format for some reason.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I'd agree, but in this situation I think it's better to throw an exception so we can get a signal that the analyzer is returning a poorly formatted response since this should always be an integer.

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 2, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Apr 2, 2026
Merged via the queue into flutter:master with commit 02f8ea2 Apr 2, 2026
153 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 2, 2026
@bkonyi
bkonyi deleted the widget_preview_analysis_server_implementation branch April 2, 2026 19:19
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 3, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Apr 3, 2026
flutter/flutter@0f401ee...7245c3f

2026-04-03 [email protected] Roll Skia from c07c67045b6d to 5d847ba5c4aa (1 revision) (flutter/flutter#184570)
2026-04-03 [email protected] Roll Dart SDK from 3c7a79045b8b to 46f49142acd9 (1 revision) (flutter/flutter#184567)
2026-04-03 [email protected] Roll ICU from ee5f27adc28b to ff7995a708a1 (5 revisions) (flutter/flutter#184566)
2026-04-03 [email protected] Roll Skia from 9ae8231be181 to c07c67045b6d (4 revisions) (flutter/flutter#184562)
2026-04-03 [email protected] Roll Fuchsia Linux SDK from BFLjk6Uwd0gs_Hkdk... to PpL3Bn2YMb2h9LbdK... (flutter/flutter#184556)
2026-04-03 [email protected] Roll Skia from 0566b2f5f0d1 to 9ae8231be181 (1 revision) (flutter/flutter#184547)
2026-04-03 [email protected] Roll Dart SDK from 6008eaddd589 to 3c7a79045b8b (3 revisions) (flutter/flutter#184551)
2026-04-03 [email protected] Fix wide gamut macos integration test (flutter/flutter#184427)
2026-04-02 [email protected] forward an application name to DDS (flutter/flutter#184459)
2026-04-02 [email protected] Roll Skia from 973117cfa875 to 0566b2f5f0d1 (8 revisions) (flutter/flutter#184534)
2026-04-02 [email protected] Support different joins for stroked rects in uber_sdf, fix incorrect aa (flutter/flutter#184395)
2026-04-02 [email protected] [ Widget Preview ] Handle collections and records in custom preview annotations (flutter/flutter#184518)
2026-04-02 [email protected] Moves android_semantics_integration_test out of staging (flutter/flutter#184079)
2026-04-02 [email protected] Roll Packages from b3fcf14 to 66bf7ec (4 revisions) (flutter/flutter#184514)
2026-04-02 [email protected] Fix line breaks being lost when copying after selection gesture in SelectableRegion (flutter/flutter#184421)
2026-04-02 [email protected] Add plugin version to SwiftPM package symlink directory (flutter/flutter#183668)
2026-04-02 [email protected] Add our own wrapper for `CommonExtension` due to change in signature from 8.x->9.0 (flutter/flutter#184433)
2026-04-02 [email protected] [Android] Use EdgeToEdge.enable/WindowCompat for edge-to-edge mode instead of deprecated View flags (flutter/flutter#183072)
2026-04-02 [email protected] [data_assets] Cleanup tests (flutter/flutter#184209)
2026-04-02 [email protected] Enable SPM by default on Stable (flutter/flutter#184495)
2026-04-02 [email protected] Roll Dart SDK from d84bdfeb45eb to 6008eaddd589 (2 revisions) (flutter/flutter#184513)
2026-04-02 [email protected] Reland "Even more awaits" (flutter/flutter#184467)
2026-04-02 [email protected] Roll Skia from bb9fd8653739 to 973117cfa875 (2 revisions) (flutter/flutter#184498)
2026-04-02 [email protected] [ Widget Preview ] Use analysis server for widget preview detection (flutter/flutter#184473)
2026-04-02 [email protected] [web_ui] Fix avoid_type_to_string lint violation (flutter/flutter#184342)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
mbcorona pushed a commit to mbcorona/flutter that referenced this pull request Apr 15, 2026
…lutter#184473)

This change ports the `flutter widget-preview start` command to utilize
the Dart Analysis Server to detect widget previews in projects. When
launched from an IDE, the widget previewer will use the existing DAS and
DTD instances, greatly reducing the amount of memory consumed by the
widget previewer.

A `--legacy-preview-detection` flag has also been added to fall back to
the previous in-process preview detection logic. This flag will be
removed in a future release once the DAS implementation is proven to be
stable.

Fixes flutter#179584
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11427)

flutter/flutter@0f401ee...7245c3f

2026-04-03 [email protected] Roll Skia from c07c67045b6d to 5d847ba5c4aa (1 revision) (flutter/flutter#184570)
2026-04-03 [email protected] Roll Dart SDK from 3c7a79045b8b to 46f49142acd9 (1 revision) (flutter/flutter#184567)
2026-04-03 [email protected] Roll ICU from ee5f27adc28b to ff7995a708a1 (5 revisions) (flutter/flutter#184566)
2026-04-03 [email protected] Roll Skia from 9ae8231be181 to c07c67045b6d (4 revisions) (flutter/flutter#184562)
2026-04-03 [email protected] Roll Fuchsia Linux SDK from BFLjk6Uwd0gs_Hkdk... to PpL3Bn2YMb2h9LbdK... (flutter/flutter#184556)
2026-04-03 [email protected] Roll Skia from 0566b2f5f0d1 to 9ae8231be181 (1 revision) (flutter/flutter#184547)
2026-04-03 [email protected] Roll Dart SDK from 6008eaddd589 to 3c7a79045b8b (3 revisions) (flutter/flutter#184551)
2026-04-03 [email protected] Fix wide gamut macos integration test (flutter/flutter#184427)
2026-04-02 [email protected] forward an application name to DDS (flutter/flutter#184459)
2026-04-02 [email protected] Roll Skia from 973117cfa875 to 0566b2f5f0d1 (8 revisions) (flutter/flutter#184534)
2026-04-02 [email protected] Support different joins for stroked rects in uber_sdf, fix incorrect aa (flutter/flutter#184395)
2026-04-02 [email protected] [ Widget Preview ] Handle collections and records in custom preview annotations (flutter/flutter#184518)
2026-04-02 [email protected] Moves android_semantics_integration_test out of staging (flutter/flutter#184079)
2026-04-02 [email protected] Roll Packages from b3fcf14 to 66bf7ec (4 revisions) (flutter/flutter#184514)
2026-04-02 [email protected] Fix line breaks being lost when copying after selection gesture in SelectableRegion (flutter/flutter#184421)
2026-04-02 [email protected] Add plugin version to SwiftPM package symlink directory (flutter/flutter#183668)
2026-04-02 [email protected] Add our own wrapper for `CommonExtension` due to change in signature from 8.x->9.0 (flutter/flutter#184433)
2026-04-02 [email protected] [Android] Use EdgeToEdge.enable/WindowCompat for edge-to-edge mode instead of deprecated View flags (flutter/flutter#183072)
2026-04-02 [email protected] [data_assets] Cleanup tests (flutter/flutter#184209)
2026-04-02 [email protected] Enable SPM by default on Stable (flutter/flutter#184495)
2026-04-02 [email protected] Roll Dart SDK from d84bdfeb45eb to 6008eaddd589 (2 revisions) (flutter/flutter#184513)
2026-04-02 [email protected] Reland "Even more awaits" (flutter/flutter#184467)
2026-04-02 [email protected] Roll Skia from bb9fd8653739 to 973117cfa875 (2 revisions) (flutter/flutter#184498)
2026-04-02 [email protected] [ Widget Preview ] Use analysis server for widget preview detection (flutter/flutter#184473)
2026-04-02 [email protected] [web_ui] Fix avoid_type_to_string lint violation (flutter/flutter#184342)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
pull Bot pushed a commit to g-star1024/flutter that referenced this pull request Sep 1, 2026
…etector (flutter#192120)

In Flutter 3.44
([flutter#184473](flutter#184473)),
`LspPreviewDetector` became the default preview detector, but did not
instrument `previewAnalytics.startPreviewReloadStopwatch()` or
`previewAnalytics.reportPreviewReloadTiming()`. This caused a severe
drop in reported `preview-reload-time` telemetry events.

This change instruments `LspPreviewDetector` to start the reload
stopwatch on file changes, report reload timings after change detection
completes, and reset the stopwatch on errors. Non-Dart file edits are
also filtered out to avoid unnecessary reload events.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
auto-submit Bot pushed a commit that referenced this pull request Sep 9, 2026
…pPreviewDetector (#192256)

This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

### Issue Link:
#192120

### Impact Description:
In Flutter 3.44 ([#184473](#184473)), `LspPreviewDetector` became the default preview detector, but did not instrument preview reload timing analytics (`previewAnalytics.startPreviewReloadStopwatch()` and `previewAnalytics.reportPreviewReloadTiming()`). This caused a severe drop in reported `preview-reload-time` telemetry events for the widget previewer. This cherry-pick restores reporting of reload timing metrics and filters out non-Dart file edits to avoid spurious reload timing events.

### Changelog Description:
[flutter/192120] Fixes missing preview reload timing analytics in LspPreviewDetector across all platforms.

### Workaround:
None. Telemetry for widget preview reload timing is omitted unless instrumented.

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
Run `packages/flutter_tools` unit tests:
`dart test test/commands.shard/hermetic/widget_preview/lsp_preview_detector_test.dart`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Process dart:flutter_tools.snapshot and dart:frontend_server_aot.dart.snapshot consumes huge memory on macOS when flutter run even has stopped

2 participants