☂️ Documentation imports #56186
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
The original issue describing a new "documentation import" system is #50702, but it is a bit outdated, and has grown to be a pretty long issue. This issue serves as the new umbrella issue for the "documentation imports" feature.
BACKGROUND
Glossary
///
), and which is placed just before a library element (class, top-level function, top-level constant, etc.) or a class/mixin/enum/extension element (method, field, etc.). A doc comment is parsed (by various tools) as Markdown text.[List]
or[Future.wait]
.OVERVIEW
The basic design is to add a dartdoc-style doc comment directive, called a "doc-import" which looks similar to an
import
directive. When a library directive has a documentation comment with doc-imports, the analyzer will add another layer of resolution scope, used when resolving doc comment references. Quick examples:DETAILED DESIGN/DISCUSSION
This feature is designed to be used only by static analysis tools like the Dart analyzer and dartdoc.
At the start of any line in a documentation comment on a library's
library
directive, a doc-import can be written. A doc-import looks exactly like a Dart import directive, with 3 differences:@docImport
instead ofimport
.deferred
keyword is not supported.Otherwise, all other features of Dart imports are supported, including package URIs, relative file URIs, prefixes with "as", and "show" and "hide" combinators.
Each identifier in a library (both in code and in doc comment references) is resolved according to various scoping rules, which may resolve to a non-top-level identifier, or a top-level identifier from one of the top-level namespaces. (This is a simplification since a prefix itself is an identifier which needs resolution, and which can also be shadowed by a non-top-level identifier.) The presence of one-or-more doc-imports introduces a new scope, applicable only within doc comments. This doc-imports scope introduces visible names using the same rules and mechanisms as Dart imports.
New static warnings are reported in the following situations:
TESTING PLAN
Support for this syntax will be tested in:
DOCUMENTATION PLAN
The support for this feature can be documented in an article on dart.dev.
This addresses #44637.
The text was updated successfully, but these errors were encountered: