-
Notifications
You must be signed in to change notification settings - Fork 127
Canonicalization overhaul #1368
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
Changes from 40 commits
47966ee
3bc180e
3016e8b
a7a9ce6
6154a18
687cf72
5c03e6d
531a559
add09d1
692b727
9d4ebf9
ab1da77
ed7af68
c9dc37f
a8e7a18
8a80a18
8edf848
aecb075
34b0645
06f65ba
da0b42a
55b6c8a
8cb927e
88a5bc2
167bffd
1a5c085
91bfdbe
f31199a
c3b1ee9
189b069
738dce3
0784d76
46c9f04
5b53b58
f8898f3
22da575
c79c0e7
6cdf4f6
4179bf9
849a3ec
3d0ee6e
edd9f07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ export 'src/package_meta.dart'; | |
|
||
const String name = 'dartdoc'; | ||
// Update when pubspec version changes. | ||
const String version = '0.9.13'; | ||
const String version = '0.10.0'; | ||
|
||
final String defaultOutDir = path.join('doc', 'api'); | ||
|
||
|
@@ -134,6 +134,7 @@ class DartDoc { | |
? const [] | ||
: findFilesToDocumentInPackage(rootDir.path).toList(); | ||
|
||
// TODO(jcollins-g): seems like most of this belongs in the Package constructor | ||
List<LibraryElement> libraries = _parseLibraries(files, includeExternals); | ||
|
||
if (includes != null && includes.isNotEmpty) { | ||
|
@@ -154,21 +155,27 @@ class DartDoc { | |
}); | ||
} | ||
|
||
if (includes.isNotEmpty || excludes.isNotEmpty) { | ||
print('generating docs for libraries ${libraries.join(', ')}\n'); | ||
} | ||
|
||
Package package = new Package(libraries, packageMeta); | ||
|
||
Package package; | ||
if (config != null && config.autoIncludeDependencies) { | ||
final newLibraryElements = | ||
_buildLibrariesWithAutoincludedDependencies(package); | ||
Library.clearLibraryMap(); | ||
package = new Package(newLibraryElements, packageMeta); | ||
package = Package.withAutoIncludedDependencies(libraries, packageMeta); | ||
libraries = package.libraries.map((l) => l.element).toList(); | ||
// remove excluded libraries again, in case they are picked up through | ||
// dependencies. | ||
excludes.forEach((pattern) { | ||
libraries.removeWhere((lib) { | ||
return lib.name.startsWith(pattern) || lib.name == pattern; | ||
}); | ||
}); | ||
} | ||
package = new Package(libraries, packageMeta); | ||
|
||
print( | ||
'generating docs for libraries ${package.libraries.map((Library l) => l.name).join(', ')}\n'); | ||
|
||
// Go through docs of every model element in package to prebuild the macros index | ||
package.allModelElements.forEach((m) => m.documentation); | ||
// TODO(jcollins-g): move index building into a cached-on-demand generation | ||
// like most other bits in [Package]. | ||
package.allCanonicalModelElements.forEach((m) => m.documentation); | ||
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. Eliminates repeats? Were we looking at documentation for elements that were not documented? 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. Right. |
||
|
||
// Create the out directory. | ||
if (!outputDir.existsSync()) outputDir.createSync(recursive: true); | ||
|
@@ -179,11 +186,11 @@ class DartDoc { | |
|
||
double seconds = _stopwatch.elapsedMilliseconds / 1000.0; | ||
print( | ||
"\nDocumented ${libraries.length} librar${libraries.length == 1 ? 'y' : 'ies'} " | ||
"\nDocumented ${package.libraries.length} librar${package.libraries.length == 1 ? 'y' : 'ies'} " | ||
"in ${seconds.toStringAsFixed(1)} seconds."); | ||
|
||
if (libraries.isEmpty) { | ||
print( | ||
if (package.libraries.isEmpty) { | ||
stderr.write( | ||
"\ndartdoc could not find any libraries to document. Run `pub get` and try again."); | ||
} | ||
|
||
|
@@ -192,7 +199,7 @@ class DartDoc { | |
|
||
List<LibraryElement> _parseLibraries( | ||
List<String> files, List<String> includeExternals) { | ||
List<LibraryElement> libraries = []; | ||
Set<LibraryElement> libraries = new Set(); | ||
DartSdk sdk = new FolderBasedDartSdk(PhysicalResourceProvider.INSTANCE, | ||
PhysicalResourceProvider.INSTANCE.getFolder(sdkDir.path)); | ||
List<UriResolver> resolvers = []; | ||
|
@@ -257,7 +264,7 @@ class DartDoc { | |
sources.add(source); | ||
if (context.computeKindOf(source) == SourceKind.LIBRARY) { | ||
LibraryElement library = context.computeLibraryElement(source); | ||
libraries.add(library); | ||
if (!isPrivate(library)) libraries.add(library); | ||
} | ||
} | ||
|
||
|
@@ -279,13 +286,40 @@ class DartDoc { | |
// Use the includeExternals. | ||
for (Source source in context.librarySources) { | ||
LibraryElement library = context.computeLibraryElement(source); | ||
if (library == null) { | ||
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. Are you seeing use cases when the analyzer returns null for LibraryElement . Pretty sure it should not do so. Could you check with @bwilkerson on this? 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. Poked at this and I'm pretty sure this was an intermediate debugging step that got forgotten. Ran through my cases without it and saw no issues. |
||
continue; | ||
} | ||
String libraryName = Library.getLibraryName(library); | ||
var fullPath = source.fullName; | ||
|
||
if (includeExternals.any((string) => fullPath.endsWith(string))) { | ||
if (libraries.map(Library.getLibraryName).contains(libraryName)) { | ||
continue; | ||
} | ||
libraries.add(library); | ||
} else if (config != null && | ||
config.autoIncludeDependencies && | ||
libraryName != '') { | ||
File searchFile = new File(fullPath); | ||
searchFile = | ||
new File(path.join(searchFile.parent.path, 'pubspec.yaml')); | ||
bool foundLibSrc = false; | ||
while (!foundLibSrc && searchFile.parent != null) { | ||
if (searchFile.existsSync()) break; | ||
List<String> pathParts = path.split(searchFile.parent.path); | ||
// This is a pretty intensely hardcoded convention, but there seems to | ||
// to be no other way to identify what might be a "top level" library | ||
// here. If lib/src is in the path between the file and the pubspec, | ||
// assume that this is supposed to be private. | ||
if (pathParts.length < 2) break; | ||
pathParts = pathParts.sublist(pathParts.length - 2, pathParts.length); | ||
foundLibSrc = | ||
path.join(pathParts[0], pathParts[1]) == path.join('lib', 'src'); | ||
searchFile = new File( | ||
path.join(searchFile.parent.parent.path, 'pubspec.yaml')); | ||
} | ||
if (foundLibSrc) continue; | ||
libraries.add(library); | ||
} | ||
} | ||
|
||
|
@@ -376,26 +410,3 @@ class _Error implements Comparable<_Error> { | |
@override | ||
String toString() => '[${severityName}] ${description}'; | ||
} | ||
|
||
Iterable<LibraryElement> _buildLibrariesWithAutoincludedDependencies( | ||
Package package) { | ||
final List<LibraryElement> newLibraryElements = [] | ||
..addAll(package.libraries.map((l) => l.element as LibraryElement)); | ||
|
||
package.allModelElements.forEach((modelElement) { | ||
modelElement.usedElements.forEach((used) { | ||
if (used != null && used.modelType != null) { | ||
final ModelElement modelTypeElement = used.modelType.element; | ||
final library = package.findLibraryFor(modelTypeElement.element); | ||
if (library == null && modelTypeElement.library != null) { | ||
if (!newLibraryElements.contains(modelTypeElement.library.element) && | ||
!modelTypeElement.library.name.startsWith("dart:")) { | ||
newLibraryElements.add(modelTypeElement.library.element); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
return newLibraryElements; | ||
} |
This file was deleted.
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.
+1 to using stderr here
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.
👍