-
Notifications
You must be signed in to change notification settings - Fork 125
Add a hideConstantImplementations dartdoc directive #3398
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ac08d55
Some basic refactorings
jcollins-g 45315f8
This seems to work.
jcollins-g 52334e9
dev version, dart format
jcollins-g c19962b
rebuild clean
jcollins-g b1b56e5
rebuild at 40.0
jcollins-g 59de008
Add -dev to changelog
jcollins-g 182b67c
Update README to include documentation for the new directive
jcollins-g fb09cca
merge
jcollins-g a745090
review comments, fix reentrancy problem in grinder
jcollins-g db4a861
rebuild
jcollins-g 157dc4c
Allow for 20 libraries (new in dev)
jcollins-g 4e71705
fix nits
jcollins-g cf4f2ac
dartfmt
jcollins-g ca46067
clean up subprocess_launcher exception handling
jcollins-g 493fa2f
Merge branch 'main' into hide-implementations
jcollins-g 927dbdb
Temporarily forbid 1.24 test
jcollins-g 19a937c
that was a red herring
jcollins-g 400e038
last review comment
jcollins-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
dartdoc: | ||
linkToSource: | ||
root: '.' | ||
uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v6.2.2/%f%#L%l%' | ||
uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v6.2.2-dev/%f%#L%l%' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:dartdoc/src/model/documentation_comment.dart'; | ||
import 'package:dartdoc/src/model/library.dart'; | ||
|
||
final _canonicalRegExp = RegExp(r'{@canonicalFor\s([^}]+)}'); | ||
|
||
/// Used by [Library] to implement the `canonicalFor` directive. | ||
mixin CanonicalFor on DocumentationComment { | ||
Set<String>? _canonicalFor; | ||
|
||
Set<String> get canonicalFor { | ||
if (_canonicalFor == null) { | ||
buildDocumentationAddition(documentationComment); | ||
} | ||
return _canonicalFor!; | ||
} | ||
|
||
/// Hides `canonicalFor` from doc while leaving a note to ourselves to | ||
/// help with ambiguous canonicalization determination. | ||
/// | ||
/// Example: | ||
/// | ||
/// {@canonicalFor libname.ClassName} | ||
@override | ||
String buildDocumentationAddition(String rawDocs) { | ||
rawDocs = super.buildDocumentationAddition(rawDocs); | ||
var newCanonicalFor = <String>{}; | ||
rawDocs = rawDocs.replaceAllMapped(_canonicalRegExp, (Match match) { | ||
var elementName = match.group(1)!; | ||
newCanonicalFor.add(elementName); | ||
return ''; | ||
}); | ||
|
||
_canonicalFor = newCanonicalFor; | ||
return rawDocs; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,11 @@ final RegExp _categoryRegExp = RegExp( | |
r'[ ]*{@(api|category|subCategory|image|samples) (.+?)}[ ]*\n?', | ||
multiLine: true); | ||
|
||
/// Mixin implementing dartdoc categorization for ModelElements. | ||
mixin Categorization implements ModelElement { | ||
/// Mixin parsing the `@category` directive for ModelElements. | ||
mixin Categorization on DocumentationComment implements Indexable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice cleanup! |
||
@override | ||
String buildDocumentationAddition(String rawDocs) => | ||
_stripAndSetDartdocCategories(rawDocs); | ||
_stripAndSetDartdocCategories(super.buildDocumentationAddition(rawDocs)); | ||
|
||
/// Parse `{@category ...}` and related information in API comments, stripping | ||
/// out that information from the given comments and returning the stripped | ||
|
@@ -61,7 +61,6 @@ mixin Categorization implements ModelElement { | |
return _subCategoryNames; | ||
} | ||
|
||
@override | ||
bool get hasCategoryNames => categoryNames?.isNotEmpty ?? false; | ||
List<String>? _categoryNames; | ||
|
||
|
@@ -99,7 +98,6 @@ mixin Categorization implements ModelElement { | |
...?categoryNames?.map((n) => package.nameToCategory[n]).whereNotNull() | ||
]..sort(); | ||
|
||
@override | ||
Iterable<Category> get displayedCategories { | ||
if (config.showUndocumentedCategories) return categories; | ||
return categories.where((c) => c.isDocumented); | ||
|
41 changes: 41 additions & 0 deletions
41
lib/src/model/directives/hide_constant_implementations.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:dartdoc/src/model/documentation_comment.dart'; | ||
import 'package:dartdoc/src/model/model_element.dart'; | ||
|
||
final _hideConstantImplementationsRegExp = | ||
RegExp(r'{@hideConstantImplementations}'); | ||
|
||
/// Implement parsing the hideConstantImplementations dartdoc directive | ||
/// for this [ModelElement]. Used by [Container]. | ||
mixin HideConstantImplementations on DocumentationComment { | ||
bool? _hasHideConstantImplementations; | ||
|
||
/// [true] if the `{@hideConstantImplementations}` dartdoc directive is | ||
/// present in the documentation for this class. | ||
bool get hasHideConstantImplementations { | ||
if (_hasHideConstantImplementations == null) { | ||
buildDocumentationAddition(documentationComment); | ||
} | ||
return _hasHideConstantImplementations!; | ||
} | ||
|
||
/// Hides `{@hideConstantImplementations}` from doc while leaving a note to | ||
/// ourselves to change rendering for these constants. | ||
/// Example: | ||
/// | ||
/// {@hideConstantImplementations} | ||
@override | ||
String buildDocumentationAddition(String rawDocs) { | ||
srawlins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rawDocs = super.buildDocumentationAddition(rawDocs); | ||
_hasHideConstantImplementations = false; | ||
rawDocs = rawDocs.replaceAllMapped(_hideConstantImplementationsRegExp, | ||
(Match match) { | ||
_hasHideConstantImplementations = true; | ||
return ''; | ||
}); | ||
return rawDocs; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we're steering away from named libraries like this; we can use
library;
in Dart 2.19.