Skip to content

Commit 21cd68d

Browse files
author
Andy
authored
Test for isNewIdentifierLocation, and make true for type with index signature (#22910)
1 parent ccd6a01 commit 21cd68d

19 files changed

+35
-32
lines changed

src/harness/fourslash.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,8 @@ namespace FourSlash {
840840
this.raiseError(`No completions at position '${this.currentCaretPosition}'.`);
841841
}
842842

843-
if (options && options.isNewIdentifierLocation !== undefined && actualCompletions.isNewIdentifierLocation !== options.isNewIdentifierLocation) {
844-
this.raiseError(`Expected 'isNewIdentifierLocation' to be ${options.isNewIdentifierLocation}, got ${actualCompletions.isNewIdentifierLocation}`);
843+
if (actualCompletions.isNewIdentifierLocation !== (options && options.isNewIdentifierLocation || false)) {
844+
this.raiseError(`Expected 'isNewIdentifierLocation' to be ${options && options.isNewIdentifierLocation}, got ${actualCompletions.isNewIdentifierLocation}`);
845845
}
846846

847847
const actual = actualCompletions.entries;

src/services/completions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,8 @@ namespace ts.Completions {
10311031
}
10321032

10331033
function addTypeProperties(type: Type): void {
1034+
isNewIdentifierLocation = !!type.getStringIndexType() || !!type.getNumberIndexType();
1035+
10341036
if (isSourceFileJavaScript(sourceFile)) {
10351037
// In javascript files, for union types, we don't just get the members that
10361038
// the individual types have in common, we also include all the members that

tests/cases/fourslash/completionForStringLiteral7.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
////function f(x: T, ...args: U[]) { };
66
////f("/*1*/", "/*2*/", "/*3*/");
77

8-
verify.completionsAt("1", ["foo", "bar"]);
9-
verify.completionsAt("2", ["oof", "rab"]);
10-
verify.completionsAt("3", ["oof", "rab"]);
8+
// TODO: GH#22907
9+
const options = { isNewIdentifierLocation: true };
10+
verify.completionsAt("1", ["foo", "bar"], options);
11+
verify.completionsAt("2", ["oof", "rab"], options);
12+
verify.completionsAt("3", ["oof", "rab"], options);

tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,4 @@
77
////
88
////declare function foo<TString, TNumber>(obj: I<TString, TNumber>): { /*1*/ }
99

10-
goTo.marker("1");
11-
12-
verify.not.completionListContains("I");
13-
verify.not.completionListContains("TString");
14-
verify.not.completionListContains("TNumber");
15-
verify.not.completionListContains("foo");
16-
verify.not.completionListContains("obj");
10+
verify.completionsAt("1", ["readonly"], { isNewIdentifierLocation: true });

tests/cases/fourslash/completionListInImportClause05.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ verify.completionsAt("1", [
1717
{ name: "@a/b", replacementSpan },
1818
{ name: "@c/d", replacementSpan },
1919
{ name: "@e/f", replacementSpan },
20-
]);
20+
], { isNewIdentifierLocation: true });

tests/cases/fourslash/completionListInImportClause06.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
// Confirm that entries are de-dup'd.
1515
verify.completionsAt("1", [
1616
{ name: "@a/b", replacementSpan: test.ranges()[0] },
17-
]);
17+
], { isNewIdentifierLocation: true });

tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
////
88
////declare function foo<TString, TNumber>(obj: I<TString, TNumber>): { /*1*/
99

10-
verify.completionsAt("1", ["readonly"]);
10+
verify.completionsAt("1", ["readonly"], { isNewIdentifierLocation: true });

tests/cases/fourslash/completionListInvalidMemberNames.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
////x[|./*a*/|];
1515
////x["/*b*/"];
1616

17-
verify.completionsAt("b", ["foo ", "bar", "break", "any", "#", "$", "b", "1b"]);
17+
// TODO: GH#22907
18+
verify.completionsAt("b", ["foo ", "bar", "break", "any", "#", "$", "b", "1b"], { isNewIdentifierLocation: true });
1819

1920
const replacementSpan = test.ranges()[0];
2021
verify.completionsAt("a", [

tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ goToMarkAndGeneralVerify('class', { isClassScope: true });
311311
//verify.not.completionListContains('ceVar');
312312

313313
// from interface in mod1
314-
verify.completionsAt("interface", ["readonly"]);
314+
verify.completionsAt("interface", ["readonly"], { isNewIdentifierLocation: true });
315315

316316
// from namespace in mod1
317317
verifyNamespaceInMod1('namespace');
@@ -348,7 +348,7 @@ verify.not.completionListContains('ceFunc');
348348
verify.not.completionListContains('ceVar');
349349

350350
// from exported interface in mod1
351-
verify.completionsAt("exportedInterface", ["readonly"]);
351+
verify.completionsAt("exportedInterface", ["readonly"], { isNewIdentifierLocation: true });
352352

353353
// from exported namespace in mod1
354354
verifyExportedNamespace('exportedNamespace');

tests/cases/fourslash/completionsInterfaceElement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
////interface EndOfFile { f; /*e*/
1515

1616
for (const marker of test.markerNames()) {
17-
verify.completionsAt(marker, ["readonly"]);
17+
verify.completionsAt(marker, ["readonly"], { isNewIdentifierLocation: true });
1818
}

0 commit comments

Comments
 (0)