fix(language-service): fix calculation of pipe spans (#35986)

This commit accomplishes two tasks:

- Fixes the span of queried pipes to only be applied on pipe names
- By consequence, fixes how pipes are located in arguments (previously,
  pipes with arguments could not be found because the span of a pipe
  uses a relative span, while the template position is absolute)

The screenshots attached to the PR for this commit demonstrate the
change.

Closes https://github.com/angular/vscode-ng-language-service/issues/677

PR Close #35986
This commit is contained in:
ayazhafiz
2020-03-09 22:16:08 -07:00
committed by Matias Niemelä
parent a73e125c04
commit 406419bc0f
4 changed files with 59 additions and 13 deletions

View File

@ -234,22 +234,19 @@ describe('definitions', () => {
it('should be able to find a pipe', () => {
const fileName = mockHost.addCode(`
@Component({
template: '<div *ngIf="~{start-my}input | «async»~{end-my}"></div>'
template: '<div *ngIf="input | «async»"></div>'
})
export class MyComponent {
input: EventEmitter;
}`);
// Get the marker for «test» in the code added above.
// Get the marker for «async» in the code added above.
const marker = mockHost.getReferenceMarkerFor(fileName, 'async');
const result = ngService.getDefinitionAndBoundSpan(fileName, marker.start);
expect(result).toBeDefined();
const {textSpan, definitions} = result !;
// Get the marker for bounded text in the code added above
const boundedText = mockHost.getLocationMarkerFor(fileName, 'my');
expect(textSpan).toEqual(boundedText);
expect(textSpan).toEqual(marker);
expect(definitions).toBeDefined();
expect(definitions !.length).toBe(4);
@ -263,6 +260,28 @@ describe('definitions', () => {
}
});
// https://github.com/angular/vscode-ng-language-service/issues/677
it('should be able to find a pipe with arguments', () => {
mockHost.override(TEST_TEMPLATE, `{{birthday | «date»: "MM/dd/yy"}}`);
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'date');
const result = ngService.getDefinitionAndBoundSpan(TEST_TEMPLATE, marker.start);
expect(result).toBeDefined();
const {textSpan, definitions} = result !;
expect(textSpan).toEqual(marker);
expect(definitions).toBeDefined();
expect(definitions !.length).toBe(1);
const refFileName = '/node_modules/@angular/common/common.d.ts';
for (const def of definitions !) {
expect(def.fileName).toBe(refFileName);
expect(def.name).toBe('date');
expect(def.kind).toBe('pipe');
}
});
describe('in structural directive', () => {
it('should be able to find the directive', () => {
mockHost.override(