Skip to content
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

aio: improve code auto-linking #22494

Conversation

petebacondarwin
Copy link
Member

Closes #21375

@petebacondarwin petebacondarwin added type: bug/fix action: review The PR is still awaiting reviews from at least one requested reviewer severity3: broken target: patch This PR is targeted for the next patch release labels Feb 28, 2018
@petebacondarwin petebacondarwin added this to REVIEW in docs-infra Feb 28, 2018
@petebacondarwin petebacondarwin force-pushed the aio-autolink-code-disambiguation branch 2 times, most recently from 2334586 to 83f344c Compare February 28, 2018 15:17
@ngbot
Copy link

ngbot bot commented Feb 28, 2018

Hi @petebacondarwin! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@mary-poppins
Copy link

You can preview d7c85d1 at https://pr22494-d7c85d1.ngbuilds.io/.

};
};


Copy link
Member

Choose a reason for hiding this comment

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

Too many empty lines 😱

@@ -45,7 +45,7 @@ module.exports = function autoLinkCode(getDocFromAlias) {
parent.children.splice(index, 1, createLinkNode(docs[0], node.value));
} else {
// Parse the text for words that we can convert to links
const nodes = textContent(node).split(/([A-Za-z0-9_-]+)/)
const nodes = textContent(node).split(/([A-Za-z0-9_.-]+)/)
Copy link
Member

Choose a reason for hiding this comment

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

Where are the tests? 😁

Copy link
Member Author

Choose a reason for hiding this comment

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

Coming

Copy link
Member Author

Choose a reason for hiding this comment

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

arrived

doc.statics.forEach(member => {
member.anchor = computeAnchor(member);
member.path = member.containerDoc.path + '#' + member.anchor;
});
Copy link
Member

Choose a reason for hiding this comment

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

Where are the tests? 😁

Copy link
Member Author

Choose a reason for hiding this comment

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

coming!

@@ -3,29 +3,22 @@ var _ = require('lodash');
/**
* @dgService getDocFromAlias
* @description Get an array of docs that match this alias, relative to the originating doc.
*
* @property {(alias: string, originatingDoc: Doc, ambiguousDocs: Doc[]) => Doc[]} disambiguators a collection of functions
Copy link
Member

Choose a reason for hiding this comment

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

The type should indicate it is an array of such functions. E.g. ((...) => Doc[])[] or Array<(...) => Doc[]>.

function getDocFromAlias(alias, originatingDoc) {
return getDocFromAlias.disambiguators.reduce(
// Run the disambiguators while there is more than 1 doc found
(docs, disambiguater) => docs.length > 1 ? disambiguater(alias, originatingDoc, docs) : docs,
Copy link
Member

@gkalpak gkalpak Feb 28, 2018

Choose a reason for hiding this comment

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

The previous implementation returned all docs if the disambiguation process ended up removing all docs. Is the new implementation deliberately more strict (which will potentially result in fewer matches) to avoid false positives?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would rather have false negatives that positives

@@ -0,0 +1,3 @@
module.exports = function disambiguateByDeprecated() {
return (alias, originatingDoc, docs) => docs.filter(doc => doc.deprecated === undefined);
Copy link
Member

Choose a reason for hiding this comment

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

The deprecatedDocsLinkDisambiguator used to return all the docs if filter() ended up removing all docs. The new implementation will return an empty array instead. Is that intentionally more strict? May it affect behavior in practice?

Copy link
Member Author

Choose a reason for hiding this comment

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

If all the options are deprecated then we probably don't want to advertise them by linking to them :-)

…mAlias`

The disambiguation needs to be done earlier so that the auto-link-code
post-processor can benefit from it.
The new version of `dgeni-packages/typescript` no longer strips
out "namespaces" from types, which was part of the problem of
not autolinking correctly to `HttpEventType.Response`.

Another part of the problem was that we did not include `.`
characters when matching potential code blocks for auto-linking,
which precluded properties of enums from being linked.

Finally, members we not being given a `path` property, which is
needed to effectively autolink to them. This is now set in
the `simplifyMemberAnchors` processor.

Closes angular#21375
@petebacondarwin
Copy link
Member Author

Rebased and added tests etc (via fixup commits). PTAL @gkalpak

@mary-poppins
Copy link

You can preview e60f62f at https://pr22494-e60f62f.ngbuilds.io/.

{ id: 'some-doc', members: [ { name: 'foo' }, { name: 'new' }, { name: '' } ] }
];
processor.$process(docs);
expect(docs[0].members.map(member => member.anchor)).toEqual(['foo', 'new', 'call']);
Copy link
Member

Choose a reason for hiding this comment

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

Not directly related to this PR, but what if there is a method called call 😱

Copy link
Member Author

Choose a reason for hiding this comment

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

That is a good point. In TS 2.7 I believe that such names are somehow escaped?

@gkalpak gkalpak added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 1, 2018
@petebacondarwin petebacondarwin moved this from REVIEW to MERGE in docs-infra Mar 1, 2018
alexeagle pushed a commit that referenced this pull request Mar 1, 2018
…mAlias` (#22494)

The disambiguation needs to be done earlier so that the auto-link-code
post-processor can benefit from it.

PR Close #22494
alexeagle pushed a commit that referenced this pull request Mar 1, 2018
The new version of `dgeni-packages/typescript` no longer strips
out "namespaces" from types, which was part of the problem of
not autolinking correctly to `HttpEventType.Response`.

Another part of the problem was that we did not include `.`
characters when matching potential code blocks for auto-linking,
which precluded properties of enums from being linked.

Finally, members we not being given a `path` property, which is
needed to effectively autolink to them. This is now set in
the `simplifyMemberAnchors` processor.

Closes #21375

PR Close #22494
@alexeagle alexeagle closed this in 997b30a Mar 1, 2018
alexeagle pushed a commit that referenced this pull request Mar 1, 2018
The new version of `dgeni-packages/typescript` no longer strips
out "namespaces" from types, which was part of the problem of
not autolinking correctly to `HttpEventType.Response`.

Another part of the problem was that we did not include `.`
characters when matching potential code blocks for auto-linking,
which precluded properties of enums from being linked.

Finally, members we not being given a `path` property, which is
needed to effectively autolink to them. This is now set in
the `simplifyMemberAnchors` processor.

Closes #21375

PR Close #22494
@petebacondarwin petebacondarwin deleted the aio-autolink-code-disambiguation branch March 1, 2018 19:12
@petebacondarwin petebacondarwin removed this from MERGE in docs-infra Mar 1, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
…mAlias` (angular#22494)

The disambiguation needs to be done earlier so that the auto-link-code
post-processor can benefit from it.

PR Close angular#22494
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
The new version of `dgeni-packages/typescript` no longer strips
out "namespaces" from types, which was part of the problem of
not autolinking correctly to `HttpEventType.Response`.

Another part of the problem was that we did not include `.`
characters when matching potential code blocks for auto-linking,
which precluded properties of enums from being linked.

Finally, members we not being given a `path` property, which is
needed to effectively autolink to them. This is now set in
the `simplifyMemberAnchors` processor.

Closes angular#21375

PR Close angular#22494
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: patch This PR is targeted for the next patch release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(aio): incorrect resolution in naming conflicts
4 participants