Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aace1e7

Browse filesBrowse files
ivanwonderatscott
authored andcommitted
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
1 parent fbfec94 commit aace1e7
Copy full SHA for aace1e7

File tree

Expand file treeCollapse file tree

2 files changed

+26
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-1
lines changed

‎packages/compiler-cli/src/ngtsc/typecheck/src/completion.ts

Copy file name to clipboardExpand all lines: packages/compiler-cli/src/ngtsc/typecheck/src/completion.ts
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {TmplAstReference, TmplAstTemplate} from '@angular/compiler';
10-
import {AST, EmptyExpr, LiteralPrimitive, MethodCall, PropertyRead, PropertyWrite, SafeMethodCall, SafePropertyRead, TmplAstNode} from '@angular/compiler/src/compiler';
10+
import {AST, EmptyExpr, ImplicitReceiver, LiteralPrimitive, MethodCall, PropertyRead, PropertyWrite, SafeMethodCall, SafePropertyRead, TmplAstNode} from '@angular/compiler/src/compiler';
1111
import {TextAttribute} from '@angular/compiler/src/render3/r3_ast';
1212
import * as ts from 'typescript';
1313

@@ -91,6 +91,19 @@ export class CompletionEngine {
9191
}
9292
}
9393

94+
if (node instanceof PropertyRead && node.receiver instanceof ImplicitReceiver) {
95+
const nodeLocation = findFirstMatchingNode(this.tcb, {
96+
filter: ts.isPropertyAccessExpression,
97+
withSpan: node.sourceSpan,
98+
});
99+
if (nodeLocation) {
100+
nodeContext = {
101+
shimPath: this.shimPath,
102+
positionInShimFile: nodeLocation.getStart(),
103+
};
104+
}
105+
}
106+
94107
return {
95108
componentContext: this.componentContext,
96109
templateContext,

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

Copy file name to clipboardExpand all lines: packages/language-service/ivy/test/completions_spec.ts
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,18 @@ describe('completions', () => {
234234
const {templateFile} = setup(`<input dir [myInput]="">`, '', DIR_WITH_UNION_TYPE_INPUT);
235235
templateFile.moveCursorToText('dir [myInput]="¦">');
236236

237+
const completions = templateFile.getCompletionsAtPosition();
238+
expectContain(completions, ts.ScriptElementKind.string, [`'foo'`, '42']);
239+
expectContain(completions, ts.ScriptElementKind.keyword, ['null']);
240+
expectContain(completions, ts.ScriptElementKind.variableElement, ['undefined']);
241+
expectDoesNotContain(completions, ts.ScriptElementKind.parameterElement, ['ctx']);
242+
});
243+
244+
it('should return completions of string literals, number literals, `true`, `false`, `null` and `undefined` when the user tries to modify the symbol',
245+
() => {
246+
const {templateFile} = setup(`<input dir [myInput]="a">`, '', DIR_WITH_UNION_TYPE_INPUT);
247+
templateFile.moveCursorToText('dir [myInput]="a¦">');
248+
237249
const completions = templateFile.getCompletionsAtPosition();
238250
expectContain(completions, ts.ScriptElementKind.string, [`'foo'`, '42']);
239251
expectContain(completions, ts.ScriptElementKind.keyword, ['null']);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.