Skip to content

Canonicalization overhaul part two #1390

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 12 commits into from
May 4, 2017
Merged

Conversation

jcollins-g
Copy link
Contributor

@jcollins-g jcollins-g commented May 1, 2017

Welcome to the second part of the canonicalization overhaul begun in #1368. It's somewhat smaller and less fundamental.

The key elements are the rewrite of how comment references are handled (changes to _findRefElementInLibrary and its callers particularly) and the new hints to ModelElement.from and findCanonicalModelElementFor -- if you understand those, most of the remaining structural changes are understandable.

The link checker and warning enhancements are, in retrospect, somewhat orthogonal to the change, but were very much necessary to be able to corral all the consequences from canonicalization and insure they remain fixed.

More unit tests are on deck for some of the features and capabilities the code has now, but since the many new asserts and the new, better warnings make problems much more visible, regressions will be detectable in other ways. Given that and upcoming flutter deadlines, I wanted to get this out for review ASAP.

@@ -3,6 +3,7 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/dartdoc.iml" filepath="$PROJECT_DIR$/dartdoc.iml" />
<module fileurl="file://$PROJECT_DIR$/../mustache4dart/mustache4dart.iml" filepath="$PROJECT_DIR$/../mustache4dart/mustache4dart.iml" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to drop this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to just delete the whole file so I can have my own intellij settings. Is that a bad idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, feel free to delete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

CHANGELOG.md Outdated
* Upgrades to new Package.warn system.
* Fully integrated all scattered "warnings" and added new ones for the link checker.
* Allow for setting which warnings are errors in the library.
* Change location output to something IntelliJ can understand and link to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@jcollins-g
Copy link
Contributor Author

Travis failures are because for some reason the link checker allocates a tremendous amount of memory. I'll try to figure out why that is.

Copy link
Member

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice changes! I made one pass through.

You alluded to this in your PR comments, but some of the changes here - the warnings overhaul for example - could have been handled in separate, smaller PRs before this one. That would make for happier reviewers - it's hard to meaningfully review PRs of this size.

I note that the flutter bot is failing on this PR; do you know why?

Travis failures are because for some reason the link checker allocates a tremendous amount of memory. I'll try to figure out why that is.

Nevermind, looks like our comments crossed.


* Many cleanups to dartdoc stdout/stderr, error messages, and warnings:
* Display fatal errors with 'fatal error' string to distinguish them from ordinary errors
* Upgrades to new Package.warn system.
Copy link
Member

@devoncarew devoncarew May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Food for thought for later - Dart now has good support for detecting when a console supports ansi. There are some very lightweight libraries for colorizing console output and showing indeterminate progress. We may want to use ansi colors when writing warnings and errors.

https://github.com/google/tuneup.dart/blob/master/lib/src/ansi.dart

https://github.com/google/tuneup.dart/blob/master/lib/src/logger.dart#L92

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I was wondering about that.

