fix(language-service): global autocomplete doesn't work when the user tries to modify the symbol (#42923)
When the user tries to trigger suggestions from an interruption, the LS should provide the global completions. For example, `[input]="t¦"`, the `t` can be the `true` or the symbol from the component context. PR Close #42923
This commit is contained in:
parent
f62366fd16
commit
f0c5ba08f6
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {TmplAstReference, TmplAstTemplate} from '@angular/compiler';
|
||||
import {AST, EmptyExpr, LiteralPrimitive, MethodCall, PropertyRead, PropertyWrite, SafeMethodCall, SafePropertyRead, TmplAstNode} from '@angular/compiler/src/compiler';
|
||||
import {AST, EmptyExpr, ImplicitReceiver, LiteralPrimitive, MethodCall, PropertyRead, PropertyWrite, SafeMethodCall, SafePropertyRead, TmplAstNode} from '@angular/compiler/src/compiler';
|
||||
import {TextAttribute} from '@angular/compiler/src/render3/r3_ast';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
|
@ -91,6 +91,19 @@ export class CompletionEngine {
|
|||
}
|
||||
}
|
||||
|
||||
if (node instanceof PropertyRead && node.receiver instanceof ImplicitReceiver) {
|
||||
const nodeLocation = findFirstMatchingNode(this.tcb, {
|
||||
filter: ts.isPropertyAccessExpression,
|
||||
withSpan: node.sourceSpan,
|
||||
});
|
||||
if (nodeLocation) {
|
||||
nodeContext = {
|
||||
shimPath: this.shimPath,
|
||||
positionInShimFile: nodeLocation.getStart(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
componentContext: this.componentContext,
|
||||
templateContext,
|
||||
|
|
|
@ -234,6 +234,18 @@ describe('completions', () => {
|
|||
const {templateFile} = setup(`<input dir [myInput]="">`, '', DIR_WITH_UNION_TYPE_INPUT);
|
||||
templateFile.moveCursorToText('dir [myInput]="¦">');
|
||||
|
||||
const completions = templateFile.getCompletionsAtPosition();
|
||||
expectContain(completions, ts.ScriptElementKind.string, [`'foo'`, '42']);
|
||||
expectContain(completions, ts.ScriptElementKind.keyword, ['null']);
|
||||
expectContain(completions, ts.ScriptElementKind.variableElement, ['undefined']);
|
||||
expectDoesNotContain(completions, ts.ScriptElementKind.parameterElement, ['ctx']);
|
||||
});
|
||||
|
||||
it('should return completions of string literals, number literals, `true`, `false`, `null` and `undefined` when the user tries to modify the symbol',
|
||||
() => {
|
||||
const {templateFile} = setup(`<input dir [myInput]="a">`, '', DIR_WITH_UNION_TYPE_INPUT);
|
||||
templateFile.moveCursorToText('dir [myInput]="a¦">');
|
||||
|
||||
const completions = templateFile.getCompletionsAtPosition();
|
||||
expectContain(completions, ts.ScriptElementKind.string, [`'foo'`, '42']);
|
||||
expectContain(completions, ts.ScriptElementKind.keyword, ['null']);
|
||||
|
|
Loading…
Reference in New Issue