diff --git a/packages/compiler-cli/src/ngtsc/typecheck/api/checker.ts b/packages/compiler-cli/src/ngtsc/typecheck/api/checker.ts index 4358c46240f..633934a3c5c 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/api/checker.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/api/checker.ts @@ -14,7 +14,7 @@ import {ErrorCode} from '../../diagnostics'; import {FullTemplateMapping, NgTemplateDiagnostic, TypeCheckableDirectiveMeta} from './api'; import {GlobalCompletion} from './completion'; -import {DirectiveInScope, PipeInScope} from './scope'; +import {PipeInScope, PotentialDirective} from './scope'; import {ElementSymbol, Symbol, TcbLocation, TemplateSymbol} from './symbols'; /** @@ -131,7 +131,7 @@ export interface TemplateTypeChecker { /** * Get basic metadata on the directives which are in scope for the given component. */ - getDirectivesInScope(component: ts.ClassDeclaration): DirectiveInScope[]|null; + getDirectivesInScope(component: ts.ClassDeclaration): PotentialDirective[]|null; /** * Get basic metadata on the pipes which are in scope for the given component. @@ -139,11 +139,11 @@ export interface TemplateTypeChecker { getPipesInScope(component: ts.ClassDeclaration): PipeInScope[]|null; /** - * Retrieve a `Map` of potential template element tags, to either the `DirectiveInScope` that + * Retrieve a `Map` of potential template element tags, to either the `PotentialDirective` that * declares them (if the tag is from a directive/component), or `null` if the tag originates from * the DOM schema. */ - getPotentialElementTags(component: ts.ClassDeclaration): Map; + getPotentialElementTags(component: ts.ClassDeclaration): Map; /** * Get the primary decorator for an Angular class (such as @Component). This does not work for diff --git a/packages/compiler-cli/src/ngtsc/typecheck/api/scope.ts b/packages/compiler-cli/src/ngtsc/typecheck/api/scope.ts index fc83da8b1c6..6235350d501 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/api/scope.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/api/scope.ts @@ -14,7 +14,7 @@ import {SymbolWithValueDeclaration} from '../../util/src/typescript'; /** * Metadata on a directive which is available in the scope of a template. */ -export interface DirectiveInScope { +export interface PotentialDirective { /** * The `ts.Symbol` for the directive class. */ diff --git a/packages/compiler-cli/src/ngtsc/typecheck/api/symbols.ts b/packages/compiler-cli/src/ngtsc/typecheck/api/symbols.ts index 010d8f989f0..219a23ca048 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/api/symbols.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/api/symbols.ts @@ -12,7 +12,7 @@ import ts from 'typescript'; import {AbsoluteFsPath} from '../../file_system'; import {SymbolWithValueDeclaration} from '../../util/src/typescript'; -import {DirectiveInScope} from './scope'; +import {PotentialDirective} from './scope'; export enum SymbolKind { Input, @@ -262,7 +262,7 @@ export interface TemplateSymbol { * A representation of a directive/component whose selector matches a node in a component * template. */ -export interface DirectiveSymbol extends DirectiveInScope { +export interface DirectiveSymbol extends PotentialDirective { kind: SymbolKind.Directive; /** The `ts.Type` for the class declaration. */ diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts index aa988ccc2d3..d604b33bd93 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/checker.ts @@ -20,7 +20,7 @@ import {ClassDeclaration, isNamedClassDeclaration, ReflectionHost} from '../../r import {ComponentScopeKind, ComponentScopeReader, TypeCheckScopeRegistry} from '../../scope'; import {isShim} from '../../shims'; import {getSourceFileOrNull, isSymbolWithValueDeclaration} from '../../util/src/typescript'; -import {DirectiveInScope, ElementSymbol, FullTemplateMapping, GlobalCompletion, NgTemplateDiagnostic, OptimizeFor, PipeInScope, ProgramTypeCheckAdapter, Symbol, TcbLocation, TemplateDiagnostic, TemplateId, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta, TypeCheckingConfig} from '../api'; +import {ElementSymbol, FullTemplateMapping, GlobalCompletion, NgTemplateDiagnostic, OptimizeFor, PipeInScope, PotentialDirective, ProgramTypeCheckAdapter, Symbol, TcbLocation, TemplateDiagnostic, TemplateId, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta, TypeCheckingConfig} from '../api'; import {makeTemplateDiagnostic} from '../diagnostics'; import {CompletionEngine} from './completion'; @@ -75,7 +75,7 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker { * destroyed when the `ts.Program` changes and the `TemplateTypeCheckerImpl` as a whole is * destroyed and replaced. */ - private elementTagCache = new Map>(); + private elementTagCache = new Map>(); private isComplete = false; @@ -549,7 +549,7 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker { return builder; } - getDirectivesInScope(component: ts.ClassDeclaration): DirectiveInScope[]|null { + getDirectivesInScope(component: ts.ClassDeclaration): PotentialDirective[]|null { const data = this.getScopeData(component); if (data === null) { return null; @@ -572,12 +572,12 @@ export class TemplateTypeCheckerImpl implements TemplateTypeChecker { return this.typeCheckScopeRegistry.getTypeCheckDirectiveMetadata(new Reference(dir)); } - getPotentialElementTags(component: ts.ClassDeclaration): Map { + getPotentialElementTags(component: ts.ClassDeclaration): Map { if (this.elementTagCache.has(component)) { return this.elementTagCache.get(component)!; } - const tagMap = new Map(); + const tagMap = new Map(); for (const tag of REGISTRY.allKnownElementNames()) { tagMap.set(tag, null); @@ -886,7 +886,7 @@ class SingleShimTypeCheckingHost extends SingleFileTypeCheckingHost { * Cached scope information for a component. */ interface ScopeData { - directives: DirectiveInScope[]; + directives: PotentialDirective[]; pipes: PipeInScope[]; isPoisoned: boolean; } diff --git a/packages/language-service/src/attribute_completions.ts b/packages/language-service/src/attribute_completions.ts index 63d4ccfec3b..c844b92677d 100644 --- a/packages/language-service/src/attribute_completions.ts +++ b/packages/language-service/src/attribute_completions.ts @@ -7,7 +7,7 @@ */ import {CssSelector, SelectorMatcher, TmplAstElement, TmplAstTemplate} from '@angular/compiler'; -import {DirectiveInScope, ElementSymbol, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta} from '@angular/compiler-cli/src/ngtsc/typecheck/api'; +import {ElementSymbol, PotentialDirective, TemplateSymbol, TemplateTypeChecker, TypeCheckableDirectiveMeta} from '@angular/compiler-cli/src/ngtsc/typecheck/api'; import ts from 'typescript'; import {DisplayInfoKind, unsafeCastDisplayInfoKindToScriptElementKind} from './display_parts'; @@ -116,7 +116,7 @@ export interface DirectiveAttributeCompletion { /** * The directive whose selector gave rise to this completion. */ - directive: DirectiveInScope; + directive: PotentialDirective; } /** @@ -135,7 +135,7 @@ export interface DirectiveInputCompletion { /** * The directive which has this input. */ - directive: DirectiveInScope; + directive: PotentialDirective; /** * The field name on the directive class which corresponds to this input. @@ -164,7 +164,7 @@ export interface DirectiveOutputCompletion { /** *The directive which has this output. */ - directive: DirectiveInScope; + directive: PotentialDirective; /** * The field name on the directive class which corresponds to this output. @@ -251,7 +251,8 @@ export function buildAttributeCompletionTable( // Next, explore hypothetical directives and determine if the addition of any single attributes // can cause the directive to match the element. - const directivesInScope = checker.getDirectivesInScope(component); + const directivesInScope = + checker.getPotentialTemplateDirectives(component).filter(d => d.isInScope); if (directivesInScope !== null) { const elementSelector = makeElementSelector(element); diff --git a/packages/language-service/src/completions.ts b/packages/language-service/src/completions.ts index 435e1021a95..fb28952f4db 100644 --- a/packages/language-service/src/completions.ts +++ b/packages/language-service/src/completions.ts @@ -8,7 +8,7 @@ import {AST, ASTWithSource, BindingPipe, BindingType, Call, EmptyExpr, ImplicitReceiver, LiteralPrimitive, ParsedEventType, ParseSourceSpan, PropertyRead, PropertyWrite, SafePropertyRead, TmplAstBoundAttribute, TmplAstBoundEvent, TmplAstElement, TmplAstNode, TmplAstReference, TmplAstTemplate, TmplAstText, TmplAstTextAttribute, TmplAstVariable} from '@angular/compiler'; import {NgCompiler} from '@angular/compiler-cli/src/ngtsc/core'; -import {CompletionKind, DirectiveInScope, SymbolKind, TemplateDeclarationSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api'; +import {CompletionKind, PotentialDirective, SymbolKind, TemplateDeclarationSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api'; import {BoundEvent, TextAttribute} from '@angular/compiler/src/render3/r3_ast'; import ts from 'typescript'; @@ -905,7 +905,7 @@ function makeReplacementSpanFromAst(node: PropertyRead|PropertyWrite|SafePropert }; } -function tagCompletionKind(directive: DirectiveInScope|null): ts.ScriptElementKind { +function tagCompletionKind(directive: PotentialDirective|null): ts.ScriptElementKind { let kind: DisplayInfoKind; if (directive === null) { kind = DisplayInfoKind.ELEMENT; diff --git a/packages/language-service/src/display_parts.ts b/packages/language-service/src/display_parts.ts index 6d12d2dd4dc..2d8f6197122 100644 --- a/packages/language-service/src/display_parts.ts +++ b/packages/language-service/src/display_parts.ts @@ -7,7 +7,7 @@ */ import {isNamedClassDeclaration} from '@angular/compiler-cli/src/ngtsc/reflection'; -import {DirectiveInScope, ReferenceSymbol, Symbol, SymbolKind, TcbLocation, VariableSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api'; +import {PotentialDirective, ReferenceSymbol, Symbol, SymbolKind, TcbLocation, VariableSymbol} from '@angular/compiler-cli/src/ngtsc/typecheck/api'; import ts from 'typescript'; @@ -130,7 +130,7 @@ function getDocumentationFromTypeDefAtLocation( } export function getDirectiveDisplayInfo( - tsLS: ts.LanguageService, dir: DirectiveInScope): DisplayInfo { + tsLS: ts.LanguageService, dir: PotentialDirective): DisplayInfo { const kind = dir.isComponent ? DisplayInfoKind.COMPONENT : DisplayInfoKind.DIRECTIVE; const decl = dir.tsSymbol.declarations.find(ts.isClassDeclaration); if (decl === undefined || decl.name === undefined) {