Support import fix/completions for export = (#25708)

This commit is contained in:
Andy
2018-08-28 13:04:11 -07:00
committed by GitHub
parent b94061c587
commit 552bd1c8a2
12 changed files with 132 additions and 25 deletions

View File

@@ -11,7 +11,7 @@
////fooB/*1*/
goTo.marker("0");
const preferences = { includeCompletionsForModuleExports: true };
const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true };
verify.completions(
{ marker: "0", excludes: { name: "default", source: "/src/foo-bar" }, preferences },
{ marker: "1", includes: { name: "fooBar", source: "/src/foo-bar", sourceDisplay: "./foo-bar", text: "(property) default: 0", kind: "property", hasAction: true }, preferences }

View File

@@ -0,0 +1,53 @@
/// <reference path="fourslash.ts" />
// @module: commonjs
// @Filename: /a.d.ts
////declare function a(): void;
////declare namespace a {
//// export interface b {}
////}
////export = a;
// @Filename: /b.ts
////a/*0*/;
////let x: b/*1*/;
const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true };
verify.completions(
{
marker: "0",
includes: { name: "a", source: "/a", hasAction: true, },
preferences,
},
{
marker: "1",
includes: { name: "b", source: "/a", hasAction: true },
preferences,
}
);
// Import { b } first, or it will just add a qualified name from 'a' (which isn't what we're trying to test)
verify.applyCodeActionFromCompletion("1", {
name: "b",
source: "/a",
description: `Import 'b' from module "./a"`,
newFileContent:
`import { b } from "./a";
a;
let x: b;`,
});
verify.applyCodeActionFromCompletion("0", {
name: "a",
source: "/a",
description: `Import 'a' from module "./a"`,
newFileContent:
`import { b } from "./a";
import a = require("./a");
a;
let x: b;`,
});

View File

@@ -18,7 +18,7 @@
verify.completions({
marker: "",
// Tester will assert that it is only included once
includes: [{ name: "foo", hasAction: true }],
includes: [{ name: "foo", source: "a", hasAction: true }],
preferences: {
includeCompletionsForModuleExports: true,
}

View File

@@ -12,7 +12,7 @@
verify.completions({
marker: "",
includes: { name: "Foo", source: "/a.tsx", hasAction: true },
includes: { name: "Foo", source: "/a", hasAction: true },
excludes: "Bar",
preferences: {
includeCompletionsForModuleExports: true,

View File

@@ -24,7 +24,7 @@ verify.completions({
marker: "",
exact: [
"n",
{ name: "publicSym", insertText: "[publicSym]", replacementSpan: test.ranges()[0], hasAction: true },
{ name: "publicSym", source: "/a", insertText: "[publicSym]", replacementSpan: test.ranges()[0], hasAction: true },
],
preferences: {
includeInsertTextCompletions: true,

View File

@@ -37,11 +37,11 @@ verify.codeFixAll({
fixId: "fixMissingImport",
fixAllDescription: "Add all missing imports",
newFileContent:
// TODO: GH#25135 (should import 'e')
`import bd, * as b from "./b";
import cd, { c0 } from "./c";
import dd, { d0, d1 } from "./d";
import ad, { a0 } from "./a";
import e = require("./e");
ad; ad; a0; a0;
bd; bd; b.b0; b.b0;

View File

@@ -0,0 +1,25 @@
/// <reference path="fourslash.ts" />
// @Filename: /a.d.ts
////declare function a(): void;
////declare namespace a {
//// export interface b {}
////}
////export = a;
// @Filename: /b.ts
////a;
////let x: b;
goTo.file("/b.ts");
verify.codeFixAll({
fixId: "fixMissingImport",
fixAllDescription: "Add all missing imports",
newFileContent:
`import { b } from "./a";
import a = require("./a");
a;
let x: b;`,
});