Skip to content

Commit 1b1b65e

Browse files
ivanwonderzarend
authored andcommitted
fix(language-service): can't provide the Input and Output custom binding property name (#41005)
Now the language service always uses the name of the JavaScript property on the component or directive instance for this input or output. This PR will use the right binding property name. PR Close #41005
1 parent 27d55f6 commit 1b1b65e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

packages/language-service/ivy/attribute_completions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export function buildAttributeCompletionTable(
203203
continue;
204204
}
205205

206-
for (const [propertyName, classPropertyName] of meta.inputs) {
206+
for (const [classPropertyName, propertyName] of meta.inputs) {
207207
if (table.has(propertyName)) {
208208
continue;
209209
}
@@ -217,7 +217,7 @@ export function buildAttributeCompletionTable(
217217
});
218218
}
219219

220-
for (const [propertyName, classPropertyName] of meta.outputs) {
220+
for (const [classPropertyName, propertyName] of meta.outputs) {
221221
if (table.has(propertyName)) {
222222
continue;
223223
}

packages/language-service/ivy/test/completions_spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ const DIR_WITH_TWO_WAY_BINDING = {
5252
`
5353
};
5454

55+
const DIR_WITH_BINDING_PROPERTY_NAME = {
56+
'Dir': `
57+
@Directive({
58+
selector: '[dir]',
59+
inputs: ['model: customModel'],
60+
outputs: ['update: customModelChange'],
61+
})
62+
export class Dir {
63+
model!: any;
64+
update!: any;
65+
}
66+
`
67+
};
68+
5569
const NG_FOR_DIR = {
5670
'NgFor': `
5771
@Directive({
@@ -563,6 +577,30 @@ describe('completions', () => {
563577
completions, unsafeCastDisplayInfoKindToScriptElementKind(DisplayInfoKind.EVENT),
564578
['otherOutput']);
565579
});
580+
581+
it('should return input completions for a binding property name', () => {
582+
const {templateFile} =
583+
setup(`<h1 dir [customModel]></h1>`, ``, DIR_WITH_BINDING_PROPERTY_NAME);
584+
templateFile.moveCursorToText('[customModel¦]');
585+
const completions = templateFile.getCompletionsAtPosition();
586+
expectReplacementText(completions, templateFile.contents, 'customModel');
587+
588+
expectContain(
589+
completions, unsafeCastDisplayInfoKindToScriptElementKind(DisplayInfoKind.PROPERTY),
590+
['customModel']);
591+
});
592+
593+
it('should return output completions for a binding property name', () => {
594+
const {templateFile} =
595+
setup(`<h1 dir (customModel)></h1>`, ``, DIR_WITH_BINDING_PROPERTY_NAME);
596+
templateFile.moveCursorToText('(customModel¦)');
597+
const completions = templateFile.getCompletionsAtPosition();
598+
expectReplacementText(completions, templateFile.contents, 'customModel');
599+
600+
expectContain(
601+
completions, unsafeCastDisplayInfoKindToScriptElementKind(DisplayInfoKind.EVENT),
602+
['customModelChange']);
603+
});
566604
});
567605
});
568606

0 commit comments

Comments
 (0)