Skip to content

Fix doc comment references that need prefixed doc imports - #193906

Merged
szakarias merged 12 commits into
flutter:masterfrom
szakarias:fix-library-doc-references
Oct 19, 2026
Merged

szakarias merged 12 commits into
flutter:masterfrom
szakarias:fix-library-doc-references

Conversation

@szakarias

Copy link
Copy Markdown
Contributor

Adds prefixed @docImport directives so that doc comment references that need a prefix resolve in Dart scope. This is possible now that https://dart-review.googlesource.com/c/sdk/+/557680 has rolled into Flutter.

  • 20 library references in packages/flutter, flutter_test, and integration_test, such as [widgets] and [flutter_test].
  • [ui.Rect], [ui.Size], and [flutter_test.expectLater] in dev/.

The generated API docs link these references the same as before.

Towards #192870 — enabling the comment_references lint.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Oct 6, 2026
@github-actions github-actions Bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: integration_test The flutter/packages/integration_test plugin labels Oct 6, 2026
@szakarias
szakarias requested a review from justinmc October 6, 2026 13:47

@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 adds several @DocImport statements across multiple files in the flutter and flutter_test packages to improve documentation imports. I have no feedback to provide.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

/// @docImport 'package:flutter/gestures.dart' as gestures;
/// @docImport 'package:flutter/rendering.dart';
/// @docImport 'package:flutter/scheduler.dart';
/// @docImport 'package:flutter/services.dart';

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.

services, widgets and flutter_test are now duplicated?

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.

Yes, it's a bit annoying. The prefixed import is needed for the library reference (e.g. [widgets]), and the existing plain import for unqualified references like [BuildContext]. To remove the duplication, we'd have to drop the plain import and qualify all those references, e.g. [widgets.BuildContext], and the prefix would then show up in the link text in the generated docs. This already happens with prefixed regular imports ([ui.Rect] renders as ui.Rect), and at some point we'd like to look into how dartdoc renders prefixed references. For now, it's a choice between duplicate imports and prefixed names in the docs, and I'm happy to go with whichever you prefer.

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.

That is indeed what I was expecting of it. I'm fine with cleaning that up later, so we can unblock enabling the lint first.

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.

I agree with @navaronbracke, this is fine for now. I expect that referencing the whole library (e.g. [widgets]) in the docs is not that common.

@navaronbracke

Copy link
Copy Markdown
Contributor

cc @chunhtai since you're trying to turn it on in #193958

@szakarias
szakarias enabled auto-merge October 8, 2026 13:14

@chunhtai chunhtai 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.

@navaronbracke

Copy link
Copy Markdown
Contributor

They do work on master, though:

linter:
   rules:
     - comment_references
/// @docImport 'dart:math' as math;
library;

void main() {}

/// Get foo without using [math.pi].
int fun() {
  return 42;
}
[✓] Flutter (Channel master, 3.49.0-1.0.pre-363, on macOS 26.6.2 25G83 darwin-arm64, locale en-US) [2.8s]
    • Flutter version 3.49.0-1.0.pre-363 on channel master at /Users/navaronbracke/Documents/flutter
    • Upstream repository [email protected]:navaronbracke/flutter.git
    • FLUTTER_GIT_URL = [email protected]:navaronbracke/flutter.git
    • Framework revision 9b57590434 (11 hours ago), 2026-10-08 06:30:06 +0000
    • Engine revision 86798946ad
    • Dart version 3.14.0 (build 3.14.0-309.0.dev)
    • DevTools version 2.61.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android,
      enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager,
      omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration, enable-riscv64, enable-hcpp

[!] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [1,787ms]
    • Android SDK at /Users/navaronbracke/Library/Android/sdk
    • Emulator version 36.4.9.0 (build_id 14788078) (CL:N/A)
    • Platform android-37.0, build-tools 36.1.0
    • ANDROID_HOME = /Users/navaronbracke/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.10+-117844308-b1163.108)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 27.0) [1,451ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 27A266a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [9ms]
    • CHROME_EXECUTABLE = /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (2 available) [6.7s]
    • macOS (desktop) • macos  • darwin-arm64   • macOS 26.6.2 25G83 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 154.0.8037.98

[✓] Network resources [247ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

@chunhtai

chunhtai commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

I am not sure if there may be some discrepancy between different system. looks like analyzer is ok with import with prefix, not sure if that applies to dart doc. let me double check with dev experience team to see whether this is ok

@chunhtai

chunhtai commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

oh nvm, it is supported now

@chunhtai chunhtai 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.

LGTM

szakarias added a commit to szakarias/flutter that referenced this pull request Oct 9, 2026
Rolls dartdoc from 9.0.9 to 9.0.11. Since analyzer 14.5.0, dartdoc 9.0.9
crashes on comment references through a prefixed doc import; 9.0.11
fixes that.

Needed before flutter#193906 can land. Towards flutter#192870.

@justinmc justinmc 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.

LGTM 👍 . I think it will be worth it to be able to enable comment_references!

/// @docImport 'package:flutter/gestures.dart' as gestures;
/// @docImport 'package:flutter/rendering.dart';
/// @docImport 'package:flutter/scheduler.dart';
/// @docImport 'package:flutter/services.dart';

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.

I agree with @navaronbracke, this is fine for now. I expect that referencing the whole library (e.g. [widgets]) in the docs is not that common.

@flutter-dashboard

Copy link
Copy Markdown

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #193906 at sha 59e56ed

@flutter-dashboard flutter-dashboard Bot added the will affect goldens Changes to golden files label Oct 19, 2026
@szakarias
szakarias added this pull request to the merge queue Oct 19, 2026
Merged via the queue into flutter:master with commit f2cf71a Oct 19, 2026
22 of 23 checks passed
@szakarias
szakarias deleted the fix-library-doc-references branch October 19, 2026 10:26
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
Rolls dartdoc from 9.0.9 to 9.0.11. Since analyzer 14.5.0, dartdoc 9.0.9
crashes on comment references through a prefixed doc import; 9.0.11
fixes that.

Needed before flutter#193906 can land. Towards flutter#192870.
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
…3906)

Adds prefixed `@docImport` directives so that doc comment references
that need a prefix resolve in Dart scope. This is possible now that
https://dart-review.googlesource.com/c/sdk/+/557680 has rolled into
Flutter.

- 20 library references in `packages/flutter`, `flutter_test`, and
`integration_test`, such as `[widgets]` and `[flutter_test]`.
- `[ui.Rect]`, `[ui.Size]`, and `[flutter_test.expectLater]` in `dev/`.

The generated API docs link these references the same as before.

Towards flutter#192870 — enabling the
`comment_references` lint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems CICD Run CI/CD f: integration_test The flutter/packages/integration_test plugin framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants