Skip to content

Commit a493ea9

Browse files
atscottthePunderWoman
authored andcommitted
fix(language-service): fix autocomplete info display for some cases (#42472)
Before this commit, attribute completion display parts were retrieved but not assigned. In addition, the switch case was non-exhaustive because it did not include `StructuralDirectiveAttribute`. PR Close #42472
1 parent f85a120 commit a493ea9

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

packages/language-service/ivy/completions.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -579,18 +579,25 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
579579
displayParts = info.displayParts;
580580
documentation = info.documentation;
581581
break;
582+
case AttributeCompletionKind.StructuralDirectiveAttribute:
582583
case AttributeCompletionKind.DirectiveInput:
583584
case AttributeCompletionKind.DirectiveOutput:
584585
const propertySymbol = getAttributeCompletionSymbol(completion, this.typeChecker);
585586
if (propertySymbol === null) {
586587
return undefined;
587588
}
588589

590+
let kind: DisplayInfoKind;
591+
if (completion.kind === AttributeCompletionKind.DirectiveInput) {
592+
kind = DisplayInfoKind.PROPERTY;
593+
} else if (completion.kind === AttributeCompletionKind.DirectiveOutput) {
594+
kind = DisplayInfoKind.EVENT;
595+
} else {
596+
kind = DisplayInfoKind.DIRECTIVE;
597+
}
598+
589599
info = getTsSymbolDisplayInfo(
590-
this.tsLS, this.typeChecker, propertySymbol,
591-
completion.kind === AttributeCompletionKind.DirectiveInput ? DisplayInfoKind.PROPERTY :
592-
DisplayInfoKind.EVENT,
593-
completion.directive.tsSymbol.name);
600+
this.tsLS, this.typeChecker, propertySymbol, kind, completion.directive.tsSymbol.name);
594601
if (info === null) {
595602
return undefined;
596603
}
@@ -602,7 +609,7 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
602609
name: entryName,
603610
kind: unsafeCastDisplayInfoKindToScriptElementKind(kind),
604611
kindModifiers: ts.ScriptElementKindModifier.none,
605-
displayParts: [],
612+
displayParts,
606613
documentation,
607614
};
608615
}

packages/language-service/ivy/display_parts.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {isNamedClassDeclaration} from '@angular/compiler-cli/src/ngtsc/reflection';
910
import {DirectiveInScope, ReferenceSymbol, ShimLocation, Symbol, SymbolKind, VariableSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api';
1011
import * as ts from 'typescript';
1112

@@ -155,7 +156,9 @@ export function getTsSymbolDisplayInfo(
155156
tsLS: ts.LanguageService, checker: ts.TypeChecker, symbol: ts.Symbol, kind: DisplayInfoKind,
156157
ownerName: string|null): DisplayInfo|null {
157158
const decl = symbol.valueDeclaration;
158-
if (decl === undefined || (!ts.isPropertyDeclaration(decl) && !ts.isMethodDeclaration(decl)) ||
159+
if (decl === undefined ||
160+
(!ts.isPropertyDeclaration(decl) && !ts.isMethodDeclaration(decl) &&
161+
!isNamedClassDeclaration(decl)) ||
159162
!ts.isIdentifier(decl.name)) {
160163
return null;
161164
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ describe('completions', () => {
586586
unsafeCastDisplayInfoKindToScriptElementKind(DisplayInfoKind.DIRECTIVE),
587587
['ngFor']);
588588
expectReplacementText(completions, templateFile.contents, 'ng');
589+
const details = templateFile.getCompletionEntryDetails(
590+
'ngFor', /* formatOptions */ undefined,
591+
/* preferences */ undefined)!;
592+
expect(toText(details.displayParts)).toEqual('(directive) NgFor.NgFor: NgFor');
589593
});
590594

591595
it('should return structural directive completions for just the structural marker', () => {

0 commit comments

Comments
 (0)