Skip invalid completion check immediately after newline (#55061)

Co-authored-by: Isabel Duan <isabelduan@microsoft.com>
This commit is contained in:
Sg 2023-11-21 05:18:06 +08:00 committed by GitHub
parent 77a2f64810
commit ffc21e5752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 1 deletions

View File

@ -4666,6 +4666,10 @@ function getCompletionData(
return undefined;
}
function isInDifferentLineThanContextToken(contextToken: Node, position: number): boolean {
return sourceFile.getLineEndOfPosition(contextToken.getEnd()) < position;
}
/**
* @returns true if we are certain that the currently edited location must define a new location; false otherwise.
*/
@ -4733,7 +4737,7 @@ function getCompletionData(
case SyntaxKind.SetKeyword:
return !isFromObjectTypeDeclaration(contextToken);
case SyntaxKind.Identifier:
case SyntaxKind.Identifier: {
if (containingNodeKind === SyntaxKind.ImportSpecifier &&
contextToken === (parent as ImportSpecifier).name &&
(contextToken as Identifier).text === "type"
@ -4741,7 +4745,16 @@ function getCompletionData(
// import { type | }
return false;
}
const ancestorVariableDeclaration = findAncestor(
contextToken.parent, isVariableDeclaration);
if (ancestorVariableDeclaration
&& isInDifferentLineThanContextToken(contextToken, position)) {
// let a
// |
return false;
}
break;
}
case SyntaxKind.ClassKeyword:
case SyntaxKind.EnumKeyword:

View File

@ -0,0 +1,21 @@
/// <reference path="fourslash.ts" />
// issue: https://github.com/microsoft/TypeScript/issues/54729
// Tests that `isCompletionListBlocker` returns true at position 1, and returns false after a newline.
////let foo /*1*/
/////*2*/
/////*3*/
verify.completions(
{ marker: "1", exact: undefined },
{
marker: ["2", "3"],
exact: completion.globalsPlus([
{
name: "foo",
},
]),
}
);

View File

@ -0,0 +1,19 @@
/// <reference path="fourslash.ts" />
// issue: https://github.com/microsoft/TypeScript/issues/54729
// Tests that `isCompletionListBlocker` returns true at position 1, and returns false after a newline.
////let foo = 5 as const /*1*/
/////*2*/
verify.completions(
{ marker: "1", exact: undefined },
{
marker: "2",
exact: completion.globalsPlus([
{
name: "foo",
},
]),
}
);