Skip to content

Commit ffc21e5

Browse files
suicaiisaduan
andauthored
Skip invalid completion check immediately after newline (#55061)
Co-authored-by: Isabel Duan <[email protected]>
1 parent 77a2f64 commit ffc21e5

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/services/completions.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4666,6 +4666,10 @@ function getCompletionData(
46664666
return undefined;
46674667
}
46684668

4669+
function isInDifferentLineThanContextToken(contextToken: Node, position: number): boolean {
4670+
return sourceFile.getLineEndOfPosition(contextToken.getEnd()) < position;
4671+
}
4672+
46694673
/**
46704674
* @returns true if we are certain that the currently edited location must define a new location; false otherwise.
46714675
*/
@@ -4733,15 +4737,24 @@ function getCompletionData(
47334737
case SyntaxKind.SetKeyword:
47344738
return !isFromObjectTypeDeclaration(contextToken);
47354739

4736-
case SyntaxKind.Identifier:
4740+
case SyntaxKind.Identifier: {
47374741
if (containingNodeKind === SyntaxKind.ImportSpecifier &&
47384742
contextToken === (parent as ImportSpecifier).name &&
47394743
(contextToken as Identifier).text === "type"
47404744
) {
47414745
// import { type | }
47424746
return false;
47434747
}
4748+
const ancestorVariableDeclaration = findAncestor(
4749+
contextToken.parent, isVariableDeclaration);
4750+
if (ancestorVariableDeclaration
4751+
&& isInDifferentLineThanContextToken(contextToken, position)) {
4752+
// let a
4753+
// |
4754+
return false;
4755+
}
47444756
break;
4757+
}
47454758

47464759
case SyntaxKind.ClassKeyword:
47474760
case SyntaxKind.EnumKeyword:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// issue: https://github.com/microsoft/TypeScript/issues/54729
4+
// Tests that `isCompletionListBlocker` returns true at position 1, and returns false after a newline.
5+
6+
7+
////let foo /*1*/
8+
/////*2*/
9+
/////*3*/
10+
11+
verify.completions(
12+
{ marker: "1", exact: undefined },
13+
{
14+
marker: ["2", "3"],
15+
exact: completion.globalsPlus([
16+
{
17+
name: "foo",
18+
},
19+
]),
20+
}
21+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// issue: https://github.com/microsoft/TypeScript/issues/54729
4+
// Tests that `isCompletionListBlocker` returns true at position 1, and returns false after a newline.
5+
6+
////let foo = 5 as const /*1*/
7+
/////*2*/
8+
9+
verify.completions(
10+
{ marker: "1", exact: undefined },
11+
{
12+
marker: "2",
13+
exact: completion.globalsPlus([
14+
{
15+
name: "foo",
16+
},
17+
]),
18+
}
19+
);

0 commit comments

Comments
 (0)