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
aio: improve code auto-linking #22494
Conversation
2334586
to
83f344c
Compare
Hi @petebacondarwin! This PR has merge conflicts due to recent upstream merges. |
83f344c
to
d7c85d1
Compare
You can preview d7c85d1 at https://pr22494-d7c85d1.ngbuilds.io/. |
}; | ||
}; | ||
|
||
|
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.
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_.-]+)/) |
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.
Where are the tests? 😁
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.
Coming
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.
arrived
doc.statics.forEach(member => { | ||
member.anchor = computeAnchor(member); | ||
member.path = member.containerDoc.path + '#' + member.anchor; | ||
}); |
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.
Where are the tests? 😁
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.
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 |
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.
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, |
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.
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?
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.
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); |
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.
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?
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.
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
cfd4987
to
e60f62f
Compare
Rebased and added tests etc (via fixup commits). PTAL @gkalpak |
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']); |
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.
Not directly related to this PR, but what if there is a method called call
😱
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.
That is a good point. In TS 2.7 I believe that such names are somehow escaped?
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
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
…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
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
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Closes #21375