WIP Resolve local links via TypeChecker#3115
Conversation
ba6f19c to
db63a51
Compare
1a2af34 to
0346506
Compare
|
[Edit: Never mind, figured it out— I'm trying to debug an issue with this where some (but only some) of the So how are the symbol ID objects created in the comment lexer (the JSDoc |
|
Okay, so the actual problem is that the |
0346506 to
5fa966c
Compare
|
Rebased the patches on the current code, and added 5fa966c, which shows what only resolving the path's root might look like. I think that is a promising direction—it avoids the resolution algorithm duplication, and could probably also replace the JSDoc-based resolution (though I don't know precisely enough what that provides to be certain). It does add another property to |
|
@Gerrit0 you may not be receiving notification for this, but I'd like you to take a look. Sorry for the ping. |
Gerrit0
left a comment
There was a problem hiding this comment.
This is very clever! There are a few issues still, but I agree this seems like a promising path forwards.
I did a bit of experimenting with replacing the ts.JSDoc implementation, and it almost entirely just works! The remaining delta I think is because TS has weird rules about link resolution (a comment on a namespace which links to Foo checks for Foo in the namespace first, but resolveName with the node we pass in today doesn't do that) https://github.com/TypeStrong/typedoc/tree/resolve-via-typechecker-no-jsdoc has what I got to, though I'm out of time for this week, will have to take another look next weekend.
| function resolveLocalLinks(comment: Comment, context: CommentContextOptionalChecker) { | ||
| const { checker, node } = context; | ||
| if (!checker || !node) return; | ||
| for (const elt of comment.summary) { |
There was a problem hiding this comment.
We also need to loop over the parts in comment.blockTags or we'll miss @link tags in @param comments
| const symbol = checker.resolveName( | ||
| ref.path[0].path, | ||
| node, | ||
| ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace, |
There was a problem hiding this comment.
That somehow returned different results, and is what sent me down the rabbit hole of believing there were multiple symbols for a name in the first place. Maybe I did something stupid, but just swapping to that broke my tests.
| ref.path[0].path, | ||
| node, | ||
| ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace, | ||
| true, |
There was a problem hiding this comment.
Is there a reason to exclude globals here? This introduces a delta between this behavior and the behavior for ts.JSDoc in the case I do something like {@link Map.size} (assuming Map is in the documentation of course)
There was a problem hiding this comment.
My thinking was that this is the place where we resolve local links, and the regular resolution can take care of globals. But probably that's not right, since links like {@link RegExp} would count as local links in the sense of the resolver, because they don't contain a !, yet refer to a global binding.
|
|
||
| const sf = declarations.find(ts.isSourceFile); | ||
| if (sf) { | ||
| return getFileComment(sf, context); |
There was a problem hiding this comment.
I think we need to add node: sf to context here, this link resolution doesn't work on // comments for the module today
|
Hi Gerrit, thanks for looking into this! Unfortunately, because I ended up moving on to a different approach for my own use case (directly querying the TS data structures, rather than TypeDoc reflections), I won't be continuing work on this patch. If you feel this approach would a be an improvement, you're of course welcome to fix it up to your standards. If not, also feel free to drop it. |
|
Thanks for the heads up! |
This shows a potential way to improve resolution of
@linktags via the TypeScript typechecker (see #3113). It's intended as a sketch to get feedback on at this point, I don't expect it merged as-is.The most obvious issue with this approach is that it introduces another resolution algorithm, because the existing one in this tree works with TypeDoc reflection objects, which aren't available at the time where we have the node and typechecker around to do this, and the one the TypeScript compiler isn't available to us in a usable way. If that's a non-starter, let me know, and I'll try to just do this in a local plugin instead.
Another issue is whether comments/index.ts is the right place for this code. I can put it into a separate file if you prefer.
Please let me know what you think and whether you see any problems with the code.