diff --git a/packages/language-service/ivy/references.ts b/packages/language-service/ivy/references.ts index b794ee9b46701..492633ed4147d 100644 --- a/packages/language-service/ivy/references.ts +++ b/packages/language-service/ivy/references.ts @@ -317,7 +317,9 @@ export class ReferencesAndRenameBuilder { entries.set(createLocationKey(entry), entry); } } else { - entries.set(createLocationKey(ref), ref); + // TODO(atscott): uncomment when VSCode deduplicates results on their end + // https://github.com/microsoft/vscode/issues/117095 + // entries.set(createLocationKey(ref), ref); } } return Array.from(entries.values()); diff --git a/packages/language-service/ivy/test/references_spec.ts b/packages/language-service/ivy/test/references_spec.ts index 5268e50339f10..00b3458c50e99 100644 --- a/packages/language-service/ivy/test/references_spec.ts +++ b/packages/language-service/ivy/test/references_spec.ts @@ -43,8 +43,8 @@ describe('find references and rename locations', () => { it('gets component member references from TS file and external template', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toBe(2); - assertFileNames(refs, ['app.html', 'app.ts']); + expect(refs.length).toBe(1); + assertFileNames(refs, ['app.html']); assertTextSpans(refs, ['myProp']); }); @@ -78,8 +78,8 @@ describe('find references and rename locations', () => { it('gets references', () => { const refs = getReferencesAtPosition(_('/app.html'), cursor)!; - expect(refs.length).toBe(2); - assertFileNames(refs, ['app.html', 'app.ts']); + expect(refs.length).toBe(1); + assertFileNames(refs, ['app.html']); assertTextSpans(refs, ['myProp']); }); @@ -109,7 +109,7 @@ describe('find references and rename locations', () => { it('gets component member reference in ts file', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toBe(2); + expect(refs.length).toBe(1); assertFileNames(refs, ['app.ts']); assertTextSpans(refs, ['setTitle']); @@ -143,7 +143,7 @@ describe('find references and rename locations', () => { it('gets member reference in ts file', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toBe(2); + expect(refs.length).toBe(1); assertTextSpans(refs, ['title']); }); @@ -207,9 +207,9 @@ describe('find references and rename locations', () => { it('gets member reference in ts file', () => { const refs = getReferencesAtPosition(_('/app.html'), cursor)!; - expect(refs.length).toBe(2); + expect(refs.length).toBe(1); - assertFileNames(refs, ['app.ts', 'app.html']); + assertFileNames(refs, ['app.html']); assertTextSpans(refs, ['title']); }); @@ -244,7 +244,7 @@ describe('find references and rename locations', () => { it('get reference to member in ts file', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toBe(2); + expect(refs.length).toBe(1); assertFileNames(refs, ['app.ts']); assertTextSpans(refs, ['otherTitle']); @@ -281,7 +281,7 @@ describe('find references and rename locations', () => { it('gets reference to member type definition and initialization in component class', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; // 3 references: the type definition, the value assignment, and the read in the template - expect(refs.length).toBe(3); + expect(refs.length).toBe(1); assertFileNames(refs, ['app.ts']); // TODO(atscott): investigate if we can make the template keyed read be just the 'name' part. @@ -289,7 +289,7 @@ describe('find references and rename locations', () => { // https://sourcegraph.com/github.com/microsoft/TypeScript@d5779c75d3dd19565b60b9e2960b8aac36d4d635/-/blob/src/services/findAllReferences.ts#L508-512 // One possible solution would be to extend `FullTemplateMapping` to include the matched TCB // node and then do the same thing that TS does: if the node is a string, adjust the span. - assertTextSpans(refs, ['name', '"name"']); + assertTextSpans(refs, ['"name"']); }); it('gets rename locations in component class', () => { @@ -330,9 +330,9 @@ describe('find references and rename locations', () => { it('get references in ts file', () => { const refs = getReferencesAtPosition(_('/app.html'), cursor)!; - expect(refs.length).toBe(2); + expect(refs.length).toBe(1); - assertFileNames(refs, ['app.ts', 'app.html']); + assertFileNames(refs, ['app.html']); assertTextSpans(refs, ['batman']); }); @@ -482,8 +482,8 @@ describe('find references and rename locations', () => { it('should get references', () => { const refs = getReferencesAtPosition(_('/app.html'), cursor)!; - expect(refs.length).toBe(2); - assertFileNames(refs, ['dir.ts', 'app.html']); + expect(refs.length).toBe(1); + assertFileNames(refs, ['app.html']); assertTextSpans(refs, ['dirValue']); }); @@ -508,8 +508,8 @@ describe('find references and rename locations', () => { it('should get references', () => { const refs = getReferencesAtPosition(_('/app.html'), cursor)!; - expect(refs.length).toBe(2); - assertFileNames(refs, ['dir.ts', 'app.html']); + expect(refs.length).toBe(1); + assertFileNames(refs, ['app.html']); assertTextSpans(refs, ['dirValue']); }); @@ -534,8 +534,8 @@ describe('find references and rename locations', () => { it('should get references', () => { const refs = getReferencesAtPosition(_('/app.html'), cursor)!; - expect(refs.length).toBe(2); - assertFileNames(refs, ['dir.ts', 'app.html']); + expect(refs.length).toBe(1); + assertFileNames(refs, ['app.html']); assertTextSpans(refs, ['doSomething']); }); @@ -671,8 +671,8 @@ describe('find references and rename locations', () => { it('should find references', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toBe(2); - assertFileNames(refs, ['app.ts', 'example-directive.ts']); + expect(refs.length).toBe(1); + assertFileNames(refs, ['app.ts']); assertTextSpans(refs, ['identifier']); }); @@ -701,7 +701,7 @@ describe('find references and rename locations', () => { it('should find references', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toBe(2); + expect(refs.length).toBe(1); assertFileNames(refs, ['app.ts']); assertTextSpans(refs, ['name']); }); @@ -751,9 +751,9 @@ describe('find references and rename locations', () => { it('should find references', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toBe(5); - assertFileNames(refs, ['index.d.ts', 'prefix-pipe.ts', 'app.ts']); - assertTextSpans(refs, ['transform', 'prefixPipe']); + expect(refs.length).toBe(1); + assertFileNames(refs, ['app.ts']); + assertTextSpans(refs, ['prefixPipe']); }); it('should find rename locations', () => { @@ -787,7 +787,7 @@ describe('find references and rename locations', () => { it('should find references', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toBe(2); + expect(refs.length).toBe(1); assertFileNames(refs, ['app.ts']); assertTextSpans(refs, ['prefix']); }); @@ -828,8 +828,8 @@ describe('find references and rename locations', () => { it('should find references', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toEqual(2); - assertFileNames(refs, ['string-model.ts', 'app.ts']); + expect(refs.length).toEqual(1); + assertFileNames(refs, ['app.ts']); assertTextSpans(refs, ['model']); }); @@ -908,8 +908,8 @@ describe('find references and rename locations', () => { it('should work for text attributes', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toEqual(2); - assertFileNames(refs, ['string-model.ts', 'app.ts']); + expect(refs.length).toEqual(1); + assertFileNames(refs, ['app.ts']); assertTextSpans(refs, ['model']); }); @@ -949,8 +949,8 @@ describe('find references and rename locations', () => { it('should work from the TS input declaration', () => { const refs = getReferencesAtPosition(_('/string-model.ts'), cursor)!; - expect(refs.length).toEqual(2); - assertFileNames(refs, ['app.ts', 'string-model.ts']); + expect(refs.length).toEqual(1); + assertFileNames(refs, ['app.ts']); assertTextSpans(refs, ['model']); }); @@ -1005,8 +1005,8 @@ describe('find references and rename locations', () => { it('should find references', () => { const refs = getReferencesAtPosition(_('/other-dir.ts'), cursor)!; - expect(refs.length).toEqual(3); - assertFileNames(refs, ['app.ts', 'string-model.ts', 'other-dir.ts']); + expect(refs.length).toEqual(1); + assertFileNames(refs, ['app.ts']); assertTextSpans(refs, ['model']); }); @@ -1036,9 +1036,9 @@ describe('find references and rename locations', () => { it('should find references', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toEqual(2); - assertFileNames(refs, ['string-model.ts', 'app.ts']); - assertTextSpans(refs, ['aliasedModel', 'alias']); + expect(refs.length).toEqual(1); + assertFileNames(refs, ['app.ts']); + assertTextSpans(refs, ['alias']); }); it('should find rename locations', () => { @@ -1090,7 +1090,7 @@ describe('find references and rename locations', () => { it('should find references', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toEqual(2); + expect(refs.length).toEqual(1); assertTextSpans(refs, ['modelChange']); }); @@ -1115,8 +1115,8 @@ describe('find references and rename locations', () => { it('should find references', () => { const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - expect(refs.length).toEqual(2); - assertTextSpans(refs, ['aliasedModelChange', 'alias']); + expect(refs.length).toEqual(1); + assertTextSpans(refs, ['alias']); }); it('should find rename locations', () => { @@ -1152,12 +1152,9 @@ describe('find references and rename locations', () => { env = createModuleWithDeclarations([appFile, dirFile]); const refs = getReferencesAtPosition(_('/app.ts'), cursor)!; - // Note that this includes the 'model` twice from the template. As with other potential - // duplicates (like if another plugin returns the same span), we expect the LS clients to filter - // these out themselves. - expect(refs.length).toEqual(4); - assertFileNames(refs, ['dir.ts', 'app.ts']); - assertTextSpans(refs, ['model', 'modelChange']); + expect(refs.length).toEqual(2); + assertFileNames(refs, ['app.ts']); + assertTextSpans(refs, ['model']); }); describe('directives', () => { @@ -1191,9 +1188,9 @@ describe('find references and rename locations', () => { const refs = getReferencesAtPosition(_('/dir.ts'), cursor)!; // 4 references are: class declaration, template usage, app import and use in declarations // list. - expect(refs.length).toBe(4); - assertTextSpans(refs, ['