mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Test for isNewIdentifierLocation, and make true for type with index signature (#22910)
This commit is contained in:
parent
ccd6a010e0
commit
21cd68dd04
@ -840,8 +840,8 @@ namespace FourSlash {
|
||||
this.raiseError(`No completions at position '${this.currentCaretPosition}'.`);
|
||||
}
|
||||
|
||||
if (options && options.isNewIdentifierLocation !== undefined && actualCompletions.isNewIdentifierLocation !== options.isNewIdentifierLocation) {
|
||||
this.raiseError(`Expected 'isNewIdentifierLocation' to be ${options.isNewIdentifierLocation}, got ${actualCompletions.isNewIdentifierLocation}`);
|
||||
if (actualCompletions.isNewIdentifierLocation !== (options && options.isNewIdentifierLocation || false)) {
|
||||
this.raiseError(`Expected 'isNewIdentifierLocation' to be ${options && options.isNewIdentifierLocation}, got ${actualCompletions.isNewIdentifierLocation}`);
|
||||
}
|
||||
|
||||
const actual = actualCompletions.entries;
|
||||
|
||||
@ -1031,6 +1031,8 @@ namespace ts.Completions {
|
||||
}
|
||||
|
||||
function addTypeProperties(type: Type): void {
|
||||
isNewIdentifierLocation = !!type.getStringIndexType() || !!type.getNumberIndexType();
|
||||
|
||||
if (isSourceFileJavaScript(sourceFile)) {
|
||||
// In javascript files, for union types, we don't just get the members that
|
||||
// the individual types have in common, we also include all the members that
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
////function f(x: T, ...args: U[]) { };
|
||||
////f("/*1*/", "/*2*/", "/*3*/");
|
||||
|
||||
verify.completionsAt("1", ["foo", "bar"]);
|
||||
verify.completionsAt("2", ["oof", "rab"]);
|
||||
verify.completionsAt("3", ["oof", "rab"]);
|
||||
// TODO: GH#22907
|
||||
const options = { isNewIdentifierLocation: true };
|
||||
verify.completionsAt("1", ["foo", "bar"], options);
|
||||
verify.completionsAt("2", ["oof", "rab"], options);
|
||||
verify.completionsAt("3", ["oof", "rab"], options);
|
||||
|
||||
@ -7,10 +7,4 @@
|
||||
////
|
||||
////declare function foo<TString, TNumber>(obj: I<TString, TNumber>): { /*1*/ }
|
||||
|
||||
goTo.marker("1");
|
||||
|
||||
verify.not.completionListContains("I");
|
||||
verify.not.completionListContains("TString");
|
||||
verify.not.completionListContains("TNumber");
|
||||
verify.not.completionListContains("foo");
|
||||
verify.not.completionListContains("obj");
|
||||
verify.completionsAt("1", ["readonly"], { isNewIdentifierLocation: true });
|
||||
|
||||
@ -17,4 +17,4 @@ verify.completionsAt("1", [
|
||||
{ name: "@a/b", replacementSpan },
|
||||
{ name: "@c/d", replacementSpan },
|
||||
{ name: "@e/f", replacementSpan },
|
||||
]);
|
||||
], { isNewIdentifierLocation: true });
|
||||
|
||||
@ -14,4 +14,4 @@
|
||||
// Confirm that entries are de-dup'd.
|
||||
verify.completionsAt("1", [
|
||||
{ name: "@a/b", replacementSpan: test.ranges()[0] },
|
||||
]);
|
||||
], { isNewIdentifierLocation: true });
|
||||
|
||||
@ -7,4 +7,4 @@
|
||||
////
|
||||
////declare function foo<TString, TNumber>(obj: I<TString, TNumber>): { /*1*/
|
||||
|
||||
verify.completionsAt("1", ["readonly"]);
|
||||
verify.completionsAt("1", ["readonly"], { isNewIdentifierLocation: true });
|
||||
|
||||
@ -14,7 +14,8 @@
|
||||
////x[|./*a*/|];
|
||||
////x["/*b*/"];
|
||||
|
||||
verify.completionsAt("b", ["foo ", "bar", "break", "any", "#", "$", "b", "1b"]);
|
||||
// TODO: GH#22907
|
||||
verify.completionsAt("b", ["foo ", "bar", "break", "any", "#", "$", "b", "1b"], { isNewIdentifierLocation: true });
|
||||
|
||||
const replacementSpan = test.ranges()[0];
|
||||
verify.completionsAt("a", [
|
||||
|
||||
@ -311,7 +311,7 @@ goToMarkAndGeneralVerify('class', { isClassScope: true });
|
||||
//verify.not.completionListContains('ceVar');
|
||||
|
||||
// from interface in mod1
|
||||
verify.completionsAt("interface", ["readonly"]);
|
||||
verify.completionsAt("interface", ["readonly"], { isNewIdentifierLocation: true });
|
||||
|
||||
// from namespace in mod1
|
||||
verifyNamespaceInMod1('namespace');
|
||||
@ -348,7 +348,7 @@ verify.not.completionListContains('ceFunc');
|
||||
verify.not.completionListContains('ceVar');
|
||||
|
||||
// from exported interface in mod1
|
||||
verify.completionsAt("exportedInterface", ["readonly"]);
|
||||
verify.completionsAt("exportedInterface", ["readonly"], { isNewIdentifierLocation: true });
|
||||
|
||||
// from exported namespace in mod1
|
||||
verifyExportedNamespace('exportedNamespace');
|
||||
|
||||
@ -14,5 +14,5 @@
|
||||
////interface EndOfFile { f; /*e*/
|
||||
|
||||
for (const marker of test.markerNames()) {
|
||||
verify.completionsAt(marker, ["readonly"]);
|
||||
verify.completionsAt(marker, ["readonly"], { isNewIdentifierLocation: true });
|
||||
}
|
||||
|
||||
@ -7,4 +7,5 @@
|
||||
////const x = { p: "x" };
|
||||
////x.p = "/**/";
|
||||
|
||||
verify.completionsAt("", ["x", "y"]);
|
||||
// TODO: GH#22907
|
||||
verify.completionsAt("", ["x", "y"], { isNewIdentifierLocation: true });
|
||||
|
||||
@ -4,4 +4,4 @@
|
||||
// @Filename: /a.js
|
||||
////const x = /** @type {{ s: string }} */ ({ /**/ });
|
||||
|
||||
verify.completionsAt("", ["s", "x"]);
|
||||
verify.completionsAt("", ["s", "x"], { isNewIdentifierLocation: true });
|
||||
|
||||
@ -24,7 +24,8 @@
|
||||
////const foo = require(`x/[|/*4*/|]`);
|
||||
|
||||
const [r0, r1, r2, r3] = test.ranges();
|
||||
verify.completionsAt("1", [{ name: "y", replacementSpan: r0 }, { name: "x", replacementSpan: r0 }]);
|
||||
verify.completionsAt("2", [{ name: "bar", replacementSpan: r1 }, { name: "foo", replacementSpan: r1 }]);
|
||||
verify.completionsAt("3", [{ name: "bar", replacementSpan: r2 }, { name: "foo", replacementSpan: r2 }]);
|
||||
verify.completionsAt("4", [{ name: "bar", replacementSpan: r3 }, { name: "foo", replacementSpan: r3 }]);
|
||||
const options = { isNewIdentifierLocation: true };
|
||||
verify.completionsAt("1", [{ name: "y", replacementSpan: r0 }, { name: "x", replacementSpan: r0 }], options);
|
||||
verify.completionsAt("2", [{ name: "bar", replacementSpan: r1 }, { name: "foo", replacementSpan: r1 }], options);
|
||||
verify.completionsAt("3", [{ name: "bar", replacementSpan: r2 }, { name: "foo", replacementSpan: r2 }], options);
|
||||
verify.completionsAt("4", [{ name: "bar", replacementSpan: r3 }, { name: "foo", replacementSpan: r3 }], options);
|
||||
|
||||
@ -21,5 +21,5 @@
|
||||
////}
|
||||
|
||||
const [r0, r1] = test.ranges();
|
||||
verify.completionsAt("0", ["a", "b", "dir"].map(name => ({ name, replacementSpan: r0 })));
|
||||
verify.completionsAt("1", ["x"].map(name => ({ name, replacementSpan: r1 })));
|
||||
verify.completionsAt("0", ["a", "b", "dir"].map(name => ({ name, replacementSpan: r0 })), { isNewIdentifierLocation: true });
|
||||
verify.completionsAt("1", ["x"].map(name => ({ name, replacementSpan: r1 })), { isNewIdentifierLocation: true });
|
||||
|
||||
@ -17,4 +17,4 @@
|
||||
////}
|
||||
|
||||
const [replacementSpan] = test.ranges();
|
||||
verify.completionsAt("", [{ name: "x", replacementSpan }]);
|
||||
verify.completionsAt("", [{ name: "x", replacementSpan }], { isNewIdentifierLocation: true });
|
||||
|
||||
@ -20,4 +20,4 @@
|
||||
////}
|
||||
|
||||
const [replacementSpan] = test.ranges();
|
||||
verify.completionsAt("", ["a", "b"].map(name => ({ name, replacementSpan })));
|
||||
verify.completionsAt("", ["a", "b"].map(name => ({ name, replacementSpan })), { isNewIdentifierLocation: true });
|
||||
|
||||
@ -14,4 +14,4 @@
|
||||
////}
|
||||
|
||||
const [replacementSpan] = test.ranges();
|
||||
verify.completionsAt("", ["src", "foo/"].map(name => ({ name, replacementSpan })));
|
||||
verify.completionsAt("", ["src", "foo/"].map(name => ({ name, replacementSpan })), { isNewIdentifierLocation: true });
|
||||
|
||||
@ -3,4 +3,5 @@
|
||||
////interface Foo { foo: string; bar: string; }
|
||||
////type T = Pick<Foo, "/**/">;
|
||||
|
||||
verify.completionsAt("", ["foo", "bar"]);
|
||||
// TODO: GH#22907
|
||||
verify.completionsAt("", ["foo", "bar"], { isNewIdentifierLocation: true });
|
||||
|
||||
@ -7,4 +7,5 @@
|
||||
|
||||
// We specifically filter out any array-like types.
|
||||
// Private members will be excluded by `createUnionOrIntersectionProperty`.
|
||||
verify.completionsAt("", ["x"]);
|
||||
// TODO: GH#22907
|
||||
verify.completionsAt("", ["x"], { isNewIdentifierLocation: true });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user