mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Skip invalid completion check immediately after newline (#55061)
Co-authored-by: Isabel Duan <isabelduan@microsoft.com>
This commit is contained in:
parent
77a2f64810
commit
ffc21e5752
@ -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:
|
||||
|
||||
21
tests/cases/fourslash/completionAfterNewline.ts
Normal file
21
tests/cases/fourslash/completionAfterNewline.ts
Normal 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",
|
||||
},
|
||||
]),
|
||||
}
|
||||
);
|
||||
19
tests/cases/fourslash/completionAfterNewline2.ts
Normal file
19
tests/cases/fourslash/completionAfterNewline2.ts
Normal 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",
|
||||
},
|
||||
]),
|
||||
}
|
||||
);
|
||||
Loading…
x
Reference in New Issue
Block a user