Repository navigation
Fix #47753 - Organize imports removes type imports that are only referenced in @link (jsdoc) - #47824
Conversation
Nathan Shively-Sanders (sandersn)
left a comment
There was a problem hiding this comment.
This works, but it should actually happen in FindAllReferences, and use the normal FindAllReference machinery.
|
Hi Nathan Shively-Sanders (@sandersn), thanks for the review. I will update the PR accordingly, but I just need a little time, because things are kind of crazy right now. |
|
This is related to the larger issue that TS considers |
|
Hey Daniel Wolf (@DanielSWolf), I think I found the root cause of both problems in the compiler. I will try to solve both issues. |
|
Felipe Armoni (@komyg) That would be great! The current behavior makes it really hard to write links that consistently work. |
|
Hi Nathan Shively-Sanders (@sandersn), I've fixed the However, I also got an error for a JSDoc baseline that I didn't understand, so I don't know if I inadvertently broke something or if the fix also corrected it. Could you please review the PR again? |
|
The JSDoc baseline change shows that the link target is now different for imports. For this code: // @filename: one.ts
export class C { }
// @filename: two.ts
import { C } from './one'
/** {@link C} */
var x = 1
That's not right, so this PR needs more work. I'll see if I can figure out what. |
|
WIthout debugging the newly-failing test case, I don't know how the old code resolves |
Well, I since the I think that the problem lies in the return (symbol.flags & meaning) || dontResolveAlias ? symbol : resolveAlias(symbol);By setting Since the original code did not have the A possible solution would be for us to find what is unique about each situation to make a better choice whether to set |
|
So: in the old code, jsdoc references, like You are right, though: for the purpose of organise imports, we don't actually want to resolve aliases. It's enough to know that |
|
How can we fix this, then? It seems that organize imports is an "edgier" case than resolving aliases that you mentioned, so maybe we could do some logic outside the My original solution did not rely on the Note: this is the commit in which I erased my previous attempt at a solution. |
|
I looked again at your test cases, and the first problem is that they import things that aren't present in the program. The test cases need to have multiple files. See jsdocLink3.ts for an example. It might be nice if organise imports didn't rely on find-all-refs, and therefore on the the target of the alias being defined. |
|
From manual testing, I can see that find-all-references doesn't work correctly for // @filename:ex.d.ts
export type A = 1 | 2
export type B = 3 | 4
// @filename: main.ts
import { A, B } from './ex'
/** {@link A} */
class C {
b: B = 3
}Find-all-refs on main's B finds 3 refs; find-all-refs on main's A only finds the import alias. |
I tested this locally and it is the solution. It does change the baselines for jsdocLink3, but I'm pretty sure those were wrong, because I manually tested the test code in jsdocLink3 and it behaves right with |
|
Hey Nathan Shively-Sanders (@sandersn), from your comments, I understood that the solution that we've implemented here is correct, and I just have to make the following changes:
Am I right? |
|
Everything is right except skipping the addition of Edit: Also I think jsdoclink3 covers enough that you don't need to add the test case in (4). |
|
Sorry, true. dontResolveAlias should be true. |
|
Hi Nathan Shively-Sanders (@sandersn), I've done the changes we've discussed. Could you review again, please? |
|
Hi Nathan Shively-Sanders (@sandersn), sorry to bother you. I've done the changes we've discussed. Could you review again, please? |
|
Woops, sorry this fell off my list. Thanks for your patience! |
|
No worries! I am happy to have contributed! |
Fixes #47753, #47558