Skip to content

Fix element discovery without analyzer changes #2050

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 3 commits into from
Oct 31, 2019
Merged

Conversation

jcollins-g
Copy link
Contributor

@jcollins-g jcollins-g commented Oct 29, 2019

Fixes #2047. (And possibly, other similar bugs due to dartdoc's inconsistency internally in discovery handling).

Per discussion with @scheglov and @bwilkerson, an analyzer extension was determined not to be necessary or even all that useful. Therefore, extract the pieces from https://dart-review.googlesource.com/c/sdk/+/122169 that remained useful and drop them directly into dartdoc.

This is a prelude to other changes to support documenting extension methods as part of classes, cross referencing extensions with what they extend, and resolving comment references inside extension methods.

@googlebot googlebot added the cla: yes Google CLA check succeeded. label Oct 29, 2019
@jcollins-g jcollins-g changed the title Fix discovery without analyzer changes Fix element discovery without analyzer changes Oct 29, 2019
@coveralls
Copy link

coveralls commented Oct 29, 2019

Coverage Status

Coverage decreased (-0.04%) to 93.893% when pulling 217bd9d on scope-changes into 3f6ff5a on master.

.whereType<ExtensionElement>());

_extensions = extensionElements
_extensions = _exportedAndLocalElements
Copy link
Member

Choose a reason for hiding this comment

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

Here and below, consider the shorter form:

return _extensions ??= ...;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Surrounding code style is along the lines of

if (_foo == null) {
  do_things_to_create__foo;
}
return _foo;

so I would prefer to keep this for now to be consistent

// Initialize the list of elements defined in this library and
// exported via its export directives.
Set<Element> exportedAndLocalElements = NamespaceBuilder()
.createExportNamespaceForLibrary(element)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would LibraryElement.exportNamespace work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to work. Given that it is part of the public interface I'll switch to that, but I'm surprised that the two seem to use completely different means to generate the same data. Is there an intended difference between the two?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, given that NamespaceBuilder is not a part of public API, while it is definitely not good that we have two implementations, it is better if external users use the one from the public API :-P

_package._allLibraries.add(this);
}

static Iterable<Element> getDefinedElements(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm adding extensions to LibraryElement.topLevelElements.
https://dart-review.googlesource.com/c/sdk/+/123551

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great. For some reason we don't seem to use/trust LibraryElement.topLevelElements anywhere, but if it gives us the same thing eventually we should switch this whole discovery system over and improve it. Added TODO

@scheglov
Copy link
Contributor

FWIW, I'm not against landing this, just pointing out that there might be a slightly better ways to do it, in the future sometimes :-)

@jcollins-g
Copy link
Contributor Author

Yes, actually there are way better ways to do this @scheglov. Transforming this into a single element construction stream, directly calling the ModelElement.from on everything and dispatching into buckets based on the returned, generated type just off the top of my head. But once I start down the refactoring path forever will it dominate my release schedule....

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.

Extension reexport doesn't handle name conflicts correctly
5 participants