fix(language-service): Insert parentheses for method completion (#33860)
This commit leverages the `insertText` field in `ts.CompletionEntry` to return a completion text for class methods that includes parentheses. PR closes https://github.com/angular/vscode-ng-language-service/issues/15 PR Close #33860
This commit is contained in:

committed by
Miško Hevery

parent
db4789bf91
commit
fb22f18694
@ -442,6 +442,7 @@ class ExpressionVisitor extends NullTemplateVisitor {
|
||||
name: s.name,
|
||||
kind: s.kind as ng.CompletionKind,
|
||||
sortText: s.name,
|
||||
insertText: s.callable ? `${s.name}()` : s.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -213,6 +213,18 @@ describe('completions', () => {
|
||||
expectContain(completions, CompletionKind.METHOD, ['myClick']);
|
||||
});
|
||||
|
||||
it('for methods should include parentheses', () => {
|
||||
mockHost.override(TEST_TEMPLATE, `<div (click)="~{cursor}"></div>`);
|
||||
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
||||
const completions = ngLS.getCompletionsAt(TEST_TEMPLATE, marker.start);
|
||||
expect(completions).toBeDefined();
|
||||
expect(completions !.entries).toContain(jasmine.objectContaining({
|
||||
name: 'myClick',
|
||||
kind: CompletionKind.METHOD as any,
|
||||
insertText: 'myClick()',
|
||||
}));
|
||||
});
|
||||
|
||||
describe('in external template', () => {
|
||||
it('should be able to get entity completions in external template', () => {
|
||||
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'entity-amp');
|
||||
|
@ -128,6 +128,7 @@ describe('plugin', () => {
|
||||
kind: CompletionKind.PROPERTY as any,
|
||||
sortText: 'children',
|
||||
replacementSpan: {start: 182, length: 8},
|
||||
insertText: 'children',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
Reference in New Issue
Block a user