mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Proposal: simplify auto import descriptions (#47631)
* Simplify import fix descriptions * Update tests * Fix new test
This commit is contained in:
@@ -6354,7 +6354,7 @@
|
||||
"category": "Message",
|
||||
"code": 90012
|
||||
},
|
||||
"Import '{0}' from module \"{1}\"": {
|
||||
"Import '{0}' from \"{1}\"": {
|
||||
"category": "Message",
|
||||
"code": 90013
|
||||
},
|
||||
@@ -6362,10 +6362,6 @@
|
||||
"category": "Message",
|
||||
"code": 90014
|
||||
},
|
||||
"Add '{0}' to existing import declaration from \"{1}\"": {
|
||||
"category": "Message",
|
||||
"code": 90015
|
||||
},
|
||||
"Declare property '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90016
|
||||
@@ -6430,14 +6426,6 @@
|
||||
"category": "Message",
|
||||
"code": 90031
|
||||
},
|
||||
"Import default '{0}' from module \"{1}\"": {
|
||||
"category": "Message",
|
||||
"code": 90032
|
||||
},
|
||||
"Add default import '{0}' to existing import declaration from \"{1}\"": {
|
||||
"category": "Message",
|
||||
"code": 90033
|
||||
},
|
||||
"Add parameter name": {
|
||||
"category": "Message",
|
||||
"code": 90034
|
||||
@@ -6482,6 +6470,14 @@
|
||||
"category": "Message",
|
||||
"code": 90056
|
||||
},
|
||||
"Add import from \"{0}\"": {
|
||||
"category": "Message",
|
||||
"code": 90057
|
||||
},
|
||||
"Update import from \"{0}\"": {
|
||||
"category": "Message",
|
||||
"code": 90058
|
||||
},
|
||||
|
||||
"Convert function to an ES2015 class": {
|
||||
"category": "Message",
|
||||
|
||||
@@ -20,9 +20,16 @@ namespace ts.codefix {
|
||||
const { errorCode, preferences, sourceFile, span, program } = context;
|
||||
const info = getFixesInfo(context, errorCode, span.start, /*useAutoImportProvider*/ true);
|
||||
if (!info) return undefined;
|
||||
const { fixes, symbolName } = info;
|
||||
const { fixes, symbolName, errorIdentifierText } = info;
|
||||
const quotePreference = getQuotePreference(sourceFile, preferences);
|
||||
return fixes.map(fix => codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, program.getCompilerOptions()));
|
||||
return fixes.map(fix => codeActionForFix(
|
||||
context,
|
||||
sourceFile,
|
||||
symbolName,
|
||||
fix,
|
||||
/*includeSymbolNameInDescription*/ symbolName !== errorIdentifierText,
|
||||
quotePreference,
|
||||
program.getCompilerOptions()));
|
||||
},
|
||||
fixIds: [importFixId],
|
||||
getAllCodeActions: context => {
|
||||
@@ -78,7 +85,7 @@ namespace ts.codefix {
|
||||
const useRequire = shouldUseRequire(sourceFile, program);
|
||||
const fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
|
||||
if (fix) {
|
||||
addImport({ fixes: [fix], symbolName });
|
||||
addImport({ fixes: [fix], symbolName, errorIdentifierText: undefined });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,6 +315,7 @@ namespace ts.codefix {
|
||||
sourceFile,
|
||||
symbolName,
|
||||
fix,
|
||||
/*includeSymbolNameInDescription*/ false,
|
||||
getQuotePreference(sourceFile, preferences), compilerOptions))
|
||||
};
|
||||
}
|
||||
@@ -316,7 +324,8 @@ namespace ts.codefix {
|
||||
const compilerOptions = program.getCompilerOptions();
|
||||
const symbolName = getSymbolName(sourceFile, program.getTypeChecker(), symbolToken, compilerOptions);
|
||||
const fix = getTypeOnlyPromotionFix(sourceFile, symbolToken, symbolName, program);
|
||||
return fix && codeFixActionToCodeAction(codeActionForFix({ host, formatContext, preferences }, sourceFile, symbolName, fix, QuotePreference.Double, compilerOptions));
|
||||
const includeSymbolNameInDescription = symbolName !== symbolToken.text;
|
||||
return fix && codeFixActionToCodeAction(codeActionForFix({ host, formatContext, preferences }, sourceFile, symbolName, fix, includeSymbolNameInDescription, QuotePreference.Double, compilerOptions));
|
||||
}
|
||||
|
||||
function getImportFixForSymbol(sourceFile: SourceFile, exportInfos: readonly SymbolExportInfo[], moduleSymbol: Symbol, symbolName: string, program: Program, position: number | undefined, isValidTypeOnlyUseSite: boolean, useRequire: boolean, host: LanguageServiceHost, preferences: UserPreferences) {
|
||||
@@ -666,7 +675,7 @@ namespace ts.codefix {
|
||||
}
|
||||
}
|
||||
|
||||
interface FixesInfo { readonly fixes: readonly ImportFix[]; readonly symbolName: string; }
|
||||
interface FixesInfo { readonly fixes: readonly ImportFix[]; readonly symbolName: string; readonly errorIdentifierText: string | undefined; }
|
||||
function getFixesInfo(context: CodeFixContextBase, errorCode: number, pos: number, useAutoImportProvider: boolean): FixesInfo | undefined {
|
||||
const symbolToken = getTokenAtPosition(context.sourceFile, pos);
|
||||
let info;
|
||||
@@ -679,7 +688,7 @@ namespace ts.codefix {
|
||||
else if (errorCode === Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type.code) {
|
||||
const symbolName = getSymbolName(context.sourceFile, context.program.getTypeChecker(), symbolToken, context.program.getCompilerOptions());
|
||||
const fix = getTypeOnlyPromotionFix(context.sourceFile, symbolToken, symbolName, context.program);
|
||||
return fix && { fixes: [fix], symbolName };
|
||||
return fix && { fixes: [fix], symbolName, errorIdentifierText: symbolToken.text };
|
||||
}
|
||||
else {
|
||||
info = getFixesInfoForNonUMDImport(context, symbolToken, useAutoImportProvider);
|
||||
@@ -736,7 +745,7 @@ namespace ts.codefix {
|
||||
const exportInfos: readonly SymbolExportInfo[] = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: ExportKind.UMD, targetFlags: symbol.flags, isFromPackageJson: false }];
|
||||
const useRequire = shouldUseRequire(sourceFile, program);
|
||||
const fixes = getImportFixes(exportInfos, symbolName, isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
|
||||
return { fixes, symbolName };
|
||||
return { fixes, symbolName, errorIdentifierText: tryCast(token, isIdentifier)?.text };
|
||||
}
|
||||
function getUmdSymbol(token: Node, checker: TypeChecker): Symbol | undefined {
|
||||
// try the identifier to see if it is the umd symbol
|
||||
@@ -808,7 +817,7 @@ namespace ts.codefix {
|
||||
const exportInfos = getExportInfos(symbolName, isJSXTagName(symbolToken), getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
|
||||
const fixes = arrayFrom(flatMapIterator(exportInfos.entries(), ([_, exportInfos]) =>
|
||||
getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences)));
|
||||
return { fixes, symbolName };
|
||||
return { fixes, symbolName, errorIdentifierText: symbolToken.text };
|
||||
}
|
||||
|
||||
function getTypeOnlyPromotionFix(sourceFile: SourceFile, symbolToken: Identifier, symbolName: string, program: Program): FixPromoteTypeOnlyImport | undefined {
|
||||
@@ -920,14 +929,14 @@ namespace ts.codefix {
|
||||
return allowSyntheticDefaults ? ImportKind.Default : ImportKind.CommonJS;
|
||||
}
|
||||
|
||||
function codeActionForFix(context: textChanges.TextChangesContext, sourceFile: SourceFile, symbolName: string, fix: ImportFix, quotePreference: QuotePreference, compilerOptions: CompilerOptions): CodeFixAction {
|
||||
function codeActionForFix(context: textChanges.TextChangesContext, sourceFile: SourceFile, symbolName: string, fix: ImportFix, includeSymbolNameInDescription: boolean, quotePreference: QuotePreference, compilerOptions: CompilerOptions): CodeFixAction {
|
||||
let diag!: DiagnosticAndArguments;
|
||||
const changes = textChanges.ChangeTracker.with(context, tracker => {
|
||||
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference, compilerOptions);
|
||||
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, includeSymbolNameInDescription, quotePreference, compilerOptions);
|
||||
});
|
||||
return createCodeFixAction(importFixName, changes, diag, importFixId, Diagnostics.Add_all_missing_imports);
|
||||
}
|
||||
function codeActionForFixWorker(changes: textChanges.ChangeTracker, sourceFile: SourceFile, symbolName: string, fix: ImportFix, quotePreference: QuotePreference, compilerOptions: CompilerOptions): DiagnosticAndArguments {
|
||||
function codeActionForFixWorker(changes: textChanges.ChangeTracker, sourceFile: SourceFile, symbolName: string, fix: ImportFix, includeSymbolNameInDescription: boolean, quotePreference: QuotePreference, compilerOptions: CompilerOptions): DiagnosticAndArguments {
|
||||
switch (fix.kind) {
|
||||
case ImportFixKind.UseNamespace:
|
||||
addNamespaceQualifier(changes, sourceFile, fix);
|
||||
@@ -945,11 +954,9 @@ namespace ts.codefix {
|
||||
importKind === ImportKind.Named ? [{ name: symbolName, addAsTypeOnly }] : emptyArray,
|
||||
compilerOptions);
|
||||
const moduleSpecifierWithoutQuotes = stripQuotes(moduleSpecifier);
|
||||
return [
|
||||
importKind === ImportKind.Default ? Diagnostics.Add_default_import_0_to_existing_import_declaration_from_1 : Diagnostics.Add_0_to_existing_import_declaration_from_1,
|
||||
symbolName,
|
||||
moduleSpecifierWithoutQuotes
|
||||
]; // you too!
|
||||
return includeSymbolNameInDescription
|
||||
? [Diagnostics.Import_0_from_1, symbolName, moduleSpecifierWithoutQuotes]
|
||||
: [Diagnostics.Update_import_from_0, moduleSpecifierWithoutQuotes];
|
||||
}
|
||||
case ImportFixKind.AddNew: {
|
||||
const { importKind, moduleSpecifier, addAsTypeOnly, useRequire } = fix;
|
||||
@@ -958,7 +965,9 @@ namespace ts.codefix {
|
||||
const namedImports: Import[] | undefined = importKind === ImportKind.Named ? [{ name: symbolName, addAsTypeOnly }] : undefined;
|
||||
const namespaceLikeImport = importKind === ImportKind.Namespace || importKind === ImportKind.CommonJS ? { importKind, name: symbolName, addAsTypeOnly } : undefined;
|
||||
insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true);
|
||||
return [importKind === ImportKind.Default ? Diagnostics.Import_default_0_from_module_1 : Diagnostics.Import_0_from_module_1, symbolName, moduleSpecifier];
|
||||
return includeSymbolNameInDescription
|
||||
? [Diagnostics.Import_0_from_1, symbolName, moduleSpecifier]
|
||||
: [Diagnostics.Add_import_from_0, moduleSpecifier];
|
||||
}
|
||||
case ImportFixKind.PromoteTypeOnly: {
|
||||
const { typeOnlyAliasDeclaration } = fix;
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace ts.projectSystem {
|
||||
{
|
||||
codeActions: [
|
||||
{
|
||||
description: `Import 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
changes: [
|
||||
{
|
||||
fileName: "/b.ts",
|
||||
@@ -118,7 +118,7 @@ namespace ts.projectSystem {
|
||||
{
|
||||
codeActions: [
|
||||
{
|
||||
description: `Import 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
changes: [
|
||||
{
|
||||
fileName: "/b.ts",
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace ts.projectSystem {
|
||||
});
|
||||
assert.deepEqual<readonly protocol.CodeFixAction[] | undefined>(response, [
|
||||
{
|
||||
description: `Import 'foo' from module "foo"`,
|
||||
description: `Add import from "foo"`,
|
||||
fixName: "import",
|
||||
changes: [{
|
||||
fileName: user.path,
|
||||
|
||||
+1
-1
@@ -98,4 +98,4 @@ response:{"responseRequired":false}
|
||||
request:{"command":"getCodeFixes","arguments":{"file":"/user/username/projects/myproject/app/src/program/index.ts","startLine":1,"startOffset":1,"endLine":1,"endOffset":4,"errorCodes":[2304]},"seq":1,"type":"request"}
|
||||
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache
|
||||
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache
|
||||
response:{"response":[{"fixName":"import","description":"Import 'foo' from module \"shared\"","changes":[{"fileName":"/user/username/projects/myproject/app/src/program/index.ts","textChanges":[{"start":{"line":1,"offset":1},"end":{"line":1,"offset":1},"newText":"import { foo } from \"shared\";\n\n"}]}]}],"responseRequired":true}
|
||||
response:{"response":[{"fixName":"import","description":"Add import from \"shared\"","changes":[{"fileName":"/user/username/projects/myproject/app/src/program/index.ts","textChanges":[{"start":{"line":1,"offset":1},"end":{"line":1,"offset":1},"newText":"import { foo } from \"shared\";\n\n"}]}]}],"responseRequired":true}
|
||||
+1
-1
@@ -97,4 +97,4 @@ response:{"responseRequired":false}
|
||||
request:{"command":"getCodeFixes","arguments":{"file":"/user/username/projects/myproject/app/src/program/index.ts","startLine":1,"startOffset":1,"endLine":1,"endOffset":4,"errorCodes":[2304]},"seq":1,"type":"request"}
|
||||
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache
|
||||
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache
|
||||
response:{"response":[{"fixName":"import","description":"Import 'foo' from module \"shared\"","changes":[{"fileName":"/user/username/projects/myproject/app/src/program/index.ts","textChanges":[{"start":{"line":1,"offset":1},"end":{"line":1,"offset":1},"newText":"import { foo } from \"shared\";\n\n"}]}]}],"responseRequired":true}
|
||||
response:{"response":[{"fixName":"import","description":"Add import from \"shared\"","changes":[{"fileName":"/user/username/projects/myproject/app/src/program/index.ts","textChanges":[{"start":{"line":1,"offset":1},"end":{"line":1,"offset":1},"newText":"import { foo } from \"shared\";\n\n"}]}]}],"responseRequired":true}
|
||||
+1
-1
@@ -97,4 +97,4 @@ response:{"responseRequired":false}
|
||||
request:{"command":"getCodeFixes","arguments":{"file":"/user/username/projects/myproject/app/src/program/index.ts","startLine":1,"startOffset":1,"endLine":1,"endOffset":4,"errorCodes":[2304]},"seq":1,"type":"request"}
|
||||
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache
|
||||
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache
|
||||
response:{"response":[{"fixName":"import","description":"Import 'foo' from module \"shared\"","changes":[{"fileName":"/user/username/projects/myproject/app/src/program/index.ts","textChanges":[{"start":{"line":1,"offset":1},"end":{"line":1,"offset":1},"newText":"import { foo } from \"shared\";\n\n"}]}]}],"responseRequired":true}
|
||||
response:{"response":[{"fixName":"import","description":"Add import from \"shared\"","changes":[{"fileName":"/user/username/projects/myproject/app/src/program/index.ts","textChanges":[{"start":{"line":1,"offset":1},"end":{"line":1,"offset":1},"newText":"import { foo } from \"shared\";\n\n"}]}]}],"responseRequired":true}
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.codeFixAvailable([
|
||||
{ description: `Import 'foo' from module "./a"` },
|
||||
{ description: `Add import from "./a"` },
|
||||
{ description: "Change spelling to 'fooo'" },
|
||||
{ description: "Add 'this.' to unresolved variable" },
|
||||
]);
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.codeFixAvailable([
|
||||
{ description: `Import 'foo' from module "./a"` },
|
||||
{ description: `Add import from "./a"` },
|
||||
{ description: "Change spelling to 'foof'" },
|
||||
]);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "Box",
|
||||
source: "/Box",
|
||||
description: `Import 'Box' from module "./Box"`,
|
||||
description: `Add import from "./Box"`,
|
||||
newFileContent: `import { Box } from "./Box";
|
||||
|
||||
export function App() {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "Abcde",
|
||||
source: "/test",
|
||||
description: `Import 'Abcde' from module "./test"`,
|
||||
description: `Add import from "./test"`,
|
||||
newFileContent: `import { Abcde } from "./test";
|
||||
|
||||
export {};
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "a",
|
||||
source: "/a",
|
||||
description: `Import 'a' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import { a } from "./a";
|
||||
|
||||
function *f() {
|
||||
|
||||
@@ -80,7 +80,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "ref",
|
||||
source: "vue",
|
||||
description: `Add 'ref' to existing import declaration from "vue"`,
|
||||
description: `Update import from "vue"`,
|
||||
data: {
|
||||
exportName: "ref",
|
||||
fileName: "/node_modules/vue/dist/vue.d.ts",
|
||||
|
||||
@@ -45,7 +45,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "Bar",
|
||||
source: "path2longer",
|
||||
description: `Import 'Bar' from module "path2longer"`,
|
||||
description: `Add import from "path2longer"`,
|
||||
newFileContent: `import { Bar } from "path2longer";\n\nBa`,
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true
|
||||
|
||||
@@ -42,7 +42,7 @@ verify.applyCodeActionFromCompletion("", {
|
||||
name: "someModule",
|
||||
source: "/someModule",
|
||||
data: { exportName: "default", fileName: "/someModule.ts" },
|
||||
description: `Import default 'someModule' from module "./someModule"`,
|
||||
description: `Add import from "./someModule"`,
|
||||
newFileContent: `import someModule from "./someModule";
|
||||
|
||||
someMo`
|
||||
|
||||
@@ -30,7 +30,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "concat",
|
||||
source: "/node_modules/bar/concat",
|
||||
description: `Import 'concat' from module "bar/concat"`,
|
||||
description: `Add import from "bar/concat"`,
|
||||
newFileContent:
|
||||
`import { concat } from "bar/concat";
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Add default import 'foo' to existing import declaration from "./a"`,
|
||||
description: `Update import from "./a"`,
|
||||
newFileContent: `import foo, { x } from "./a";
|
||||
f;`,
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Add default import 'foo' to existing import declaration from "./a"`,
|
||||
description: `Update import from "./a"`,
|
||||
newFileContent: `import foo, * as a from "./a";
|
||||
f;`,
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Import default 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import foo from "./a";
|
||||
import f_o_o from "./a";
|
||||
f;`,
|
||||
|
||||
@@ -37,7 +37,7 @@ verify.completions(
|
||||
verify.applyCodeActionFromCompletion("1", {
|
||||
name: "fooBar",
|
||||
source: "/src/foo-bar",
|
||||
description: `Import default 'fooBar' from module "./foo-bar"`,
|
||||
description: `Add import from "./foo-bar"`,
|
||||
newFileContent: `import fooBar from "./foo-bar"
|
||||
|
||||
def
|
||||
|
||||
@@ -25,7 +25,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Import default 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import foo from "./a";
|
||||
|
||||
f;`,
|
||||
|
||||
@@ -30,7 +30,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Import default 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import foo from "./a";
|
||||
|
||||
f;`,
|
||||
|
||||
@@ -32,7 +32,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "M",
|
||||
source: "m",
|
||||
description: `Import default 'M' from module "m"`,
|
||||
description: `Add import from "m"`,
|
||||
newFileContent: `import M from "m";
|
||||
|
||||
`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @module: commonjs
|
||||
|
||||
// @Filename: /node_modules/@types/range-parser/index.d.ts
|
||||
@@ -37,7 +37,7 @@ function RangeParser(): string`
|
||||
verify.applyCodeActionFromCompletion("0", {
|
||||
name: "RangeParser",
|
||||
source: "/node_modules/@types/range-parser/index",
|
||||
description: `Import 'RangeParser' from module "range-parser"`,
|
||||
description: `Add import from "range-parser"`,
|
||||
newFileContent: `import RangeParser = require("range-parser");
|
||||
|
||||
R`,
|
||||
|
||||
@@ -13,7 +13,7 @@ goTo.marker("1");
|
||||
verify.applyCodeActionFromCompletion("1", {
|
||||
name: "abc",
|
||||
source: "/a",
|
||||
description: `Import 'abc' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import { abc } from "./a";
|
||||
|
||||
acb;`,
|
||||
@@ -27,7 +27,7 @@ verify.applyCodeActionFromCompletion("2", {
|
||||
exportName: "abc",
|
||||
fileName: "/a.ts",
|
||||
},
|
||||
description: `Import 'abc' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import { abc } from "./a";
|
||||
|
||||
acb;`,
|
||||
|
||||
@@ -41,7 +41,7 @@ verify.completions(
|
||||
verify.applyCodeActionFromCompletion("1", {
|
||||
name: "b",
|
||||
source: "/a",
|
||||
description: `Import 'b' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent:
|
||||
`import { b } from "./a";
|
||||
|
||||
@@ -52,7 +52,7 @@ let x: b;`,
|
||||
verify.applyCodeActionFromCompletion("0", {
|
||||
name: "a",
|
||||
source: "/a",
|
||||
description: `Import 'a' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent:
|
||||
`import { b } from "./a";
|
||||
import a = require("./a");
|
||||
|
||||
@@ -37,7 +37,7 @@ verify.completions(
|
||||
verify.applyCodeActionFromCompletion("0", {
|
||||
name: "fooBar",
|
||||
source: "/src/foo-bar",
|
||||
description: `Import 'fooBar' from module "./foo-bar"`,
|
||||
description: `Add import from "./foo-bar"`,
|
||||
newFileContent: `import fooBar = require("./foo-bar")
|
||||
|
||||
exp
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "x",
|
||||
source: "m",
|
||||
description: `Import 'x' from module "m"`,
|
||||
description: `Add import from "m"`,
|
||||
newFileContent: `import { x } from "m";
|
||||
|
||||
`,
|
||||
|
||||
@@ -42,7 +42,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("0", {
|
||||
name: "C",
|
||||
source: "/a",
|
||||
description: `Import 'C' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent:
|
||||
`import { C } from "./a";
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "Component",
|
||||
source: "/component",
|
||||
description: `Import default 'Component' from module "./component"`,
|
||||
description: `Add import from "./component"`,
|
||||
newFileContent:
|
||||
`import Component from "./component";
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/b",
|
||||
description: `Import 'foo' from module "./b"`,
|
||||
description: `Add import from "./b"`,
|
||||
newFileContent: `import { foo } from "./b";
|
||||
|
||||
fo`,
|
||||
|
||||
@@ -25,7 +25,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Add 'foo' to existing import declaration from "./a"`,
|
||||
description: `Update import from "./a"`,
|
||||
newFileContent: `import { foo, x } from "./a";
|
||||
f;`,
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "Test1",
|
||||
source: "/a",
|
||||
description: `Add 'Test1' to existing import declaration from "./a"`,
|
||||
description: `Update import from "./a"`,
|
||||
newFileContent: `import { Test1, Test2 } from "./a";
|
||||
t`,
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Import 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import { foo } from "./a";
|
||||
|
||||
f;`,
|
||||
|
||||
@@ -32,7 +32,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "M",
|
||||
source: "m",
|
||||
description: `Import 'M' from module "m"`,
|
||||
description: `Add import from "m"`,
|
||||
newFileContent: `import { M } from "m";
|
||||
|
||||
`,
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Import 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import { foo } from "./a"
|
||||
|
||||
const x = 0
|
||||
|
||||
@@ -33,7 +33,7 @@ for (const [marker, sourceDisplay] of [["0", "./src"], ["1", "./a"], ["2", "../a
|
||||
verify.applyCodeActionFromCompletion(marker, {
|
||||
name: "x",
|
||||
source: "/src/a",
|
||||
description: `Import 'x' from module "${sourceDisplay}"`,
|
||||
description: `Add import from "${sourceDisplay}"`,
|
||||
newFileContent: `import { x } from "${sourceDisplay}";\n\nx`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Import 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import { foo } from "./a";
|
||||
|
||||
fo`,
|
||||
|
||||
@@ -35,7 +35,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/foo/lib/foo",
|
||||
description: `Import 'foo' from module "./foo"`,
|
||||
description: `Add import from "./foo"`,
|
||||
newFileContent: `import { foo } from "./foo";
|
||||
|
||||
fo`,
|
||||
|
||||
@@ -12,7 +12,7 @@ goTo.marker("");
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Import 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
preferences: {
|
||||
quotePreference: "single",
|
||||
},
|
||||
|
||||
@@ -31,7 +31,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "foo",
|
||||
source: "/a/b/impl",
|
||||
description: `Import 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import { foo } from "./a";
|
||||
|
||||
fo`,
|
||||
|
||||
@@ -37,7 +37,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "x",
|
||||
source: "/a",
|
||||
description: `Import 'x' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import { x } from "./a";
|
||||
|
||||
`,
|
||||
@@ -45,7 +45,7 @@ verify.applyCodeActionFromCompletion("", {
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "y",
|
||||
source: "/index",
|
||||
description: `Import 'y' from module "."`,
|
||||
description: `Add import from "."`,
|
||||
newFileContent: `import { y } from ".";
|
||||
import { x } from "./a";
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("b", {
|
||||
name: "foo",
|
||||
source: "/a",
|
||||
description: `Import 'foo' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent:
|
||||
`import * as s from "something";
|
||||
import { foo } from "./a";
|
||||
|
||||
@@ -24,7 +24,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "x",
|
||||
source: "/a",
|
||||
description: `Import 'x' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `const { x } = require("./a");
|
||||
|
||||
x`,
|
||||
|
||||
@@ -27,7 +27,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "x",
|
||||
source: "/a",
|
||||
description: `Add 'x' to existing import declaration from "./a"`,
|
||||
description: `Update import from "./a"`,
|
||||
newFileContent: `const { f, x } = require("./a");
|
||||
|
||||
x`,
|
||||
|
||||
@@ -14,7 +14,7 @@ goTo.file('/b.ts');
|
||||
verify.applyCodeActionFromCompletion('', {
|
||||
name: 'B',
|
||||
source: '/a',
|
||||
description: `Add 'B' to existing import declaration from "./a"`,
|
||||
description: `Update import from "./a"`,
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true,
|
||||
includeInsertTextCompletions: true
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "Collection",
|
||||
source: "/collection",
|
||||
description: `Import 'Collection' from module "./collection"`,
|
||||
description: `Add import from "./collection"`,
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true
|
||||
},
|
||||
|
||||
@@ -35,7 +35,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "publicSym",
|
||||
source: "/a",
|
||||
description: `Add 'publicSym' to existing import declaration from "./a"`,
|
||||
description: `Update import from "./a"`,
|
||||
newFileContent:
|
||||
`import { i, publicSym } from "./a";
|
||||
i.;`
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
goTo.marker("$")
|
||||
verify.codeFixAvailable([
|
||||
{ description: "Import 'bbb' from module \"./library.js\"" },
|
||||
{ description: "Add import from \"./library.js\"" },
|
||||
{ description: "Ignore this error message" },
|
||||
{ description: "Disable checking for this file" },
|
||||
{ description: "Convert to ES module" },
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "a",
|
||||
source: "/a",
|
||||
description: `Import default 'a' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
newFileContent: `import a from "./a";\n\na`,
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.codeFix({
|
||||
description: ignoreInterpolations(ts.Diagnostics.Import_0_from_module_1),
|
||||
description: ignoreInterpolations(ts.Diagnostics.Add_import_from_0),
|
||||
newFileContent:
|
||||
`/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
@@ -52,7 +52,7 @@ export class B extends A { }`,
|
||||
|
||||
goTo.file("/c.ts");
|
||||
verify.codeFix({
|
||||
description: ignoreInterpolations(ts.Diagnostics.Import_0_from_module_1),
|
||||
description: ignoreInterpolations(ts.Diagnostics.Add_import_from_0),
|
||||
newFileContent:
|
||||
`/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
@@ -70,7 +70,7 @@ export class C extends A { }`,
|
||||
|
||||
goTo.file("/d.ts");
|
||||
verify.codeFix({
|
||||
description: ignoreInterpolations(ts.Diagnostics.Import_0_from_module_1),
|
||||
description: ignoreInterpolations(ts.Diagnostics.Add_import_from_0),
|
||||
newFileContent:
|
||||
`/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.codeFix({
|
||||
description: ignoreInterpolations(ts.Diagnostics.Import_0_from_module_1),
|
||||
description: ignoreInterpolations(ts.Diagnostics.Add_import_from_0),
|
||||
newFileContent:
|
||||
`"use strict";
|
||||
|
||||
@@ -29,7 +29,7 @@ export class B extends A { }`,
|
||||
|
||||
goTo.file("/c.ts");
|
||||
verify.codeFix({
|
||||
description: ignoreInterpolations(ts.Diagnostics.Import_0_from_module_1),
|
||||
description: ignoreInterpolations(ts.Diagnostics.Add_import_from_0),
|
||||
newFileContent:
|
||||
`/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
goTo.file("/a.tsx");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: [ts.Diagnostics.Import_0_from_module_1.message, "Text", "react-native"],
|
||||
description: [ts.Diagnostics.Add_import_from_0.message, "react-native"],
|
||||
newFileContent:
|
||||
`import React from "react";
|
||||
import { Text } from "react-native";
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
goTo.file("/a.tsx");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: [ts.Diagnostics.Import_0_from_module_1.message, "Text", "react-native"],
|
||||
description: [ts.Diagnostics.Add_import_from_0.message, "react-native"],
|
||||
newFileContent:
|
||||
`import React from "react";
|
||||
import { Text } from "react-native";
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
goTo.file("/a.tsx");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: [ts.Diagnostics.Import_default_0_from_module_1.message, "React", "react"],
|
||||
description: [ts.Diagnostics.Import_0_from_1.message, "React", "react"],
|
||||
newFileContent:
|
||||
`import React from "react";
|
||||
import { Text } from "react-native";
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
goTo.file("/a.tsx");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: [ts.Diagnostics.Import_0_from_module_1.message, "Text", "react-native"],
|
||||
description: [ts.Diagnostics.Add_import_from_0.message, "react-native"],
|
||||
newFileContent:
|
||||
`import React from "react";
|
||||
import { Text } from "react-native";
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
goTo.file("/a.tsx");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: [ts.Diagnostics.Import_default_0_from_module_1.message, "React", "react"],
|
||||
description: [ts.Diagnostics.Import_0_from_1.message, "React", "react"],
|
||||
applyChanges: true,
|
||||
newFileContent:
|
||||
`import React from "react";
|
||||
@@ -32,7 +32,7 @@ verify.codeFix({
|
||||
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: [ts.Diagnostics.Import_0_from_module_1.message, "Text", "react-native"],
|
||||
description: [ts.Diagnostics.Add_import_from_0.message, "react-native"],
|
||||
newFileContent:
|
||||
`import React from "react";
|
||||
import { Text } from "react-native";
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
goTo.file("index.js");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: `Import 'Foo' from module "./umd"`,
|
||||
description: `Add import from "./umd"`,
|
||||
newFileContent:
|
||||
`const Foo = require("./umd");
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ goTo.file("index.js");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
errorCode: ts.Diagnostics.Cannot_find_name_0.code,
|
||||
description: `Add default import 'Blah' to existing import declaration from "./blah"`,
|
||||
description: `Update import from "./blah"`,
|
||||
newFileContent:
|
||||
`var path = require('path')
|
||||
, { promisify } = require('util')
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ goTo.file("index.js");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
errorCode: ts.Diagnostics.Cannot_find_name_0.code,
|
||||
description: `Add default import 'Blah' to existing import declaration from "./blah"`,
|
||||
description: `Update import from "./blah"`,
|
||||
newFileContent:
|
||||
`var path = require('path')
|
||||
, { promisify } = require('util')
|
||||
|
||||
@@ -26,7 +26,7 @@ goTo.file("addToExisting.js");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
errorCode: ts.Diagnostics.Cannot_find_name_0.code,
|
||||
description: `Add default import 'Blah' to existing import declaration from "./blah"`,
|
||||
description: `Update import from "./blah"`,
|
||||
newFileContent:
|
||||
`const { Named2 } = require('./blah')
|
||||
import Blah, { Named1 } from './blah'
|
||||
@@ -41,7 +41,7 @@ goTo.file("newImport.js");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
errorCode: ts.Diagnostics.Cannot_find_name_0.code,
|
||||
description: `Import default 'Blah' from module "./blah"`,
|
||||
description: `Add import from "./blah"`,
|
||||
newFileContent:
|
||||
`import fs from 'fs';
|
||||
import Blah from './blah';
|
||||
|
||||
@@ -15,7 +15,7 @@ goTo.file("index.js");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
errorCode: ts.Diagnostics.Cannot_find_name_0.code,
|
||||
description: `Import 'x' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
applyChanges: false,
|
||||
newFileContent:
|
||||
`import { x } from "./a";
|
||||
@@ -30,7 +30,7 @@ edit.insertLine("const fs = require('fs');\n");
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
errorCode: ts.Diagnostics.Cannot_find_name_0.code,
|
||||
description: `Import 'x' from module "./a"`,
|
||||
description: `Add import from "./a"`,
|
||||
applyChanges: false,
|
||||
newFileContent:
|
||||
`const fs = require('fs');
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
goTo.file("index.ts");
|
||||
verify.codeFix({
|
||||
errorCode: ts.Diagnostics.Cannot_find_name_0.code,
|
||||
description: ignoreInterpolations(ts.Diagnostics.Import_0_from_module_1),
|
||||
description: ignoreInterpolations(ts.Diagnostics.Add_import_from_0),
|
||||
newFileContent:
|
||||
`import type { DisplayStyle } from "./Presenter";
|
||||
import type Presenter from "./Presenter";
|
||||
|
||||
@@ -51,7 +51,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("1", {
|
||||
name: "MyClass",
|
||||
source: "mylib",
|
||||
description: `Import 'MyClass' from module "mylib"`,
|
||||
description: `Add import from "mylib"`,
|
||||
data: {
|
||||
exportName: "MyClass",
|
||||
fileName: "/packages/mylib/index.ts",
|
||||
|
||||
@@ -51,7 +51,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("1", {
|
||||
name: "MyClass",
|
||||
source: "mylib",
|
||||
description: `Import 'MyClass' from module "mylib"`,
|
||||
description: `Add import from "mylib"`,
|
||||
data: {
|
||||
exportName: "MyClass",
|
||||
fileName: "/packages/mylib/index.ts",
|
||||
|
||||
@@ -52,7 +52,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("1", {
|
||||
name: "MyClass",
|
||||
source: "../packages/mylib",
|
||||
description: `Import 'MyClass' from module "../packages/mylib"`,
|
||||
description: `Add import from "../packages/mylib"`,
|
||||
data: {
|
||||
exportName: "MyClass",
|
||||
fileName: "/packages/mylib/index.ts",
|
||||
|
||||
@@ -45,6 +45,6 @@ verify.applyCodeActionFromCompletion("", {
|
||||
name: "someModule",
|
||||
source: "/someModule",
|
||||
data: { exportName: "default", fileName: "/someModule.ts" },
|
||||
description: `Import default 'someModule' from module "./someModule"`,
|
||||
description: `Add import from "./someModule"`,
|
||||
newFileContent: `import someModule from "./someModule";\r\n\r\nsomeMo`
|
||||
});
|
||||
|
||||
@@ -46,7 +46,7 @@ verify.completions({
|
||||
verify.applyCodeActionFromCompletion("", {
|
||||
name: "defaults",
|
||||
source: "/third_party/marked/src/defaults",
|
||||
description: `Import 'defaults' from module "./third_party/marked/src/defaults"`,
|
||||
description: `Add import from "./third_party/marked/src/defaults"`,
|
||||
data: {
|
||||
exportName: "defaults",
|
||||
fileName: "/third_party/marked/src/defaults.js",
|
||||
|
||||
Reference in New Issue
Block a user