microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.06k stars 12.49k forks source link

referencesCodeLens count is wrong #50614

Open Southhill opened 2 years ago

Southhill commented 2 years ago

Does this issue occur when all extensions are disabled?: Yes

wrong_referencesCodeLens.ts file: https://gist.github.com/Southhill/a89406054990d1ae86fcebf7124d125f

Steps to Reproduce:

  1. setting: "typescript.referencesCodeLens.enabled": true
  2. open wrong_referencesCodeLens.ts
  3. expect class A method destroy only 1 references but 6 references
mjbvz commented 2 years ago

A few issues here:

sandersn commented 1 year ago

I'm following up on the details, but internally the language service produces a 3-element list with exactly the results you'd expect for each of Base.destroy, A.destroy and B.destroy. Then the language service flattens all 3 entries instead of returning the entry for A.destroy. I'm not sure why.

For ease of reference, here's a condensed repro:

class Base {
    protected destroy() {
        return 0;
    }
}
class A extends Base {
    public destroy(): number {
        super.destroy();
        return 0;
    }
}
class B extends Base {
    public destroy(): number {
        super.destroy();
        return 0;
    }
}
(new A).destroy();
(new B).destroy();

Expected: 1 reference to A.destroy Actual: 6 references to A.destroy