feat(language-service): completions for output $event properties in (#34570)
This commit adds support for completions of properties on `$event` variables in bound outputs. This is the second major PR to support completions for `$event` variables (https://github.com/angular/vscode-ng-language-service/issues/531). The final completion support that must be provided is for `$event` variables in bindings targeting DOM events, like `(click)`. PR Close #34570
This commit is contained in:

committed by
Andrew Kushnir

parent
c246787ccc
commit
2a537273ca
@ -758,10 +758,17 @@ describe('completions', () => {
|
||||
it('should suggest $event in event bindings', () => {
|
||||
mockHost.override(TEST_TEMPLATE, `<div (click)="myClick(~{cursor});"></div>`);
|
||||
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
||||
debugger;
|
||||
const completions = ngLS.getCompletionsAt(TEST_TEMPLATE, marker.start);
|
||||
const completions = ngLS.getCompletionsAtPosition(TEST_TEMPLATE, marker.start);
|
||||
expectContain(completions, CompletionKind.VARIABLE, ['$event']);
|
||||
});
|
||||
|
||||
it('should suggest $event completions in output bindings', () => {
|
||||
mockHost.override(TEST_TEMPLATE, `<div string-model (modelChange)="$event.~{cursor}"></div>`);
|
||||
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
||||
const completions = ngLS.getCompletionsAtPosition(TEST_TEMPLATE, marker.start);
|
||||
// Expect string properties
|
||||
expectContain(completions, CompletionKind.METHOD, ['charAt', 'substring']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -319,16 +319,14 @@ describe('diagnostics', () => {
|
||||
|
||||
describe('with $event', () => {
|
||||
it('should accept an event', () => {
|
||||
const fileName = '/app/test.ng';
|
||||
mockHost.override(fileName, '<div (click)="myClick($event)">Click me!</div>');
|
||||
const diagnostics = ngLS.getSemanticDiagnostics(fileName);
|
||||
mockHost.override(TEST_TEMPLATE, '<div (click)="myClick($event)">Click me!</div>');
|
||||
const diagnostics = ngLS.getSemanticDiagnostics(TEST_TEMPLATE);
|
||||
expect(diagnostics).toEqual([]);
|
||||
});
|
||||
|
||||
it('should reject it when not in an event binding', () => {
|
||||
const fileName = '/app/test.ng';
|
||||
const content = mockHost.override(fileName, '<div [tabIndex]="$event"></div>');
|
||||
const diagnostics = ngLS.getSemanticDiagnostics(fileName) !;
|
||||
const content = mockHost.override(TEST_TEMPLATE, '<div [tabIndex]="$event"></div>');
|
||||
const diagnostics = ngLS.getSemanticDiagnostics(TEST_TEMPLATE) !;
|
||||
expect(diagnostics.length).toBe(1);
|
||||
const {messageText, start, length} = diagnostics[0];
|
||||
expect(messageText)
|
||||
@ -338,6 +336,17 @@ describe('diagnostics', () => {
|
||||
expect(start).toBe(content.lastIndexOf(keyword));
|
||||
expect(length).toBe(keyword.length);
|
||||
});
|
||||
|
||||
it('should reject invalid properties on an event type', () => {
|
||||
const content = mockHost.override(
|
||||
TEST_TEMPLATE, '<div string-model (modelChange)="$event.notSubstring()"></div>');
|
||||
const diagnostics = ngLS.getSemanticDiagnostics(TEST_TEMPLATE) !;
|
||||
expect(diagnostics.length).toBe(1);
|
||||
const {messageText, start, length} = diagnostics[0];
|
||||
expect(messageText).toBe(`Unknown method 'notSubstring'`);
|
||||
expect(start).toBe(content.indexOf('$event'));
|
||||
expect(length).toBe('$event.notSubstring()'.length);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not crash with a incomplete *ngFor', () => {
|
||||
|
Reference in New Issue
Block a user