2016-11-22 12:10:23 -05:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as ts from 'typescript';
|
|
|
|
|
|
|
|
import {createLanguageService} from '../src/language_service';
|
|
|
|
import {TypeScriptServiceHost} from '../src/typescript_host';
|
|
|
|
|
2017-01-03 20:21:45 -05:00
|
|
|
import {MockTypescriptHost} from './test_utils';
|
2016-11-22 12:10:23 -05:00
|
|
|
|
2019-10-17 21:42:27 -04:00
|
|
|
const TEST_TEMPLATE = '/app/test.ng';
|
2020-02-24 21:28:31 -05:00
|
|
|
const PARSING_CASES = '/app/parsing-cases.ts';
|
2019-10-17 21:42:27 -04:00
|
|
|
|
2019-10-16 15:00:41 -04:00
|
|
|
describe('hover', () => {
|
2019-10-16 14:01:31 -04:00
|
|
|
const mockHost = new MockTypescriptHost(['/app/main.ts']);
|
|
|
|
const tsLS = ts.createLanguageService(mockHost);
|
|
|
|
const ngLSHost = new TypeScriptServiceHost(mockHost, tsLS);
|
|
|
|
const ngLS = createLanguageService(ngLSHost);
|
2019-08-28 15:55:12 -04:00
|
|
|
|
2020-04-03 23:57:39 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
mockHost.reset();
|
|
|
|
});
|
2016-11-22 12:10:23 -05:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
describe('location of hover', () => {
|
|
|
|
it('should find members in a text interpolation', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, '<div>{{«title»}}</div>');
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'title');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TemplateReference.title: string');
|
|
|
|
});
|
2020-02-17 05:38:12 -05:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should find members in an attribute interpolation', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div string-model model="{{«title»}}"></div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'title');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TemplateReference.title: string');
|
|
|
|
});
|
2016-11-22 12:10:23 -05:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should find members in a property binding', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<test-comp [tcName]="«title»"></test-comp>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'title');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TemplateReference.title: string');
|
|
|
|
});
|
2016-11-22 12:10:23 -05:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should find members in an event binding', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<test-comp (test)="«title»=$event"></test-comp>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'title');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TemplateReference.title: string');
|
|
|
|
});
|
2016-11-22 12:10:23 -05:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should find members in a two-way binding', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<input [(ngModel)]="«title»" />`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'title');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TemplateReference.title: string');
|
|
|
|
});
|
2016-11-22 12:10:23 -05:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should find members in a structural directive', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div *ngIf="«anyValue»"></div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'anyValue');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TemplateReference.anyValue: any');
|
|
|
|
});
|
feat(language-service): directive info when looking up attribute's symbol (#33127)
Now, hovering over an attribute on an element will provide information
about the directive that attribute matches in the element, if any.
(More generally, we return information about directive symbols
matched on an element attribute.)
I believe this is similar to how the indexer provides this kind of
information, though more precise in the sense that this commit provides
directive information only if the directive selector exactly matches the
attribute selector. In another sense, this is a limitation.
In fact, there are the limitations of:
- Directives matched on the element, but with a selector of anything
more than the attribute (e.g. `div[string-model]` or
`[string-model][other-attr]`) will not be returned as symbols matching
on the attribute.
- Only one symbol can be returned currently. If the attribute matches
multiple directives, only one directive symbol will be returned.
Furthermore, we cannot say that the directive symbol returned is
determinstic.
Resolution of these limitations can be discussed in the future. At least
the second limitation should be very easy to fixup in a future commit.
This relies solely on the template compiler and is agnostic to any Ivy
changes, so this is strictly a feature enhancement that will not have to
be refactored when we migrate the language service to Ivy.
PR Close #33127
2019-10-12 20:11:55 -04:00
|
|
|
});
|
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
describe('hovering on expression nodes', () => {
|
|
|
|
it('should provide documentation', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div>{{~{cursor}title}}</div>`);
|
|
|
|
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeDefined();
|
2020-04-03 23:57:39 -04:00
|
|
|
const documentation = toText(quickInfo!.documentation);
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(documentation).toBe('This is the title of the `TemplateReference` Component.');
|
|
|
|
});
|
2016-11-22 12:10:23 -05:00
|
|
|
|
2020-03-30 03:10:34 -04:00
|
|
|
describe('property reads', () => {
|
|
|
|
it('should work for class members', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div>{{«title»}}</div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'title');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-03-30 03:10:34 -04:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TemplateReference.title: string');
|
|
|
|
});
|
|
|
|
|
2020-04-27 21:54:30 -04:00
|
|
|
it('should work for accessed property reads', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div>{{title.«length»}}</div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'length');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) String.length: number');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for properties in writes', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div (click)="«title» = 't'"></div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'title');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TemplateReference.title: string');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for accessed properties in writes', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div (click)="hero.«id» = 2"></div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'id');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) Hero.id: number');
|
|
|
|
});
|
|
|
|
|
2020-03-30 03:10:34 -04:00
|
|
|
it('should work for array members', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div *ngFor="let hero of heroes">{{«hero»}}</div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'hero');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-03-30 03:10:34 -04:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(variable) hero: Hero');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for ReadonlyArray members (#36191)', () => {
|
|
|
|
mockHost.override(
|
|
|
|
TEST_TEMPLATE, `<div *ngFor="let hero of readonlyHeroes">{{«hero»}}</div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'hero');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-03-30 03:10:34 -04:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(variable) hero: Readonly<Hero>');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for const array members (#36191)', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div *ngFor="let name of constNames">{{«name»}}</div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'name');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-03-30 03:10:34 -04:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(variable) name: { readonly name: "name"; }');
|
|
|
|
});
|
2020-02-24 21:28:31 -05:00
|
|
|
});
|
2016-11-22 12:10:23 -05:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should work for method calls', () => {
|
2020-04-27 21:54:30 -04:00
|
|
|
mockHost.override(TEST_TEMPLATE, `<div (click)="«myClick»($event)"></div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'myClick');
|
2020-01-17 05:11:23 -05:00
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-01-17 05:11:23 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(toText(displayParts)).toBe('(method) TemplateReference.myClick: (event: any) => void');
|
2020-01-17 05:11:23 -05:00
|
|
|
});
|
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should work for structural directive inputs', () => {
|
2020-03-05 18:38:25 -05:00
|
|
|
mockHost.override(TEST_TEMPLATE, `<div *ngFor="let item of heroes; «trackBy»: test;"></div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'trackBy');
|
2020-01-17 05:11:23 -05:00
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-01-17 05:11:23 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(method) NgForOf<T, U>.ngForTrackBy: TrackByFunction<T>');
|
|
|
|
});
|
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should work for members in structural directives', () => {
|
2020-01-17 05:11:23 -05:00
|
|
|
mockHost.override(TEST_TEMPLATE, `<div *ngFor="let item of «heroes»; trackBy: test;"></div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'heroes');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-01-17 05:11:23 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TemplateReference.heroes: Hero[]');
|
|
|
|
});
|
2019-12-26 02:19:38 -05:00
|
|
|
|
2020-03-10 01:16:08 -04:00
|
|
|
it('should work for pipes', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `
|
|
|
|
<p>The hero's birthday is {{birthday | «date»: "MM/dd/yy"}}</p>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'date');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-03-10 01:16:08 -04:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts))
|
|
|
|
.toBe(
|
|
|
|
'(pipe) date: (value: any, format?: string | undefined, timezone?: string | undefined, locale?: string | undefined) => string | null');
|
|
|
|
});
|
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should work for the $any() cast function', () => {
|
|
|
|
const content = mockHost.override(TEST_TEMPLATE, '<div>{{$any(title)}}</div>');
|
|
|
|
const position = content.indexOf('$any');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, position);
|
|
|
|
expect(quickInfo).toBeDefined();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual({
|
|
|
|
start: position,
|
2020-04-27 21:54:30 -04:00
|
|
|
length: '$any'.length,
|
2020-02-24 21:28:31 -05:00
|
|
|
});
|
|
|
|
expect(toText(displayParts)).toBe('(method) $any: $any');
|
|
|
|
});
|
2020-01-03 05:32:30 -05:00
|
|
|
});
|
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
describe('hovering on template nodes', () => {
|
|
|
|
it('should provide documentation', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<~{cursor}test-comp></test-comp>`);
|
|
|
|
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeDefined();
|
2020-04-03 23:57:39 -04:00
|
|
|
const documentation = toText(quickInfo!.documentation);
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(documentation).toBe('This Component provides the `test-comp` selector.');
|
|
|
|
});
|
2019-09-16 22:07:43 -04:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should work for components', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, '<~{cursor}test-comp></test-comp>');
|
|
|
|
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeDefined();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {displayParts, documentation} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(toText(displayParts))
|
|
|
|
.toBe('(component) AppModule.TestComponent: typeof TestComponent');
|
|
|
|
expect(toText(documentation)).toBe('This Component provides the `test-comp` selector.');
|
|
|
|
});
|
2019-09-16 22:07:43 -04:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should work for directives', () => {
|
|
|
|
const content = mockHost.override(TEST_TEMPLATE, `<div string-model~{cursor}></div>`);
|
|
|
|
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeDefined();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {displayParts, textSpan} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(toText(displayParts)).toBe('(directive) AppModule.StringModel: typeof StringModel');
|
|
|
|
expect(content.substring(textSpan.start, textSpan.start + textSpan.length))
|
|
|
|
.toBe('string-model');
|
|
|
|
});
|
2019-10-11 20:15:07 -04:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should work for event providers', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<test-comp «(ᐱtestᐱ)="myClick($event)"»></div>`);
|
|
|
|
const marker = mockHost.getDefinitionMarkerFor(TEST_TEMPLATE, 'test');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(event) TestComponent.testEvent: EventEmitter<any>');
|
2019-10-16 15:00:41 -04:00
|
|
|
});
|
2019-10-17 21:42:27 -04:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should work for input providers', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<test-comp «[ᐱtcNameᐱ]="name"»></div>`);
|
|
|
|
const marker = mockHost.getDefinitionMarkerFor(TEST_TEMPLATE, 'tcName');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TestComponent.name: string');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for two-way binding providers', () => {
|
|
|
|
mockHost.override(
|
|
|
|
TEST_TEMPLATE, `<test-comp string-model «[(ᐱmodelᐱ)]="title"»></test-comp>`);
|
|
|
|
const marker = mockHost.getDefinitionMarkerFor(TEST_TEMPLATE, 'model');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) StringModel.model: string');
|
2019-10-17 21:42:27 -04:00
|
|
|
});
|
2019-12-19 21:33:26 -05:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
it('should work for structural directives', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div «*ᐱngForᐱ="let item of heroes"»></div>`);
|
|
|
|
const marker = mockHost.getDefinitionMarkerFor(TEST_TEMPLATE, 'ngFor');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(directive) NgForOf: typeof NgForOf');
|
|
|
|
});
|
2019-12-19 21:33:26 -05:00
|
|
|
});
|
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
describe('hovering on TypeScript nodes', () => {
|
|
|
|
it('should work for component TypeScript declarations', () => {
|
2020-04-03 23:57:39 -04:00
|
|
|
const content = mockHost.readFile(PARSING_CASES)!;
|
2020-02-24 21:28:31 -05:00
|
|
|
const position = content.indexOf('TemplateReference');
|
|
|
|
expect(position).toBeGreaterThan(0);
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(PARSING_CASES, position);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual({
|
|
|
|
start: position,
|
|
|
|
length: 'TemplateReference'.length,
|
|
|
|
});
|
|
|
|
expect(toText(displayParts)).toBe('(component) AppModule.TemplateReference: class');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work for directive TypeScript declarations', () => {
|
2020-04-03 23:57:39 -04:00
|
|
|
const content = mockHost.readFile(PARSING_CASES)!;
|
2020-02-24 21:28:31 -05:00
|
|
|
const position = content.indexOf('StringModel');
|
|
|
|
expect(position).toBeGreaterThan(0);
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(PARSING_CASES, position);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual({
|
|
|
|
start: position,
|
|
|
|
length: 'StringModel'.length,
|
|
|
|
});
|
|
|
|
expect(toText(displayParts)).toBe('(directive) AppModule.StringModel: class');
|
|
|
|
});
|
2019-12-19 21:33:26 -05:00
|
|
|
});
|
2019-12-21 20:23:09 -05:00
|
|
|
|
2020-02-24 21:28:31 -05:00
|
|
|
describe('non-goals', () => {
|
|
|
|
it('should ignore reference declarations', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div #«chart»></div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'chart');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not expand i18n templates', () => {
|
|
|
|
mockHost.override(TEST_TEMPLATE, `<div i18n="@@el">{{«title»}}</div>`);
|
|
|
|
const marker = mockHost.getReferenceMarkerFor(TEST_TEMPLATE, 'title');
|
|
|
|
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
|
|
|
expect(quickInfo).toBeTruthy();
|
2020-04-03 23:57:39 -04:00
|
|
|
const {textSpan, displayParts} = quickInfo!;
|
2020-02-24 21:28:31 -05:00
|
|
|
expect(textSpan).toEqual(marker);
|
|
|
|
expect(toText(displayParts)).toBe('(property) TemplateReference.title: string');
|
|
|
|
});
|
2019-12-21 20:23:09 -05:00
|
|
|
});
|
2019-05-08 13:30:54 -04:00
|
|
|
});
|
2019-08-28 15:55:12 -04:00
|
|
|
|
|
|
|
function toText(displayParts?: ts.SymbolDisplayPart[]): string {
|
|
|
|
return (displayParts || []).map(p => p.text).join('');
|
|
|
|
}
|