Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference libraries with @docImports #56528

Open
goderbauer opened this issue Aug 20, 2024 · 3 comments
Open

Reference libraries with @docImports #56528

goderbauer opened this issue Aug 20, 2024 · 3 comments
Labels
analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@goderbauer
Copy link
Contributor

Imagine we have a library as follows:

/// Long and extensive documentation about this library
library foo;

// Good stuff in this library.

I would now like to refer to that library comment from another file/package:

/// Bla bla bla.
///
/// The details are explained in the [foo] library.
void bar() {
  // ...
}

I would like to have [foo] link to the doc on the library foo;. Currently, this doesn't seem possible with docImports in a way that makes the comment_references lint happy.

@goderbauer
Copy link
Contributor Author

Real life example where flutter has these kind of library references in doc comments: https://github.com/flutter/flutter/blob/b79aabff265dce997152a4ec181337ccffe779ee/packages/flutter/lib/src/foundation/binding.dart#L57-L58

@dart-github-bot
Copy link
Collaborator

Summary: The user wants to link to the documentation of a library using @docImports but the comment_references lint prevents this. They propose using [foo] to link to the library's documentation, but this functionality is currently unavailable.

@dart-github-bot dart-github-bot added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-enhancement A request for a change that isn't a bug labels Aug 20, 2024
@srawlins srawlins added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-server P2 A bug or feature request we're likely to work on and removed area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 20, 2024
@srawlins
Copy link
Member

It's a bit unique because the name of the library (a la library foo;) is not anything that can be used or even referenced by code (as opposed to, say, an import prefix name). So there is no element, for example, that is provided by an import, or a shared namespace from one or more import prefixes, that represents the library. The named library is also becoming less popular, and I don't think it's a good idea to implement a feature that requires a name on a library directive.

I think the strategy we're likely going to go with is to allow you to reference a library as its import prefix. So that you could refer to foo with:

/// @docImport 'foo.dart' as foo;
library;

// OR:
import 'foo.dart' as foo;

/// Hello [foo].
var x = 0;

One shortcoming of this strategy is that import prefixes are not generally tied to a single import; they act as a shared namespace. I think it's not a huge shortcoming, as we can just report an "ambiguous element" warning if you try to reference [foo] and foo is a shared import or doc-import prefix. It might require an awkward or sub-optimal implementation, tying a prefix to the (singular) URI of the library that it's tied to. I'm open to other ideas.

@devoncarew devoncarew removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants