Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-service): propagate attribute completion display parts #42472

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/language-service/ivy/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,18 +575,25 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
displayParts = info.displayParts;
documentation = info.documentation;
break;
case AttributeCompletionKind.StructuralDirectiveAttribute:
case AttributeCompletionKind.DirectiveInput:
case AttributeCompletionKind.DirectiveOutput:
const propertySymbol = getAttributeCompletionSymbol(completion, this.typeChecker);
if (propertySymbol === null) {
return undefined;
}

let kind: DisplayInfoKind;
if (completion.kind === AttributeCompletionKind.DirectiveInput) {
kind = DisplayInfoKind.PROPERTY;
} else if (completion.kind === AttributeCompletionKind.DirectiveOutput) {
kind = DisplayInfoKind.EVENT;
} else {
kind = DisplayInfoKind.DIRECTIVE;
atscott marked this conversation as resolved.
Show resolved Hide resolved
}

info = getTsSymbolDisplayInfo(
this.tsLS, this.typeChecker, propertySymbol,
completion.kind === AttributeCompletionKind.DirectiveInput ? DisplayInfoKind.PROPERTY :
DisplayInfoKind.EVENT,
completion.directive.tsSymbol.name);
this.tsLS, this.typeChecker, propertySymbol, kind, completion.directive.tsSymbol.name);
if (info === null) {
return undefined;
}
Expand All @@ -598,7 +605,7 @@ export class CompletionBuilder<N extends TmplAstNode|AST> {
name: entryName,
kind: unsafeCastDisplayInfoKindToScriptElementKind(kind),
kindModifiers: ts.ScriptElementKindModifier.none,
displayParts: [],
displayParts,
documentation,
};
}
Expand Down
5 changes: 4 additions & 1 deletion packages/language-service/ivy/display_parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

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

Expand Down Expand Up @@ -155,7 +156,9 @@ export function getTsSymbolDisplayInfo(
tsLS: ts.LanguageService, checker: ts.TypeChecker, symbol: ts.Symbol, kind: DisplayInfoKind,
ownerName: string|null): DisplayInfo|null {
const decl = symbol.valueDeclaration;
if (decl === undefined || (!ts.isPropertyDeclaration(decl) && !ts.isMethodDeclaration(decl)) ||
if (decl === undefined ||
(!ts.isPropertyDeclaration(decl) && !ts.isMethodDeclaration(decl) &&
!isNamedClassDeclaration(decl)) ||
!ts.isIdentifier(decl.name)) {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/language-service/ivy/test/completions_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ describe('completions', () => {
unsafeCastDisplayInfoKindToScriptElementKind(DisplayInfoKind.DIRECTIVE),
['ngFor']);
expectReplacementText(completions, templateFile.contents, 'ng');
const details = templateFile.getCompletionEntryDetails(
'ngFor', /* formatOptions */ undefined,
/* preferences */ undefined)!;
expect(toText(details.displayParts)).toEqual('(directive) NgFor.NgFor: NgFor');
atscott marked this conversation as resolved.
Show resolved Hide resolved
});

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