lib/dartdoc.dart Outdated
@@ -167,21 +185,170 @@ class DartDoc {

for (var generator in generators) {
await generator.generate(package, outputDir);
generator.writtenFiles
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps slightly clearer as writtenFiles.addAll(generator.writtenFiles.map(path.normalize))?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

lib/dartdoc.dart Outdated
String staticAssets = path.joinAll([normalOrigin, 'static-assets', '']);
String indexJson = path.joinAll([normalOrigin, 'index.json']);
bool foundIndex = false;
await for (FileSystemEntity f
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a bit simpler to use listSync()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could then remove the async from _doOrphanCheck.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And - not necessarily for this PR - it would be interesting to add the lint that checks that you're only awaiting Futures. It should then fire when you make _doOrphanCheck sync, on the await in verifyLinks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Went with listSync and removed async where appropriate.

lib/dartdoc.dart Outdated
fullPath = path.normalize(fullPath);
}

File file = new File("$fullPath");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new File(fullPath)?

lib/dartdoc.dart Outdated
if (!file.existsSync()) {
_warn(package, PackageWarning.brokenLink, pathToCheck,
path.normalize(origin),
source: source);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may auto-format slightly nicer if you add a trailing comma after source.

@@ -828,7 +879,7 @@ class Constructor extends ModelElement
String constructorName = element.name;
Class c = new ModelElement.from(element.enclosingElement, library) as Class;
if (constructorName.isEmpty) {
return c.name;
return '${c.name}';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is name a String? This isn't necessary, unless you don't want to return null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no need for this here, there were intermediate changes I had that renamed all constructors to "ClassName.ConstructorName", even defaults. Fixed.

}

String get arrow {
if (readOnly) return r'&#8594;';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could have the actual char in a line comment to help readers (// →).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

class Package implements Nameable, Documentable {
/// Provides description text and command line flags for warnings.
/// TODO(jcollins-g): Actually use this for command line flags.
Map<PackageWarning, List<String>> packageWarningText = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool! Nice to have a centralized structure for the errors we emit.

PackageWarningOptions() {
_asWarnings.addAll(PackageWarning.values);
ignore(PackageWarning.typeAsHtml);
//error(PackageWarning.brokenLink);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

'dartdoc detected an unknown file in the doc tree: ${message}';
break;
case PackageWarning.typeAsHtml:
warningMessage = 'generic type handled as HTML: """${message}"""';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so many quotes? A single " should work here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it visually indistinct when the sample message often contained quotes and so on for this warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added clarifying comment, but it turned out that the symbols typically involved in the message string made it visually indistinct to use single quotes.

@jcollins-g
Copy link
Contributor Author

Yes. I actually tried to avoid fixing the warnings while fixing the broken links, but incrementally I found it impossible to correct the broken links without doing so, so the two wound up happening together. Same with the link checker.

I expect there to be a finite, small number of these giant PRs. I think the code is improved enough now that future PRs will not be wide ranging; a goal here is to make it less structurally necessary to touch quite so much just to fix something like #1391.

@@ -3,6 +3,7 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/dartdoc.iml" filepath="$PROJECT_DIR$/dartdoc.iml" />
<module fileurl="file://$PROJECT_DIR$/../mustache4dart/mustache4dart.iml" filepath="$PROJECT_DIR$/../mustache4dart/mustache4dart.iml" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


* Many cleanups to dartdoc stdout/stderr, error messages, and warnings:
* Display fatal errors with 'fatal error' string to distinguish them from ordinary errors
* Upgrades to new Package.warn system.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I was wondering about that.

lib/dartdoc.dart Outdated
@@ -167,21 +185,170 @@ class DartDoc {

for (var generator in generators) {
await generator.generate(package, outputDir);
generator.writtenFiles
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

lib/dartdoc.dart Outdated
String staticAssets = path.joinAll([normalOrigin, 'static-assets', '']);
String indexJson = path.joinAll([normalOrigin, 'index.json']);
bool foundIndex = false;
await for (FileSystemEntity f
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Went with listSync and removed async where appropriate.

lib/dartdoc.dart Outdated
_hrefs = package.allHrefs;

Set<String> visited = new Set();
String start = 'index.html';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

PackageWarningOptions() {
_asWarnings.addAll(PackageWarning.values);
ignore(PackageWarning.typeAsHtml);
//error(PackageWarning.brokenLink);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

'dartdoc detected an unknown file in the doc tree: ${message}';
break;
case PackageWarning.typeAsHtml:
warningMessage = 'generic type handled as HTML: """${message}"""';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it visually indistinct when the sample message often contained quotes and so on for this warning.

}

String get arrow {
if (readOnly) return r'&#8594;';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

PackageWarningOptions() {
_asWarnings.addAll(PackageWarning.values);
ignore(PackageWarning.typeAsHtml);
//error(PackageWarning.brokenLink);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

'dartdoc detected an unknown file in the doc tree: ${message}';
break;
case PackageWarning.typeAsHtml:
warningMessage = 'generic type handled as HTML: """${message}"""';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added clarifying comment, but it turned out that the symbols typically involved in the message string made it visually indistinct to use single quotes.

CHANGELOG.md Outdated
* Change --show-warnings to show all warnings, even those that might not be useful yet.
* Display a count of all warnings/errors after document generation.
* Make the progress counter tick slower.
* Added a built-in link checker and orphaned file generator, and tied it into Package.warn so
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==> orphaned file checker?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@devoncarew
Copy link
Member

lgtm for my part! Excited to get this into play for the flutter docs

// TODO(jcollins-g): Rewrite this to handle constructors in a less hacky way
// TODO(jcollins-g): This function breaks down naturally into many helpers, extract them
// TODO(jcollins-g): Subcomponents of this function shouldn't be adding nulls to results, strip the
// removes out that are gratuitous and
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing end of comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

// and will add to [results]
void _getResultsForClass(Class tryClass, String codeRefChomped,
Set<ModelElement> results, String codeRef, Package package) {
if ((tryClass.modelType.typeArguments.map((e) => e.name))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment, indicate this is for type arguments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

CHANGELOG.md Outdated
* Change --show-warnings to show all warnings, even those that might not be useful yet.
* Display a count of all warnings/errors after document generation.
* Make the progress counter tick slower.
* Added a built-in link checker and orphaned file generator, and tied it into Package.warn so
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants