fix(language-service): provide completions for the structural directive that only injects the 'ViewContainerRef' (#35466)
The completions list don't include the 'ngTemplateOutlet'. The directive is a structural directive when it has injected the 'TemplateRef' or 'ViewContainerRef'. PR Close #35466
This commit is contained in:
parent
d2a112fa72
commit
66c06eb1ad
|
@ -15,7 +15,7 @@ import {getExpressionCompletions} from './expressions';
|
|||
import {attributeNames, elementNames, eventNames, propertyNames} from './html_info';
|
||||
import {InlineTemplate} from './template';
|
||||
import * as ng from './types';
|
||||
import {diagnosticInfoFromTemplateInfo, findTemplateAstAt, getPathToNodeAtPosition, getSelectors, hasTemplateReference, inSpan, spanOf} from './utils';
|
||||
import {diagnosticInfoFromTemplateInfo, findTemplateAstAt, getPathToNodeAtPosition, getSelectors, inSpan, isStructuralDirective, spanOf} from './utils';
|
||||
|
||||
const HIDDEN_HTML_ELEMENTS: ReadonlySet<string> =
|
||||
new Set(['html', 'script', 'noscript', 'base', 'body', 'title', 'head', 'link']);
|
||||
|
@ -629,11 +629,11 @@ function angularAttributes(info: AstResult, elementName: string): AngularAttribu
|
|||
continue;
|
||||
}
|
||||
const summary = selectorMap.get(selector) !;
|
||||
const isTemplateRef = hasTemplateReference(summary.type);
|
||||
const hasTemplateRef = isStructuralDirective(summary.type);
|
||||
// attributes are listed in (attribute, value) pairs
|
||||
for (let i = 0; i < selector.attrs.length; i += 2) {
|
||||
const attr = selector.attrs[i];
|
||||
if (isTemplateRef) {
|
||||
if (hasTemplateRef) {
|
||||
templateRefs.add(attr);
|
||||
} else {
|
||||
others.add(attr);
|
||||
|
|
|
@ -56,9 +56,11 @@ export function isNarrower(spanA: Span, spanB: Span): boolean {
|
|||
return spanA.start >= spanB.start && spanA.end <= spanB.end;
|
||||
}
|
||||
|
||||
export function hasTemplateReference(type: CompileTypeMetadata): boolean {
|
||||
export function isStructuralDirective(type: CompileTypeMetadata): boolean {
|
||||
for (const diDep of type.diDeps) {
|
||||
if (diDep.token && identifierName(diDep.token.identifier) === Identifiers.TemplateRef.name) {
|
||||
const diDepName = identifierName(diDep.token?.identifier);
|
||||
if (diDepName === Identifiers.TemplateRef.name ||
|
||||
diDepName === Identifiers.ViewContainerRef.name) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ describe('completions', () => {
|
|||
'ngSwitchCase',
|
||||
'ngSwitchDefault',
|
||||
'ngPluralCase',
|
||||
'ngTemplateOutlet',
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue