1 | /**
|
2 | * @license
|
3 | * Copyright Google LLC All Rights Reserved.
|
4 | *
|
5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | * found in the LICENSE file at https://angular.io/license
|
7 | */
|
8 | /// <amd-module name="@angular/language-service/ivy/attribute_completions" />
|
9 | import { TmplAstElement, TmplAstTemplate } from '@angular/compiler';
|
10 | import { DirectiveInScope, TemplateTypeChecker } from '@angular/compiler-cli/src/ngtsc/typecheck/api';
|
11 | import * as ts from 'typescript';
|
12 | /**
|
13 | * Differentiates different kinds of `AttributeCompletion`s.
|
14 | */
|
15 | export declare enum AttributeCompletionKind {
|
16 | /**
|
17 | * Completion of an attribute from the HTML schema.
|
18 | *
|
19 | * Attributes often have a corresponding DOM property of the same name.
|
20 | */
|
21 | DomAttribute = 0,
|
22 | /**
|
23 | * Completion of a property from the DOM schema.
|
24 | *
|
25 | * `DomProperty` completions are generated only for properties which don't share their name with
|
26 | * an HTML attribute.
|
27 | */
|
28 | DomProperty = 1,
|
29 | /**
|
30 | * Completion of an attribute that results in a new directive being matched on an element.
|
31 | */
|
32 | DirectiveAttribute = 2,
|
33 | /**
|
34 | * Completion of an attribute that results in a new structural directive being matched on an
|
35 | * element.
|
36 | */
|
37 | StructuralDirectiveAttribute = 3,
|
38 | /**
|
39 | * Completion of an input from a directive which is either present on the element, or becomes
|
40 | * present after the addition of this attribute.
|
41 | */
|
42 | DirectiveInput = 4,
|
43 | /**
|
44 | * Completion of an output from a directive which is either present on the element, or becomes
|
45 | * present after the addition of this attribute.
|
46 | */
|
47 | DirectiveOutput = 5
|
48 | }
|
49 | /**
|
50 | * Completion of an attribute from the DOM schema.
|
51 | */
|
52 | export interface DomAttributeCompletion {
|
53 | kind: AttributeCompletionKind.DomAttribute;
|
54 | /**
|
55 | * Name of the HTML attribute (not to be confused with the corresponding DOM property name).
|
56 | */
|
57 | attribute: string;
|
58 | /**
|
59 | * Whether this attribute is also a DOM property.
|
60 | */
|
61 | isAlsoProperty: boolean;
|
62 | }
|
63 | /**
|
64 | * Completion of a DOM property of an element that's distinct from an HTML attribute.
|
65 | */
|
66 | export interface DomPropertyCompletion {
|
67 | kind: AttributeCompletionKind.DomProperty;
|
68 | /**
|
69 | * Name of the DOM property
|
70 | */
|
71 | property: string;
|
72 | }
|
73 | /**
|
74 | * Completion of an attribute which results in a new directive being matched on an element.
|
75 | */
|
76 | export interface DirectiveAttributeCompletion {
|
77 | kind: AttributeCompletionKind.DirectiveAttribute | AttributeCompletionKind.StructuralDirectiveAttribute;
|
78 | /**
|
79 | * Name of the attribute whose addition causes this directive to match the element.
|
80 | */
|
81 | attribute: string;
|
82 | /**
|
83 | * The directive whose selector gave rise to this completion.
|
84 | */
|
85 | directive: DirectiveInScope;
|
86 | }
|
87 | /**
|
88 | * Completion of an input of a directive which may either be present on the element, or become
|
89 | * present when a binding to this input is added.
|
90 | */
|
91 | export interface DirectiveInputCompletion {
|
92 | kind: AttributeCompletionKind.DirectiveInput;
|
93 | /**
|
94 | * The public property name of the input (the name which would be used in any binding to that
|
95 | * input).
|
96 | */
|
97 | propertyName: string;
|
98 | /**
|
99 | * The directive which has this input.
|
100 | */
|
101 | directive: DirectiveInScope;
|
102 | /**
|
103 | * The field name on the directive class which corresponds to this input.
|
104 | *
|
105 | * Currently, in the case where a single property name corresponds to multiple input fields, only
|
106 | * the first such field is represented here. In the future multiple results may be warranted.
|
107 | */
|
108 | classPropertyName: string;
|
109 | /**
|
110 | * Whether this input can be used with two-way binding (that is, whether a corresponding change
|
111 | * output exists on the directive).
|
112 | */
|
113 | twoWayBindingSupported: boolean;
|
114 | }
|
115 | export interface DirectiveOutputCompletion {
|
116 | kind: AttributeCompletionKind.DirectiveOutput;
|
117 | /**
|
118 | * The public event name of the output (the name which would be used in any binding to that
|
119 | * output).
|
120 | */
|
121 | eventName: string;
|
122 | /**
|
123 | *The directive which has this output.
|
124 | */
|
125 | directive: DirectiveInScope;
|
126 | /**
|
127 | * The field name on the directive class which corresponds to this output.
|
128 | */
|
129 | classPropertyName: string;
|
130 | }
|
131 | /**
|
132 | * Any named attribute which is available for completion on a given element.
|
133 | *
|
134 | * Disambiguated by the `kind` property into various types of completions.
|
135 | */
|
136 | export declare type AttributeCompletion = DomAttributeCompletion | DomPropertyCompletion | DirectiveAttributeCompletion | DirectiveInputCompletion | DirectiveOutputCompletion;
|
137 | /**
|
138 | * Given an element and its context, produce a `Map` of all possible attribute completions.
|
139 | *
|
140 | * 3 kinds of attributes are considered for completion, from highest to lowest priority:
|
141 | *
|
142 | * 1. Inputs/outputs of directives present on the element already.
|
143 | * 2. Inputs/outputs of directives that are not present on the element, but which would become
|
144 | * present if such a binding is added.
|
145 | * 3. Attributes from the DOM schema for the element.
|
146 | *
|
147 | * The priority of these options determines which completions are added to the `Map`. If a directive
|
148 | * input shares the same name as a DOM attribute, the `Map` will reflect the directive input
|
149 | * completion, not the DOM completion for that name.
|
150 | */
|
151 | export declare function buildAttributeCompletionTable(component: ts.ClassDeclaration, element: TmplAstElement | TmplAstTemplate, checker: TemplateTypeChecker): Map<string, AttributeCompletion>;
|
152 | /**
|
153 | * Given an `AttributeCompletion`, add any available completions to a `ts.CompletionEntry` array of
|
154 | * results.
|
155 | *
|
156 | * The kind of completions generated depends on whether the current context is an attribute context
|
157 | * or not. For example, completing on `<element attr|>` will generate two results: `attribute` and
|
158 | * `[attribute]` - either a static attribute can be generated, or a property binding. However,
|
159 | * `<element [attr|]>` is not an attribute context, and so only the property completion `attribute`
|
160 | * is generated. Note that this completion does not have the `[]` property binding sugar as its
|
161 | * implicitly present in a property binding context (we're already completing within an `[attr|]`
|
162 | * expression).
|
163 | */
|
164 | export declare function addAttributeCompletionEntries(entries: ts.CompletionEntry[], completion: AttributeCompletion, isAttributeContext: boolean, isElementContext: boolean, replacementSpan: ts.TextSpan | undefined): void;
|
165 | export declare function getAttributeCompletionSymbol(completion: AttributeCompletion, checker: ts.TypeChecker): ts.Symbol | null;
|