diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index f8f417df0c31d..b23b7c127e872 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -80,12 +80,15 @@ import { ImportSpecifier, insertImports, InternalSymbolName, + isDefaultImport, isExternalModuleReference, isFullSourceFile, isIdentifier, isImportable, + isImportClause, isImportDeclaration, isImportEqualsDeclaration, + isImportSpecifier, isIntrinsicJsxName, isJSDocImportTag, isJsxClosingElement, @@ -228,6 +231,7 @@ export interface ImportAdder { addImportFromDiagnostic: (diagnostic: DiagnosticWithLocation, context: CodeFixContextBase) => void; addImportFromExportedSymbol: (exportedSymbol: Symbol, isValidTypeOnlyUseSite?: boolean, referenceImport?: ImportOrRequireAliasDeclaration) => void; addImportForNonExistentExport: (exportName: string, exportingFileName: string, exportKind: ExportKind, exportedMeanings: SymbolFlags, isImportUsageValidAsTypeOnly: boolean) => void; + addImportForModuleSymbol: (symbolAlias: Symbol, isValidTypeOnlyUseSite: boolean, referenceImport: ImportOrRequireAliasDeclaration) => void; addImportForUnresolvedIdentifier: (context: CodeFixContextBase, symbolToken: Identifier, useAutoImportProvider: boolean) => void; addVerbatimImport: (declaration: AnyImportOrRequireStatement | ImportOrRequireAliasDeclaration) => void; removeExistingImport: (declaration: ImportOrRequireAliasDeclaration) => void; @@ -257,7 +261,7 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog type NewImportsKey = `${0 | 1}|${string}`; /** Use `getNewImportEntry` for access */ const newImports = new Map>(); - return { addImportFromDiagnostic, addImportFromExportedSymbol, writeFixes, hasFixes, addImportForUnresolvedIdentifier, addImportForNonExistentExport, removeExistingImport, addVerbatimImport }; + return { addImportFromDiagnostic, addImportFromExportedSymbol, addImportForModuleSymbol, writeFixes, hasFixes, addImportForUnresolvedIdentifier, addImportForNonExistentExport, removeExistingImport, addVerbatimImport }; function addVerbatimImport(declaration: AnyImportOrRequireStatement | ImportOrRequireAliasDeclaration) { verbatimImports.add(declaration); @@ -276,7 +280,7 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog } function addImportFromExportedSymbol(exportedSymbol: Symbol, isValidTypeOnlyUseSite?: boolean, referenceImport?: ImportOrRequireAliasDeclaration) { - const moduleSymbol = Debug.checkDefined(exportedSymbol.parent); + const moduleSymbol = Debug.checkDefined(exportedSymbol.parent, "Expected exported symbol to have module symbol as parent"); const symbolName = getNameForExportedSymbol(exportedSymbol, getEmitScriptTarget(compilerOptions)); const checker = program.getTypeChecker(); const symbol = checker.getMergedSymbol(skipAlias(exportedSymbol, checker)); @@ -317,6 +321,74 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog } } + function addImportForModuleSymbol(symbolAlias: Symbol, isValidTypeOnlyUseSite: boolean, referenceImport: ImportOrRequireAliasDeclaration) { + // Adds import for module, import alias will be symbolAlias.name + const checker = program.getTypeChecker(); + const moduleSymbol = checker.getAliasedSymbol(symbolAlias); + Debug.assert(moduleSymbol.flags & SymbolFlags.Module, "Expected symbol to be a module"); + const moduleSpecifierResolutionHost = createModuleSpecifierResolutionHost(program, host); + const moduleSpecifierResult = moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences, /*options*/ undefined, /*forAutoImport*/ true); + + const useRequire = shouldUseRequire(sourceFile, program); + + // Copy the type-only status from the reference import + let addAsTypeOnly = getAddAsTypeOnly( + isValidTypeOnlyUseSite, + /*isForNewImportDeclaration*/ true, + /*symbol*/ undefined, + symbolAlias.flags, + program.getTypeChecker(), + compilerOptions, + ); + addAsTypeOnly = addAsTypeOnly === AddAsTypeOnly.Allowed && isTypeOnlyImportDeclaration(referenceImport) ? AddAsTypeOnly.Required : AddAsTypeOnly.Allowed; + + // Copy the kind of import + const importKind = isImportDeclaration(referenceImport) ? + isDefaultImport(referenceImport) ? ImportKind.Default : ImportKind.Namespace : + isImportSpecifier(referenceImport) ? ImportKind.Named : + isImportClause(referenceImport) && !!referenceImport.name ? ImportKind.Default : ImportKind.Namespace; + + const exportInfo = [{ + symbol: symbolAlias, + moduleSymbol, + moduleFileName: moduleSymbol.declarations?.[0]?.getSourceFile()?.fileName, + exportKind: ExportKind.Module, + targetFlags: symbolAlias.flags, + isFromPackageJson: false, + }]; + + const existingFix = getImportFixForSymbol( + sourceFile, + exportInfo, + program, + /*position*/ undefined, + !!isValidTypeOnlyUseSite, + useRequire, + host, + preferences, + ); + + let fix: FixAddNewImport | ImportFixWithModuleSpecifier; + if (existingFix && importKind !== ImportKind.Namespace) { + fix = { + ...existingFix, + addAsTypeOnly, + importKind, + }; + } + else { + fix = { + kind: ImportFixKind.AddNew, + moduleSpecifierKind: existingFix !== undefined ? existingFix.moduleSpecifierKind : moduleSpecifierResult.kind, + moduleSpecifier: existingFix !== undefined ? existingFix.moduleSpecifier : first(moduleSpecifierResult.moduleSpecifiers), + importKind, + addAsTypeOnly, + useRequire, + }; + } + addImport({ fix, symbolName: symbolAlias.name, errorIdentifierText: undefined }); + } + function addImportForNonExistentExport(exportName: string, exportingFileName: string, exportKind: ExportKind, exportedMeanings: SymbolFlags, isImportUsageValidAsTypeOnly: boolean) { const exportingSourceFile = program.getSourceFile(exportingFileName); const useRequire = shouldUseRequire(sourceFile, program); @@ -1452,6 +1524,8 @@ export function getImportKind(importingFile: SourceFile | FutureSourceFile, expo return getExportEqualsImportKind(importingFile, program.getCompilerOptions(), !!forceImportKeyword); case ExportKind.UMD: return getUmdImportKind(importingFile, program, !!forceImportKeyword); + case ExportKind.Module: + return ImportKind.Namespace; default: return Debug.assertNever(exportKind); } diff --git a/src/services/exportInfoMap.ts b/src/services/exportInfoMap.ts index f1f88c6ad42ef..dfd00ce2e9170 100644 --- a/src/services/exportInfoMap.ts +++ b/src/services/exportInfoMap.ts @@ -74,6 +74,7 @@ export const enum ExportKind { Default, ExportEquals, UMD, + Module, } /** @internal */ diff --git a/src/services/refactors/helpers.ts b/src/services/refactors/helpers.ts index 38fc8b965f4b9..9779b8559f89b 100644 --- a/src/services/refactors/helpers.ts +++ b/src/services/refactors/helpers.ts @@ -80,6 +80,10 @@ export function addTargetFileImports( if (checker.isUnknownSymbol(targetSymbol)) { importAdder.addVerbatimImport(Debug.checkDefined(declaration ?? findAncestor(symbol.declarations?.[0], isAnyImportOrRequireStatement))); } + else if (targetSymbol.parent === undefined) { + Debug.assert(declaration !== undefined, "expected module symbol to have a declaration"); + importAdder.addImportForModuleSymbol(symbol, isValidTypeOnlyUseSite, declaration); + } else { importAdder.addImportFromExportedSymbol(targetSymbol, isValidTypeOnlyUseSite, declaration); } diff --git a/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_blankTargetFile.js b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_blankTargetFile.js index b896f39cefe33..376d47e901a34 100644 --- a/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_blankTargetFile.js +++ b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_blankTargetFile.js @@ -22,11 +22,11 @@ console.log(abc); console.log("abc"); -//// [/home/src/workspaces/project/c.ts] +//// [/home/src/workspaces/project/folder/c.ts] //// [/home/src/workspaces/project/tsconfig.json] -{ "files": ["c.ts", "a.ts", "b.ts"] } +{ "files": ["folder/c.ts", "a.ts", "b.ts"] } Info seq [hh:mm:ss:mss] request: @@ -34,16 +34,16 @@ Info seq [hh:mm:ss:mss] request: "seq": 0, "type": "request", "arguments": { - "file": "/home/src/workspaces/project/c.ts" + "file": "/home/src/workspaces/project/folder/c.ts" }, "command": "open" } -Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /home/src/workspaces/project/c.ts ProjectRootPath: undefined:: Result: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /home/src/workspaces/project/folder/c.ts ProjectRootPath: undefined:: Result: /home/src/workspaces/project/tsconfig.json Info seq [hh:mm:ss:mss] Creating ConfiguredProject: /home/src/workspaces/project/tsconfig.json, currentDirectory: /home/src/workspaces/project Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/tsconfig.json 2000 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Config file Info seq [hh:mm:ss:mss] Config: /home/src/workspaces/project/tsconfig.json : { "rootNames": [ - "/home/src/workspaces/project/c.ts", + "/home/src/workspaces/project/folder/c.ts", "/home/src/workspaces/project/a.ts", "/home/src/workspaces/project/b.ts" ], @@ -58,7 +58,7 @@ Info seq [hh:mm:ss:mss] event: "event": "projectLoadingStart", "body": { "projectName": "/home/src/workspaces/project/tsconfig.json", - "reason": "Creating possible configured project for /home/src/workspaces/project/c.ts to open" + "reason": "Creating possible configured project for /home/src/workspaces/project/folder/c.ts to open" } } Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/a.ts 500 undefined WatchType: Closed Script info @@ -81,7 +81,7 @@ Info seq [hh:mm:ss:mss] Files (6) /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text - /home/src/workspaces/project/c.ts SVC-1-0 "" + /home/src/workspaces/project/folder/c.ts SVC-1-0 "" /home/src/workspaces/project/a.ts Text-1 "export const abc = 10;" /home/src/workspaces/project/b.ts Text-1 "import { abc } from \"./a\";\n\nconsole.log(abc);\n\n\nconsole.log(\"abc\");" @@ -92,7 +92,7 @@ Info seq [hh:mm:ss:mss] Files (6) Library referenced via 'decorators' from file '../../tslibs/TS/Lib/lib.d.ts' ../../tslibs/TS/Lib/lib.decorators.legacy.d.ts Library referenced via 'decorators.legacy' from file '../../tslibs/TS/Lib/lib.d.ts' - c.ts + folder/c.ts Part of 'files' list in tsconfig.json a.ts Part of 'files' list in tsconfig.json @@ -116,7 +116,7 @@ Info seq [hh:mm:ss:mss] event: "type": "event", "event": "configFileDiag", "body": { - "triggerFile": "/home/src/workspaces/project/c.ts", + "triggerFile": "/home/src/workspaces/project/folder/c.ts", "configFile": "/home/src/workspaces/project/tsconfig.json", "diagnostics": [] } @@ -126,7 +126,7 @@ Info seq [hh:mm:ss:mss] Files (6) Info seq [hh:mm:ss:mss] ----------------------------------------------- Info seq [hh:mm:ss:mss] Open files: -Info seq [hh:mm:ss:mss] FileName: /home/src/workspaces/project/c.ts ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] FileName: /home/src/workspaces/project/folder/c.ts ProjectRootPath: undefined Info seq [hh:mm:ss:mss] Projects: /home/src/workspaces/project/tsconfig.json Info seq [hh:mm:ss:mss] response: { @@ -191,7 +191,7 @@ ScriptInfos:: version: Text-1 containingProjects: 1 /home/src/workspaces/project/tsconfig.json -/home/src/workspaces/project/c.ts (Open) *new* +/home/src/workspaces/project/folder/c.ts (Open) *new* version: SVC-1-0 containingProjects: 1 /home/src/workspaces/project/tsconfig.json *default* @@ -242,7 +242,7 @@ Info seq [hh:mm:ss:mss] request: "seq": 2, "type": "request", "arguments": { - "file": "/home/src/workspaces/project/c.ts", + "file": "/home/src/workspaces/project/folder/c.ts", "pastedText": [ "console.log(abc);" ], @@ -283,7 +283,7 @@ Info seq [hh:mm:ss:mss] Files (6) /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text - /home/src/workspaces/project/c.ts SVC-1-1 "console.log(abc);" + /home/src/workspaces/project/folder/c.ts SVC-1-1 "console.log(abc);" /home/src/workspaces/project/a.ts Text-1 "export const abc = 10;" /home/src/workspaces/project/b.ts Text-1 "import { abc } from \"./a\";\n\nconsole.log(abc);\n\n\nconsole.log(\"abc\");" @@ -303,7 +303,7 @@ Info seq [hh:mm:ss:mss] response: "body": { "edits": [ { - "fileName": "/home/src/workspaces/project/c.ts", + "fileName": "/home/src/workspaces/project/folder/c.ts", "textChanges": [ { "start": { @@ -314,7 +314,7 @@ Info seq [hh:mm:ss:mss] response: "line": 1, "offset": 1 }, - "newText": "import { abc } from \"./a\";\n\n" + "newText": "import { abc } from \"../a\";\n\n" }, { "start": { @@ -362,7 +362,7 @@ ScriptInfos:: version: Text-1 containingProjects: 1 /home/src/workspaces/project/tsconfig.json -/home/src/workspaces/project/c.ts (Open) *changed* +/home/src/workspaces/project/folder/c.ts (Open) *changed* version: SVC-1-2 *changed* containingProjects: 1 /home/src/workspaces/project/tsconfig.json *default* diff --git a/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_defaultExport1.js b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_defaultExport1.js new file mode 100644 index 0000000000000..96d4f54a4ab44 --- /dev/null +++ b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_defaultExport1.js @@ -0,0 +1,366 @@ +Info seq [hh:mm:ss:mss] currentDirectory:: /home/src/Vscode/Projects/bin useCaseSensitiveFileNames:: false +Info seq [hh:mm:ss:mss] libs Location:: /home/src/tslibs/TS/Lib +Info seq [hh:mm:ss:mss] globalTypingsCacheLocation:: /home/src/Library/Caches/typescript +Info seq [hh:mm:ss:mss] Provided types map file "/home/src/tslibs/TS/Lib/typesMap.json" doesn't exist +//// [/home/src/tslibs/TS/Lib/lib.d.ts] +lib.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.d.ts] +lib.decorators.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts] +lib.decorators.legacy.d.ts-Text + +//// [/home/src/workspaces/project/a.ts] +export default function foo(name: string): void { + console.log(name); +} + +//// [/home/src/workspaces/project/b.ts] +import foo from "./a"; +const b = foo("bar"); + +//// [/home/src/workspaces/project/folder/c.ts] + + +//// [/home/src/workspaces/project/tsconfig.json] +{ "files": ["folder/c.ts", "a.ts", "b.ts"] } + + +Info seq [hh:mm:ss:mss] request: + { + "seq": 0, + "type": "request", + "arguments": { + "file": "/home/src/workspaces/project/folder/c.ts" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /home/src/workspaces/project/folder/c.ts ProjectRootPath: undefined:: Result: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] Creating ConfiguredProject: /home/src/workspaces/project/tsconfig.json, currentDirectory: /home/src/workspaces/project +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/tsconfig.json 2000 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] Config: /home/src/workspaces/project/tsconfig.json : { + "rootNames": [ + "/home/src/workspaces/project/folder/c.ts", + "/home/src/workspaces/project/a.ts", + "/home/src/workspaces/project/b.ts" + ], + "options": { + "configFilePath": "/home/src/workspaces/project/tsconfig.json" + } +} +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingStart", + "body": { + "projectName": "/home/src/workspaces/project/tsconfig.json", + "reason": "Creating possible configured project for /home/src/workspaces/project/folder/c.ts to open" + } + } +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/a.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/b.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (6) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /home/src/workspaces/project/folder/c.ts SVC-1-0 "" + /home/src/workspaces/project/a.ts Text-1 "export default function foo(name: string): void {\n console.log(name);\n}" + /home/src/workspaces/project/b.ts Text-1 "import foo from \"./a\";\nconst b = foo(\"bar\");" + + + ../../tslibs/TS/Lib/lib.d.ts + Default library for target 'es5' + ../../tslibs/TS/Lib/lib.decorators.d.ts + Library referenced via 'decorators' from file '../../tslibs/TS/Lib/lib.d.ts' + ../../tslibs/TS/Lib/lib.decorators.legacy.d.ts + Library referenced via 'decorators.legacy' from file '../../tslibs/TS/Lib/lib.d.ts' + folder/c.ts + Part of 'files' list in tsconfig.json + a.ts + Part of 'files' list in tsconfig.json + Imported via "./a" from file 'b.ts' + b.ts + Part of 'files' list in tsconfig.json + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingFinish", + "body": { + "projectName": "/home/src/workspaces/project/tsconfig.json" + } + } +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "configFileDiag", + "body": { + "triggerFile": "/home/src/workspaces/project/folder/c.ts", + "configFile": "/home/src/workspaces/project/tsconfig.json", + "diagnostics": [] + } + } +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (6) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /home/src/workspaces/project/folder/c.ts ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 0, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/a.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/b.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/tsconfig.json: *new* + {"pollingInterval":2000} + +watchedDirectoriesRecursive:: +/home/src/workspaces/node_modules: *new* + {} +/home/src/workspaces/node_modules/@types: *new* + {} +/home/src/workspaces/project/node_modules: *new* + {} +/home/src/workspaces/project/node_modules/@types: *new* + {} + +Projects:: +/home/src/workspaces/project/tsconfig.json (Configured) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/a.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/b.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/folder/c.ts (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json *default* + +Info seq [hh:mm:ss:mss] request: + { + "seq": 1, + "type": "request", + "arguments": { + "formatOptions": { + "indentSize": 4, + "tabSize": 4, + "newLineCharacter": "\n", + "convertTabsToSpaces": true, + "indentStyle": 2, + "insertSpaceAfterConstructor": false, + "insertSpaceAfterCommaDelimiter": true, + "insertSpaceAfterSemicolonInForStatements": true, + "insertSpaceBeforeAndAfterBinaryOperators": true, + "insertSpaceAfterKeywordsInControlFlowStatements": true, + "insertSpaceAfterFunctionKeywordForAnonymousFunctions": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, + "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, + "insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, + "insertSpaceBeforeFunctionParenthesis": false, + "placeOpenBraceOnNewLineForFunctions": false, + "placeOpenBraceOnNewLineForControlBlocks": false, + "semicolons": "ignore", + "trimTrailingWhitespace": true, + "indentSwitchCase": true + } + }, + "command": "configure" + } +Info seq [hh:mm:ss:mss] Format host information updated +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "configure", + "request_seq": 1, + "success": true + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 2, + "type": "request", + "arguments": { + "file": "/home/src/workspaces/project/folder/c.ts", + "pastedText": [ + "const b = foo(\"bar\");" + ], + "pasteLocations": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + } + } + ], + "copiedFrom": { + "file": "/home/src/workspaces/project/b.ts", + "spans": [ + { + "start": { + "line": 2, + "offset": 1 + }, + "end": { + "line": 2, + "offset": 22 + } + } + ] + } + }, + "command": "getPasteEdits" + } +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json projectStateVersion: 2 projectProgramVersion: 1 structureChanged: false structureIsReused:: Completely Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (6) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /home/src/workspaces/project/folder/c.ts SVC-1-1 "const b = foo(\"bar\");" + /home/src/workspaces/project/a.ts Text-1 "export default function foo(name: string): void {\n console.log(name);\n}" + /home/src/workspaces/project/b.ts Text-1 "import foo from \"./a\";\nconst b = foo(\"bar\");" + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] getExportInfoMap: cache miss or empty; calculating new results +Info seq [hh:mm:ss:mss] getExportInfoMap: done in * ms +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "getPasteEdits", + "request_seq": 2, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + }, + "body": { + "edits": [ + { + "fileName": "/home/src/workspaces/project/folder/c.ts", + "textChanges": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + }, + "newText": "import foo from \"../a\";\n\n" + }, + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + }, + "newText": "const b = foo(\"bar\");" + } + ] + } + ], + "fixId": "providePostPasteEdits" + } + } +After Request +Projects:: +/home/src/workspaces/project/tsconfig.json (Configured) *changed* + projectStateVersion: 3 *changed* + projectProgramVersion: 1 + dirty: true *changed* + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/a.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/b.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/folder/c.ts (Open) *changed* + version: SVC-1-2 *changed* + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json *default* diff --git a/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_defaultExport2.js b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_defaultExport2.js new file mode 100644 index 0000000000000..6a5eaf2e4d5c6 --- /dev/null +++ b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_defaultExport2.js @@ -0,0 +1,344 @@ +Info seq [hh:mm:ss:mss] currentDirectory:: /home/src/Vscode/Projects/bin useCaseSensitiveFileNames:: false +Info seq [hh:mm:ss:mss] libs Location:: /home/src/tslibs/TS/Lib +Info seq [hh:mm:ss:mss] globalTypingsCacheLocation:: /home/src/Library/Caches/typescript +Info seq [hh:mm:ss:mss] Provided types map file "/home/src/tslibs/TS/Lib/typesMap.json" doesn't exist +//// [/home/src/tslibs/TS/Lib/lib.d.ts] +lib.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.d.ts] +lib.decorators.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts] +lib.decorators.legacy.d.ts-Text + +//// [/home/src/workspaces/project/a.ts] +const b = foo("bar"); + export default function foo(name: string): void { + console.log(name); + } + +//// [/home/src/workspaces/project/folder/c.ts] + + +//// [/home/src/workspaces/project/tsconfig.json] +{ "files": ["folder/c.ts", "a.ts"] } + + +Info seq [hh:mm:ss:mss] request: + { + "seq": 0, + "type": "request", + "arguments": { + "file": "/home/src/workspaces/project/folder/c.ts" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /home/src/workspaces/project/folder/c.ts ProjectRootPath: undefined:: Result: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] Creating ConfiguredProject: /home/src/workspaces/project/tsconfig.json, currentDirectory: /home/src/workspaces/project +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/tsconfig.json 2000 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] Config: /home/src/workspaces/project/tsconfig.json : { + "rootNames": [ + "/home/src/workspaces/project/folder/c.ts", + "/home/src/workspaces/project/a.ts" + ], + "options": { + "configFilePath": "/home/src/workspaces/project/tsconfig.json" + } +} +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingStart", + "body": { + "projectName": "/home/src/workspaces/project/tsconfig.json", + "reason": "Creating possible configured project for /home/src/workspaces/project/folder/c.ts to open" + } + } +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/a.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (5) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /home/src/workspaces/project/folder/c.ts SVC-1-0 "" + /home/src/workspaces/project/a.ts Text-1 "const b = foo(\"bar\");\n export default function foo(name: string): void {\n console.log(name);\n }" + + + ../../tslibs/TS/Lib/lib.d.ts + Default library for target 'es5' + ../../tslibs/TS/Lib/lib.decorators.d.ts + Library referenced via 'decorators' from file '../../tslibs/TS/Lib/lib.d.ts' + ../../tslibs/TS/Lib/lib.decorators.legacy.d.ts + Library referenced via 'decorators.legacy' from file '../../tslibs/TS/Lib/lib.d.ts' + folder/c.ts + Part of 'files' list in tsconfig.json + a.ts + Part of 'files' list in tsconfig.json + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingFinish", + "body": { + "projectName": "/home/src/workspaces/project/tsconfig.json" + } + } +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "configFileDiag", + "body": { + "triggerFile": "/home/src/workspaces/project/folder/c.ts", + "configFile": "/home/src/workspaces/project/tsconfig.json", + "diagnostics": [] + } + } +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (5) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /home/src/workspaces/project/folder/c.ts ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 0, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/a.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/tsconfig.json: *new* + {"pollingInterval":2000} + +watchedDirectoriesRecursive:: +/home/src/workspaces/node_modules: *new* + {} +/home/src/workspaces/node_modules/@types: *new* + {} +/home/src/workspaces/project/node_modules: *new* + {} +/home/src/workspaces/project/node_modules/@types: *new* + {} + +Projects:: +/home/src/workspaces/project/tsconfig.json (Configured) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/a.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/folder/c.ts (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json *default* + +Info seq [hh:mm:ss:mss] request: + { + "seq": 1, + "type": "request", + "arguments": { + "formatOptions": { + "indentSize": 4, + "tabSize": 4, + "newLineCharacter": "\n", + "convertTabsToSpaces": true, + "indentStyle": 2, + "insertSpaceAfterConstructor": false, + "insertSpaceAfterCommaDelimiter": true, + "insertSpaceAfterSemicolonInForStatements": true, + "insertSpaceBeforeAndAfterBinaryOperators": true, + "insertSpaceAfterKeywordsInControlFlowStatements": true, + "insertSpaceAfterFunctionKeywordForAnonymousFunctions": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, + "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, + "insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, + "insertSpaceBeforeFunctionParenthesis": false, + "placeOpenBraceOnNewLineForFunctions": false, + "placeOpenBraceOnNewLineForControlBlocks": false, + "semicolons": "ignore", + "trimTrailingWhitespace": true, + "indentSwitchCase": true + } + }, + "command": "configure" + } +Info seq [hh:mm:ss:mss] Format host information updated +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "configure", + "request_seq": 1, + "success": true + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 2, + "type": "request", + "arguments": { + "file": "/home/src/workspaces/project/folder/c.ts", + "pastedText": [ + "const b = foo(\"bar\");" + ], + "pasteLocations": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + } + } + ], + "copiedFrom": { + "file": "/home/src/workspaces/project/a.ts", + "spans": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 22 + } + } + ] + } + }, + "command": "getPasteEdits" + } +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json projectStateVersion: 2 projectProgramVersion: 1 structureChanged: false structureIsReused:: Completely Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (5) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /home/src/workspaces/project/folder/c.ts SVC-1-1 "const b = foo(\"bar\");" + /home/src/workspaces/project/a.ts Text-1 "const b = foo(\"bar\");\n export default function foo(name: string): void {\n console.log(name);\n }" + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "getPasteEdits", + "request_seq": 2, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + }, + "body": { + "edits": [ + { + "fileName": "/home/src/workspaces/project/folder/c.ts", + "textChanges": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + }, + "newText": "import foo from \"../a\";\n\n" + }, + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + }, + "newText": "const b = foo(\"bar\");" + } + ] + } + ], + "fixId": "providePostPasteEdits" + } + } +After Request +Projects:: +/home/src/workspaces/project/tsconfig.json (Configured) *changed* + projectStateVersion: 3 *changed* + projectProgramVersion: 1 + dirty: true *changed* + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/a.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/folder/c.ts (Open) *changed* + version: SVC-1-2 *changed* + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json *default* diff --git a/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_defaultImport.js b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_defaultImport.js new file mode 100644 index 0000000000000..a3d38c09021da --- /dev/null +++ b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_defaultImport.js @@ -0,0 +1,387 @@ +Info seq [hh:mm:ss:mss] currentDirectory:: /home/src/Vscode/Projects/bin useCaseSensitiveFileNames:: false +Info seq [hh:mm:ss:mss] libs Location:: /home/src/tslibs/TS/Lib +Info seq [hh:mm:ss:mss] globalTypingsCacheLocation:: /home/src/Library/Caches/typescript +Info seq [hh:mm:ss:mss] Provided types map file "/home/src/tslibs/TS/Lib/typesMap.json" doesn't exist +//// [/home/src/tslibs/TS/Lib/lib.d.ts] +lib.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.d.ts] +lib.decorators.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts] +lib.decorators.legacy.d.ts-Text + +//// [/home/src/workspaces/project/folder/a.ts] +const abc = 10; +const def = 20; +export interface testInterface { + abc: number; + def: number; +} + +//// [/home/src/workspaces/project/folder/b.mts] +import test from "./a.js"; + +function foo(abc: test.testInterface, def: test.testInterface) { + console.log(abc); + console.log(def); +} + + +//// [/home/src/workspaces/project/folder/folder/c.ts] + + +//// [/home/src/workspaces/project/folder/tsconfig.json] +{ "compilerOptions": { "module": "nodenext" }, "files": ["folder/c.ts", "a.ts", "b.mts"] } + + +Info seq [hh:mm:ss:mss] request: + { + "seq": 0, + "type": "request", + "arguments": { + "file": "/home/src/workspaces/project/folder/folder/c.ts" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /home/src/workspaces/project/folder/folder/c.ts ProjectRootPath: undefined:: Result: /home/src/workspaces/project/folder/tsconfig.json +Info seq [hh:mm:ss:mss] Creating ConfiguredProject: /home/src/workspaces/project/folder/tsconfig.json, currentDirectory: /home/src/workspaces/project/folder +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/folder/tsconfig.json 2000 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] Config: /home/src/workspaces/project/folder/tsconfig.json : { + "rootNames": [ + "/home/src/workspaces/project/folder/folder/c.ts", + "/home/src/workspaces/project/folder/a.ts", + "/home/src/workspaces/project/folder/b.mts" + ], + "options": { + "module": 199, + "configFilePath": "/home/src/workspaces/project/folder/tsconfig.json" + } +} +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingStart", + "body": { + "projectName": "/home/src/workspaces/project/folder/tsconfig.json", + "reason": "Creating possible configured project for /home/src/workspaces/project/folder/folder/c.ts to open" + } + } +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/folder/a.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/folder/b.mts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /home/src/workspaces/project/folder/tsconfig.json +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/folder/folder/package.json 2000 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/folder/package.json 2000 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/package.json 2000 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/package.json 2000 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: File location affecting resolution +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.esnext.full.d.ts 500 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: Missing file +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/folder/node_modules/@types 1 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/folder/node_modules/@types 1 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules/@types 1 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules/@types 1 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules/@types 1 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules/@types 1 undefined Project: /home/src/workspaces/project/folder/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /home/src/workspaces/project/folder/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/folder/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (3) + /home/src/workspaces/project/folder/folder/c.ts SVC-1-0 "" + /home/src/workspaces/project/folder/a.ts Text-1 "const abc = 10;\nconst def = 20;\nexport interface testInterface {\n abc: number;\n def: number;\n}" + /home/src/workspaces/project/folder/b.mts Text-1 "import test from \"./a.js\";\n\nfunction foo(abc: test.testInterface, def: test.testInterface) {\n console.log(abc);\n console.log(def);\n}\n" + + + folder/c.ts + Part of 'files' list in tsconfig.json + File is CommonJS module because 'package.json' was not found + a.ts + Part of 'files' list in tsconfig.json + Imported via "./a.js" from file 'b.mts' + File is CommonJS module because 'package.json' was not found + b.mts + Part of 'files' list in tsconfig.json + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingFinish", + "body": { + "projectName": "/home/src/workspaces/project/folder/tsconfig.json" + } + } +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "configFileDiag", + "body": { + "triggerFile": "/home/src/workspaces/project/folder/folder/c.ts", + "configFile": "/home/src/workspaces/project/folder/tsconfig.json", + "diagnostics": [ + { + "text": "File '/home/src/tslibs/TS/Lib/lib.esnext.full.d.ts' not found.\n The file is in the program because:\n Default library for target 'esnext'", + "code": 6053, + "category": "error" + }, + { + "text": "Cannot find global type 'Array'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Boolean'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Function'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'IArguments'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Number'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'Object'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'RegExp'.", + "code": 2318, + "category": "error" + }, + { + "text": "Cannot find global type 'String'.", + "code": 2318, + "category": "error" + } + ] + } + } +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/folder/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (3) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /home/src/workspaces/project/folder/folder/c.ts ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /home/src/workspaces/project/folder/tsconfig.json +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 0, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.esnext.full.d.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/package.json: *new* + {"pollingInterval":2000} +/home/src/workspaces/project/folder/a.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/folder/b.mts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/folder/folder/package.json: *new* + {"pollingInterval":2000} +/home/src/workspaces/project/folder/package.json: *new* + {"pollingInterval":2000} +/home/src/workspaces/project/folder/tsconfig.json: *new* + {"pollingInterval":2000} +/home/src/workspaces/project/package.json: *new* + {"pollingInterval":2000} + +watchedDirectoriesRecursive:: +/home/src/workspaces/node_modules/@types: *new* + {} +/home/src/workspaces/project/folder/node_modules/@types: *new* + {} +/home/src/workspaces/project/node_modules/@types: *new* + {} + +Projects:: +/home/src/workspaces/project/folder/tsconfig.json (Configured) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false + +ScriptInfos:: +/home/src/workspaces/project/folder/a.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/folder/tsconfig.json +/home/src/workspaces/project/folder/b.mts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/folder/tsconfig.json +/home/src/workspaces/project/folder/folder/c.ts (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /home/src/workspaces/project/folder/tsconfig.json *default* + +Info seq [hh:mm:ss:mss] request: + { + "seq": 1, + "type": "request", + "arguments": { + "formatOptions": { + "indentSize": 4, + "tabSize": 4, + "newLineCharacter": "\n", + "convertTabsToSpaces": true, + "indentStyle": 2, + "insertSpaceAfterConstructor": false, + "insertSpaceAfterCommaDelimiter": true, + "insertSpaceAfterSemicolonInForStatements": true, + "insertSpaceBeforeAndAfterBinaryOperators": true, + "insertSpaceAfterKeywordsInControlFlowStatements": true, + "insertSpaceAfterFunctionKeywordForAnonymousFunctions": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, + "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, + "insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, + "insertSpaceBeforeFunctionParenthesis": false, + "placeOpenBraceOnNewLineForFunctions": false, + "placeOpenBraceOnNewLineForControlBlocks": false, + "semicolons": "ignore", + "trimTrailingWhitespace": true, + "indentSwitchCase": true + } + }, + "command": "configure" + } +Info seq [hh:mm:ss:mss] Format host information updated +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "configure", + "request_seq": 1, + "success": true + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 2, + "type": "request", + "arguments": { + "file": "/home/src/workspaces/project/folder/folder/c.ts", + "pastedText": [ + "function foo(abc: test.abc, def: test.def) {\nconsole.log(abc);\nconsole.log(def);\n}" + ], + "pasteLocations": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + } + } + ], + "copiedFrom": { + "file": "/home/src/workspaces/project/folder/b.mts", + "spans": [ + { + "start": { + "line": 3, + "offset": 1 + }, + "end": { + "line": 6, + "offset": 2 + } + } + ] + } + }, + "command": "getPasteEdits" + } +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /home/src/workspaces/project/folder/tsconfig.json +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /home/src/workspaces/project/folder/tsconfig.json projectStateVersion: 2 projectProgramVersion: 1 structureChanged: false structureIsReused:: Completely Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/folder/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (3) + /home/src/workspaces/project/folder/folder/c.ts SVC-1-1 "function foo(abc: test.abc, def: test.def) {\nconsole.log(abc);\nconsole.log(def);\n}" + /home/src/workspaces/project/folder/a.ts Text-1 "const abc = 10;\nconst def = 20;\nexport interface testInterface {\n abc: number;\n def: number;\n}" + /home/src/workspaces/project/folder/b.mts Text-1 "import test from \"./a.js\";\n\nfunction foo(abc: test.testInterface, def: test.testInterface) {\n console.log(abc);\n console.log(def);\n}\n" + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "getPasteEdits", + "request_seq": 2, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + }, + "body": { + "edits": [ + { + "fileName": "/home/src/workspaces/project/folder/folder/c.ts", + "textChanges": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + }, + "newText": "import test from \"../a\";\n\n" + }, + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + }, + "newText": "function foo(abc: test.abc, def: test.def) {\nconsole.log(abc);\nconsole.log(def);\n}" + } + ] + } + ], + "fixId": "providePostPasteEdits" + } + } +After Request +Projects:: +/home/src/workspaces/project/folder/tsconfig.json (Configured) *changed* + projectStateVersion: 3 *changed* + projectProgramVersion: 1 + dirty: true *changed* + autoImportProviderHost: false + +ScriptInfos:: +/home/src/workspaces/project/folder/a.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/folder/tsconfig.json +/home/src/workspaces/project/folder/b.mts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/folder/tsconfig.json +/home/src/workspaces/project/folder/folder/c.ts (Open) *changed* + version: SVC-1-2 *changed* + containingProjects: 1 + /home/src/workspaces/project/folder/tsconfig.json *default* diff --git a/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_namespaceImport.js b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_namespaceImport.js new file mode 100644 index 0000000000000..7cde663d43d2a --- /dev/null +++ b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_namespaceImport.js @@ -0,0 +1,372 @@ +Info seq [hh:mm:ss:mss] currentDirectory:: /home/src/Vscode/Projects/bin useCaseSensitiveFileNames:: false +Info seq [hh:mm:ss:mss] libs Location:: /home/src/tslibs/TS/Lib +Info seq [hh:mm:ss:mss] globalTypingsCacheLocation:: /home/src/Library/Caches/typescript +Info seq [hh:mm:ss:mss] Provided types map file "/home/src/tslibs/TS/Lib/typesMap.json" doesn't exist +//// [/home/src/tslibs/TS/Lib/lib.d.ts] +lib.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.d.ts] +lib.decorators.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts] +lib.decorators.legacy.d.ts-Text + +//// [/home/src/workspaces/project/a.ts] +const abc = 10; +const def = 20; +export interface testInterface { + abc: number; + def: number; +} + +//// [/home/src/workspaces/project/b.ts] +import * as test from "./a"; + +function foo(abc: test.abc, def: test.def) { + console.log(abc); + console.log(def); +} + + +//// [/home/src/workspaces/project/folder/c.ts] + + +//// [/home/src/workspaces/project/tsconfig.json] +{ "files": ["folder/c.ts", "a.ts", "b.ts"] } + + +Info seq [hh:mm:ss:mss] request: + { + "seq": 0, + "type": "request", + "arguments": { + "file": "/home/src/workspaces/project/folder/c.ts" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /home/src/workspaces/project/folder/c.ts ProjectRootPath: undefined:: Result: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] Creating ConfiguredProject: /home/src/workspaces/project/tsconfig.json, currentDirectory: /home/src/workspaces/project +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/tsconfig.json 2000 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] Config: /home/src/workspaces/project/tsconfig.json : { + "rootNames": [ + "/home/src/workspaces/project/folder/c.ts", + "/home/src/workspaces/project/a.ts", + "/home/src/workspaces/project/b.ts" + ], + "options": { + "configFilePath": "/home/src/workspaces/project/tsconfig.json" + } +} +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingStart", + "body": { + "projectName": "/home/src/workspaces/project/tsconfig.json", + "reason": "Creating possible configured project for /home/src/workspaces/project/folder/c.ts to open" + } + } +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/a.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/b.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (6) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /home/src/workspaces/project/folder/c.ts SVC-1-0 "" + /home/src/workspaces/project/a.ts Text-1 "const abc = 10;\nconst def = 20;\nexport interface testInterface {\n abc: number;\n def: number;\n}" + /home/src/workspaces/project/b.ts Text-1 "import * as test from \"./a\";\n\nfunction foo(abc: test.abc, def: test.def) {\n console.log(abc);\n console.log(def);\n}\n" + + + ../../tslibs/TS/Lib/lib.d.ts + Default library for target 'es5' + ../../tslibs/TS/Lib/lib.decorators.d.ts + Library referenced via 'decorators' from file '../../tslibs/TS/Lib/lib.d.ts' + ../../tslibs/TS/Lib/lib.decorators.legacy.d.ts + Library referenced via 'decorators.legacy' from file '../../tslibs/TS/Lib/lib.d.ts' + folder/c.ts + Part of 'files' list in tsconfig.json + a.ts + Part of 'files' list in tsconfig.json + Imported via "./a" from file 'b.ts' + b.ts + Part of 'files' list in tsconfig.json + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingFinish", + "body": { + "projectName": "/home/src/workspaces/project/tsconfig.json" + } + } +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "configFileDiag", + "body": { + "triggerFile": "/home/src/workspaces/project/folder/c.ts", + "configFile": "/home/src/workspaces/project/tsconfig.json", + "diagnostics": [] + } + } +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (6) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /home/src/workspaces/project/folder/c.ts ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 0, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/a.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/b.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/tsconfig.json: *new* + {"pollingInterval":2000} + +watchedDirectoriesRecursive:: +/home/src/workspaces/node_modules: *new* + {} +/home/src/workspaces/node_modules/@types: *new* + {} +/home/src/workspaces/project/node_modules: *new* + {} +/home/src/workspaces/project/node_modules/@types: *new* + {} + +Projects:: +/home/src/workspaces/project/tsconfig.json (Configured) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/a.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/b.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/folder/c.ts (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json *default* + +Info seq [hh:mm:ss:mss] request: + { + "seq": 1, + "type": "request", + "arguments": { + "formatOptions": { + "indentSize": 4, + "tabSize": 4, + "newLineCharacter": "\n", + "convertTabsToSpaces": true, + "indentStyle": 2, + "insertSpaceAfterConstructor": false, + "insertSpaceAfterCommaDelimiter": true, + "insertSpaceAfterSemicolonInForStatements": true, + "insertSpaceBeforeAndAfterBinaryOperators": true, + "insertSpaceAfterKeywordsInControlFlowStatements": true, + "insertSpaceAfterFunctionKeywordForAnonymousFunctions": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, + "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, + "insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, + "insertSpaceBeforeFunctionParenthesis": false, + "placeOpenBraceOnNewLineForFunctions": false, + "placeOpenBraceOnNewLineForControlBlocks": false, + "semicolons": "ignore", + "trimTrailingWhitespace": true, + "indentSwitchCase": true + } + }, + "command": "configure" + } +Info seq [hh:mm:ss:mss] Format host information updated +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "configure", + "request_seq": 1, + "success": true + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 2, + "type": "request", + "arguments": { + "file": "/home/src/workspaces/project/folder/c.ts", + "pastedText": [ + "function foo(abc: test.abc, def: test.def) {\nconsole.log(abc);\nconsole.log(def);\n}" + ], + "pasteLocations": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + } + } + ], + "copiedFrom": { + "file": "/home/src/workspaces/project/b.ts", + "spans": [ + { + "start": { + "line": 3, + "offset": 1 + }, + "end": { + "line": 6, + "offset": 2 + } + } + ] + } + }, + "command": "getPasteEdits" + } +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json projectStateVersion: 2 projectProgramVersion: 1 structureChanged: false structureIsReused:: Completely Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (6) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /home/src/workspaces/project/folder/c.ts SVC-1-1 "function foo(abc: test.abc, def: test.def) {\nconsole.log(abc);\nconsole.log(def);\n}" + /home/src/workspaces/project/a.ts Text-1 "const abc = 10;\nconst def = 20;\nexport interface testInterface {\n abc: number;\n def: number;\n}" + /home/src/workspaces/project/b.ts Text-1 "import * as test from \"./a\";\n\nfunction foo(abc: test.abc, def: test.def) {\n console.log(abc);\n console.log(def);\n}\n" + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "getPasteEdits", + "request_seq": 2, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + }, + "body": { + "edits": [ + { + "fileName": "/home/src/workspaces/project/folder/c.ts", + "textChanges": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + }, + "newText": "import * as test from \"../a\";\n\n" + }, + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + }, + "newText": "function foo(abc: test.abc, def: test.def) {\nconsole.log(abc);\nconsole.log(def);\n}" + } + ] + } + ], + "fixId": "providePostPasteEdits" + } + } +After Request +Projects:: +/home/src/workspaces/project/tsconfig.json (Configured) *changed* + projectStateVersion: 3 *changed* + projectProgramVersion: 1 + dirty: true *changed* + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/a.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/b.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/folder/c.ts (Open) *changed* + version: SVC-1-2 *changed* + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json *default* diff --git a/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_requireImportJsx.js b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_requireImportJsx.js new file mode 100644 index 0000000000000..7ca17ad0ab4ef --- /dev/null +++ b/tests/baselines/reference/tsserver/fourslashServer/pasteEdits_requireImportJsx.js @@ -0,0 +1,377 @@ +Info seq [hh:mm:ss:mss] currentDirectory:: /home/src/Vscode/Projects/bin useCaseSensitiveFileNames:: false +Info seq [hh:mm:ss:mss] libs Location:: /home/src/tslibs/TS/Lib +Info seq [hh:mm:ss:mss] globalTypingsCacheLocation:: /home/src/Library/Caches/typescript +Info seq [hh:mm:ss:mss] Provided types map file "/home/src/tslibs/TS/Lib/typesMap.json" doesn't exist +//// [/home/src/tslibs/TS/Lib/lib.d.ts] +lib.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.d.ts] +lib.decorators.d.ts-Text + +//// [/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts] +lib.decorators.legacy.d.ts-Text + +//// [/home/src/workspaces/project/b.jsx] +import React = require("./react"); + +class MyComponent extends React.Component { + render() { + return
; + } +} + +//// [/home/src/workspaces/project/folder/c.jsx] + + +//// [/home/src/workspaces/project/react.d.ts] +export = React; +export as namespace React; +declare namespace React { + class Component {} +} + +//// [/home/src/workspaces/project/tsconfig.json] +{ "files": ["folder/c.jsx", "react.d.ts", "b.jsx"] } + + +Info seq [hh:mm:ss:mss] request: + { + "seq": 0, + "type": "request", + "arguments": { + "file": "/home/src/workspaces/project/folder/c.jsx" + }, + "command": "open" + } +Info seq [hh:mm:ss:mss] getConfigFileNameForFile:: File: /home/src/workspaces/project/folder/c.jsx ProjectRootPath: undefined:: Result: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] Creating ConfiguredProject: /home/src/workspaces/project/tsconfig.json, currentDirectory: /home/src/workspaces/project +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/tsconfig.json 2000 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Config file +Info seq [hh:mm:ss:mss] Config: /home/src/workspaces/project/tsconfig.json : { + "rootNames": [ + "/home/src/workspaces/project/folder/c.jsx", + "/home/src/workspaces/project/react.d.ts", + "/home/src/workspaces/project/b.jsx" + ], + "options": { + "configFilePath": "/home/src/workspaces/project/tsconfig.json" + } +} +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingStart", + "body": { + "projectName": "/home/src/workspaces/project/tsconfig.json", + "reason": "Creating possible configured project for /home/src/workspaces/project/folder/c.jsx to open" + } + } +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/react.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/workspaces/project/b.jsx 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project 0 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project 0 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Failed Lookup Locations +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts 500 undefined WatchType: Closed Script info +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/project/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/workspaces/node_modules/@types 1 undefined Project: /home/src/workspaces/project/tsconfig.json WatchType: Type roots +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json projectStateVersion: 1 projectProgramVersion: 0 structureChanged: true structureIsReused:: Not Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (6) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /home/src/workspaces/project/folder/c.jsx SVC-1-0 "" + /home/src/workspaces/project/react.d.ts Text-1 "export = React;\nexport as namespace React;\ndeclare namespace React {\n class Component {}\n}" + /home/src/workspaces/project/b.jsx Text-1 "import React = require(\"./react\");\n\nclass MyComponent extends React.Component {\n render() {\n return
;\n }\n}" + + + ../../tslibs/TS/Lib/lib.d.ts + Default library for target 'es5' + ../../tslibs/TS/Lib/lib.decorators.d.ts + Library referenced via 'decorators' from file '../../tslibs/TS/Lib/lib.d.ts' + ../../tslibs/TS/Lib/lib.decorators.legacy.d.ts + Library referenced via 'decorators.legacy' from file '../../tslibs/TS/Lib/lib.d.ts' + folder/c.jsx + Part of 'files' list in tsconfig.json + react.d.ts + Part of 'files' list in tsconfig.json + Imported via "./react" from file 'b.jsx' + b.jsx + Part of 'files' list in tsconfig.json + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "projectLoadingFinish", + "body": { + "projectName": "/home/src/workspaces/project/tsconfig.json" + } + } +Info seq [hh:mm:ss:mss] event: + { + "seq": 0, + "type": "event", + "event": "configFileDiag", + "body": { + "triggerFile": "/home/src/workspaces/project/folder/c.jsx", + "configFile": "/home/src/workspaces/project/tsconfig.json", + "diagnostics": [] + } + } +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (6) + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] Open files: +Info seq [hh:mm:ss:mss] FileName: /home/src/workspaces/project/folder/c.jsx ProjectRootPath: undefined +Info seq [hh:mm:ss:mss] Projects: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "open", + "request_seq": 0, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + } + } +After Request +watchedFiles:: +/home/src/tslibs/TS/Lib/lib.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.d.ts: *new* + {"pollingInterval":500} +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/b.jsx: *new* + {"pollingInterval":500} +/home/src/workspaces/project/react.d.ts: *new* + {"pollingInterval":500} +/home/src/workspaces/project/tsconfig.json: *new* + {"pollingInterval":2000} + +watchedDirectories:: +/home/src/workspaces/project: *new* + {} + +watchedDirectoriesRecursive:: +/home/src/workspaces/node_modules: *new* + {} +/home/src/workspaces/node_modules/@types: *new* + {} +/home/src/workspaces/project/node_modules: *new* + {} +/home/src/workspaces/project/node_modules/@types: *new* + {} + +Projects:: +/home/src/workspaces/project/tsconfig.json (Configured) *new* + projectStateVersion: 1 + projectProgramVersion: 1 + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/b.jsx *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/folder/c.jsx (Open) *new* + version: SVC-1-0 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json *default* +/home/src/workspaces/project/react.d.ts *new* + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json + +Info seq [hh:mm:ss:mss] request: + { + "seq": 1, + "type": "request", + "arguments": { + "formatOptions": { + "indentSize": 4, + "tabSize": 4, + "newLineCharacter": "\n", + "convertTabsToSpaces": true, + "indentStyle": 2, + "insertSpaceAfterConstructor": false, + "insertSpaceAfterCommaDelimiter": true, + "insertSpaceAfterSemicolonInForStatements": true, + "insertSpaceBeforeAndAfterBinaryOperators": true, + "insertSpaceAfterKeywordsInControlFlowStatements": true, + "insertSpaceAfterFunctionKeywordForAnonymousFunctions": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, + "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, + "insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, + "insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, + "insertSpaceBeforeFunctionParenthesis": false, + "placeOpenBraceOnNewLineForFunctions": false, + "placeOpenBraceOnNewLineForControlBlocks": false, + "semicolons": "ignore", + "trimTrailingWhitespace": true, + "indentSwitchCase": true + } + }, + "command": "configure" + } +Info seq [hh:mm:ss:mss] Format host information updated +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "configure", + "request_seq": 1, + "success": true + } +Info seq [hh:mm:ss:mss] request: + { + "seq": 2, + "type": "request", + "arguments": { + "file": "/home/src/workspaces/project/folder/c.jsx", + "pastedText": [ + "class MyComponent extends React.Component {\n render() {\n return
;\n }\n}" + ], + "pasteLocations": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + } + } + ], + "copiedFrom": { + "file": "/home/src/workspaces/project/b.jsx", + "spans": [ + { + "start": { + "line": 3, + "offset": 1 + }, + "end": { + "line": 7, + "offset": 2 + } + } + ] + } + }, + "command": "getPasteEdits" + } +Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json +Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /home/src/workspaces/project/tsconfig.json projectStateVersion: 2 projectProgramVersion: 1 structureChanged: false structureIsReused:: Completely Elapsed:: *ms +Info seq [hh:mm:ss:mss] Project '/home/src/workspaces/project/tsconfig.json' (Configured) +Info seq [hh:mm:ss:mss] Files (6) + /home/src/tslibs/TS/Lib/lib.d.ts Text-1 lib.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.d.ts Text-1 lib.decorators.d.ts-Text + /home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts Text-1 lib.decorators.legacy.d.ts-Text + /home/src/workspaces/project/folder/c.jsx SVC-1-1 "class MyComponent extends React.Component {\n render() {\n return
;\n }\n}" + /home/src/workspaces/project/react.d.ts Text-1 "export = React;\nexport as namespace React;\ndeclare namespace React {\n class Component {}\n}" + /home/src/workspaces/project/b.jsx Text-1 "import React = require(\"./react\");\n\nclass MyComponent extends React.Component {\n render() {\n return
;\n }\n}" + +Info seq [hh:mm:ss:mss] ----------------------------------------------- +Info seq [hh:mm:ss:mss] response: + { + "seq": 0, + "type": "response", + "command": "getPasteEdits", + "request_seq": 2, + "success": true, + "performanceData": { + "updateGraphDurationMs": * + }, + "body": { + "edits": [ + { + "fileName": "/home/src/workspaces/project/folder/c.jsx", + "textChanges": [ + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + }, + "newText": "const React = require(\"../react\");\n\n" + }, + { + "start": { + "line": 1, + "offset": 1 + }, + "end": { + "line": 1, + "offset": 1 + }, + "newText": "class MyComponent extends React.Component {\n render() {\n return
;\n }\n}" + } + ] + } + ], + "fixId": "providePostPasteEdits" + } + } +After Request +Projects:: +/home/src/workspaces/project/tsconfig.json (Configured) *changed* + projectStateVersion: 3 *changed* + projectProgramVersion: 1 + dirty: true *changed* + autoImportProviderHost: false + +ScriptInfos:: +/home/src/tslibs/TS/Lib/lib.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/tslibs/TS/Lib/lib.decorators.legacy.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/b.jsx + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json +/home/src/workspaces/project/folder/c.jsx (Open) *changed* + version: SVC-1-2 *changed* + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json *default* +/home/src/workspaces/project/react.d.ts + version: Text-1 + containingProjects: 1 + /home/src/workspaces/project/tsconfig.json diff --git a/tests/cases/fourslash/moveToFile_namespaceImport.ts b/tests/cases/fourslash/moveToFile_namespaceImport.ts new file mode 100644 index 0000000000000..443cf161535f9 --- /dev/null +++ b/tests/cases/fourslash/moveToFile_namespaceImport.ts @@ -0,0 +1,33 @@ +/// + +// @Filename: /a.ts +//// export type ExecutionPoint = string; +//// + +// @Filename: /b.ts +//// import * as A from "./a"; +//// +//// [|async function fn1(point: A.ExecutionPoint) {}|] +//// +//// async function fn2(point: A.ExecutionPoint) {} +//// + +// @Filename: /point.ts +//// + +verify.moveToFile({ + newFileContents: { + "/b.ts": +`import * as A from "./a"; + +async function fn2(point: A.ExecutionPoint) {} +`, + "/point.ts": +`import * as A from "./a"; + + +async function fn1(point: A.ExecutionPoint) { } +`, + }, + interactiveRefactorArguments: { targetFile: "/point.ts" }, +}); \ No newline at end of file diff --git a/tests/cases/fourslash/moveToNewFile_aliasDefaultExportNamedImport.ts b/tests/cases/fourslash/moveToNewFile_aliasDefaultExportNamedImport.ts new file mode 100644 index 0000000000000..2db768ae54e4c --- /dev/null +++ b/tests/cases/fourslash/moveToNewFile_aliasDefaultExportNamedImport.ts @@ -0,0 +1,35 @@ +/// + +// @Filename: /node_modules/use-react/index.d.ts +///// export { default as useLatest } from './useLatest'; + +// @Filename: /node_modules/use-react/index.d.ts +//// declare const useLatest: (value: T) => { +//// readonly current: T; +//// }; +//// export default useLatest; +//// + +// @Filename: /test.ts +//// import { useLatest } from 'react-use'; +//// +//// [|export function useUseLatest(data: string) { +//// return useLatest(data); +//// }|] + +verify.moveToNewFile({ + newFileContents: { + "/test.ts": +` +`, + + "/useUseLatest.ts": +`import { useLatest } from 'react-use'; + + +export function useUseLatest(data: string) { + return useLatest(data); +} +`, + }, +}); \ No newline at end of file diff --git a/tests/cases/fourslash/moveToNewFile_namespaceExport.ts b/tests/cases/fourslash/moveToNewFile_namespaceExport.ts new file mode 100644 index 0000000000000..eaa26394b482d --- /dev/null +++ b/tests/cases/fourslash/moveToNewFile_namespaceExport.ts @@ -0,0 +1,25 @@ +/// + +// @module: esnext + +// @filename: /a.ts +////export interface A {} + +// @filename: /b.ts +////export * as A from "./a"; +////export type B = string + +// @filename: /c.ts +////import { A } from "./b" +////[|type B = A.B|] + +verify.moveToNewFile({ + newFileContents: { + "/c.ts": '', + "/B.1.ts": +`import { A } from "./a"; + +type B = A.B; +`, + }, +}); \ No newline at end of file diff --git a/tests/cases/fourslash/moveToNewFile_namespaceTypeImport.ts b/tests/cases/fourslash/moveToNewFile_namespaceTypeImport.ts new file mode 100644 index 0000000000000..e5c48b342373e --- /dev/null +++ b/tests/cases/fourslash/moveToNewFile_namespaceTypeImport.ts @@ -0,0 +1,39 @@ +// @filename: /src/test.ts +//// import type * as ambient from "ambient"; +//// +//// [|export class Yadda { +//// foo(): ambient.Thing { +//// throw new Error("not implemented"); +//// } +//// +//// bar(): ambient.DoesNotExist { +//// throw new Error("not implemented"); +//// } +//// }|] + +// @filename: /src/globals.ts +//// declare module "ambient" { +//// export interface Thing {} +//// } + +verify.moveToNewFile({ + newFileContents: { + "/src/test.ts": +` +`, + "/src/Yadda.ts": +`import type * as ambient from "ambient"; + + +export class Yadda { + foo(): ambient.Thing { + throw new Error("not implemented"); + } + + bar(): ambient.DoesNotExist { + throw new Error("not implemented"); + } +} +` + } +}); diff --git a/tests/cases/fourslash/moveToNewFile_reactDefaultImport.ts b/tests/cases/fourslash/moveToNewFile_reactDefaultImport.ts new file mode 100644 index 0000000000000..49ad5794ad6dd --- /dev/null +++ b/tests/cases/fourslash/moveToNewFile_reactDefaultImport.ts @@ -0,0 +1,41 @@ +/// + +// @jsx: react +// @module: esnext +// @target: es2020 +// @moduleResolution: bundler + +// @Filename: /node_modules/react/index.d.ts +//// export = React; +//// export as namespace React; +//// declare namespace React { +//// class Component {} +//// } + +// @Filename: /src/main.tsx +//// import React from "react"; +//// +//// [|class MyComponent extends React.Component { +//// render() { +//// return
; +//// } +//// }|] + + +// this test only crashes with bundler and non-preserve +verify.moveToNewFile({ + newFileContents: { + "/src/main.tsx": +` +`, + "/src/MyComponent.tsx": +`import React from "react"; + +class MyComponent extends React.Component { + render() { + return
; + } +} +` + } +}); diff --git a/tests/cases/fourslash/moveToNewFile_reactNamespaceImport.ts b/tests/cases/fourslash/moveToNewFile_reactNamespaceImport.ts new file mode 100644 index 0000000000000..2dff4b1014877 --- /dev/null +++ b/tests/cases/fourslash/moveToNewFile_reactNamespaceImport.ts @@ -0,0 +1,44 @@ +/// + +// @jsx: preserve + +// @Filename: /node_modules/react/index.d.ts +////export = React; +////export as namespace React; +////declare namespace React { +//// class Component {} +////} + +// @Filename: /src/main.tsx +//// import * as React from 'react'; +//// +//// export const main = () => {}; +//// +//// [|interface SProps { +//// children: string; +//// } +//// +//// function SidebarSection({children}: SProps) { +//// return
{children}
; +//// }|] + + +verify.moveToNewFile({ + newFileContents: { + "/src/main.tsx": +` +export const main = () => {}; + +`, + "/src/SProps.tsx": +`import * as React from 'react'; + +interface SProps { + children: string; +} +function SidebarSection({ children }: SProps) { + return
{children}
; +} +` + } +}); diff --git a/tests/cases/fourslash/server/pasteEdits_blankTargetFile.ts b/tests/cases/fourslash/server/pasteEdits_blankTargetFile.ts index 97cd869cd74a7..711f50eaed1b8 100644 --- a/tests/cases/fourslash/server/pasteEdits_blankTargetFile.ts +++ b/tests/cases/fourslash/server/pasteEdits_blankTargetFile.ts @@ -1,6 +1,6 @@ /// -// @Filename: /home/src/workspaces/project/c.ts +// @Filename: /home/src/workspaces/project/folder/c.ts ////[||] // @Filename: /home/src/workspaces/project/a.ts @@ -15,7 +15,7 @@ //// console.log("abc"); // @Filename: /home/src/workspaces/project/tsconfig.json -////{ "files": ["c.ts", "a.ts", "b.ts"] } +////{ "files": ["folder/c.ts", "a.ts", "b.ts"] } const ranges = test.ranges(); verify.pasteEdits({ @@ -25,8 +25,8 @@ verify.pasteEdits({ copiedFrom: { file: "/home/src/workspaces/project/b.ts", range: [ranges[1]] }, }, newFileContents: { - "/home/src/workspaces/project/c.ts": -`import { abc } from "./a"; + "/home/src/workspaces/project/folder/c.ts": +`import { abc } from "../a"; console.log(abc);` } diff --git a/tests/cases/fourslash/server/pasteEdits_defaultExport1.ts b/tests/cases/fourslash/server/pasteEdits_defaultExport1.ts new file mode 100644 index 0000000000000..c04342ef37ab4 --- /dev/null +++ b/tests/cases/fourslash/server/pasteEdits_defaultExport1.ts @@ -0,0 +1,31 @@ +/// + +// @Filename: /home/src/workspaces/project/folder/c.ts +////[||] + +// @Filename: /home/src/workspaces/project/b.ts +////import foo from "./a"; +////[|const b = foo("bar");|] + +// @Filename: /home/src/workspaces/project/a.ts +//// export default function foo(name: string): void { +//// console.log(name); +//// } + +// @Filename: /home/src/workspaces/project/tsconfig.json +////{ "files": ["folder/c.ts", "a.ts", "b.ts"] } + +const range = test.ranges(); +verify.pasteEdits({ + args: { + pastedText: [`const b = foo("bar");`], + pasteLocations: [range[0]], + copiedFrom: { file: "/home/src/workspaces/project/b.ts", range: [range[1]] }, + }, + newFileContents: { + "/home/src/workspaces/project/folder/c.ts": +`import foo from "../a"; + +const b = foo("bar");` + } +}); \ No newline at end of file diff --git a/tests/cases/fourslash/server/pasteEdits_defaultExport2.ts b/tests/cases/fourslash/server/pasteEdits_defaultExport2.ts new file mode 100644 index 0000000000000..bb8adbc78a522 --- /dev/null +++ b/tests/cases/fourslash/server/pasteEdits_defaultExport2.ts @@ -0,0 +1,28 @@ +/// + +// @Filename: /home/src/workspaces/project/folder/c.ts +////[||] + +// @Filename: /home/src/workspaces/project/a.ts +////[|const b = foo("bar");|] +//// export default function foo(name: string): void { +//// console.log(name); +//// } + +// @Filename: /home/src/workspaces/project/tsconfig.json +////{ "files": ["folder/c.ts", "a.ts"] } + +const range = test.ranges(); +verify.pasteEdits({ + args: { + pastedText: [`const b = foo("bar");`], + pasteLocations: [range[0]], + copiedFrom: { file: "/home/src/workspaces/project/a.ts", range: [range[1]] }, + }, + newFileContents: { + "/home/src/workspaces/project/folder/c.ts": +`import foo from "../a"; + +const b = foo("bar");` + } +}); \ No newline at end of file diff --git a/tests/cases/fourslash/server/pasteEdits_defaultImport.ts b/tests/cases/fourslash/server/pasteEdits_defaultImport.ts new file mode 100644 index 0000000000000..d2eafb4291c45 --- /dev/null +++ b/tests/cases/fourslash/server/pasteEdits_defaultImport.ts @@ -0,0 +1,45 @@ +/// + +// @Filename: /home/src/workspaces/project/folder/folder/c.ts +//// [||] + +// @Filename: /home/src/workspaces/project/folder/b.mts +//// import test from "./a.js"; +//// +//// [|function foo(abc: test.testInterface, def: test.testInterface) { +//// console.log(abc); +//// console.log(def); +//// }|] +//// + +// @Filename: /home/src/workspaces/project/folder/a.ts +//// const abc = 10; +//// const def = 20; +//// export interface testInterface { +//// abc: number; +//// def: number; +//// } + +// @Filename: /home/src/workspaces/project/folder/tsconfig.json +////{ "compilerOptions": { "module": "nodenext" }, "files": ["folder/c.ts", "a.ts", "b.mts"] } + +const range = test.ranges(); +verify.pasteEdits({ + args: { + pastedText: [`function foo(abc: test.abc, def: test.def) { +console.log(abc); +console.log(def); +}`], + pasteLocations: [range[0]], + copiedFrom: { file: "/home/src/workspaces/project/folder/b.mts", range: [range[1]] }, + }, + newFileContents: { + "/home/src/workspaces/project/folder/folder/c.ts": +`import test from "../a"; + +function foo(abc: test.abc, def: test.def) { +console.log(abc); +console.log(def); +}` + } +}); \ No newline at end of file diff --git a/tests/cases/fourslash/server/pasteEdits_namespaceImport.ts b/tests/cases/fourslash/server/pasteEdits_namespaceImport.ts new file mode 100644 index 0000000000000..ded500926fa96 --- /dev/null +++ b/tests/cases/fourslash/server/pasteEdits_namespaceImport.ts @@ -0,0 +1,46 @@ +/// + +// @Filename: /home/src/workspaces/project/folder/c.ts +//// [||] + + +// @Filename: /home/src/workspaces/project/a.ts +//// const abc = 10; +//// const def = 20; +//// export interface testInterface { +//// abc: number; +//// def: number; +//// } + +// @Filename: /home/src/workspaces/project/b.ts +//// import * as test from "./a"; +//// +//// [|function foo(abc: test.abc, def: test.def) { +//// console.log(abc); +//// console.log(def); +//// }|] +//// + +// @Filename: /home/src/workspaces/project/tsconfig.json +////{ "files": ["folder/c.ts", "a.ts", "b.ts"] } + +const range = test.ranges(); +verify.pasteEdits({ + args: { + pastedText: [`function foo(abc: test.abc, def: test.def) { +console.log(abc); +console.log(def); +}`], + pasteLocations: [range[0]], + copiedFrom: { file: "/home/src/workspaces/project/b.ts", range: [range[1]] }, + }, + newFileContents: { + "/home/src/workspaces/project/folder/c.ts": +`import * as test from "../a"; + +function foo(abc: test.abc, def: test.def) { +console.log(abc); +console.log(def); +}` + } +}); \ No newline at end of file diff --git a/tests/cases/fourslash/server/pasteEdits_requireImportJsx.ts b/tests/cases/fourslash/server/pasteEdits_requireImportJsx.ts new file mode 100644 index 0000000000000..f7be3b8f61c4a --- /dev/null +++ b/tests/cases/fourslash/server/pasteEdits_requireImportJsx.ts @@ -0,0 +1,47 @@ +/// + +// @Filename: /home/src/workspaces/project/folder/c.jsx +//// [||] + +// @Filename: /home/src/workspaces/project/b.jsx +//// import React = require("./react"); +//// +//// [|class MyComponent extends React.Component { +//// render() { +//// return
; +//// } +//// }|] + +// @Filename: /home/src/workspaces/project/react.d.ts +////export = React; +////export as namespace React; +////declare namespace React { +//// class Component {} +////} + +// @Filename: /home/src/workspaces/project/tsconfig.json +////{ "files": ["folder/c.jsx", "react.d.ts", "b.jsx"] } + +const range = test.ranges(); +verify.pasteEdits({ + args: { + pastedText: +[`class MyComponent extends React.Component { + render() { + return
; + } +}`], + pasteLocations: [range[0]], + copiedFrom: { file: "/home/src/workspaces/project/b.jsx", range: [range[1]] }, + }, + newFileContents: { + "/home/src/workspaces/project/folder/c.jsx": +`const React = require("../react"); + +class MyComponent extends React.Component { + render() { + return
; + } +}` + } +}); \ No newline at end of file