diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 56026bb70d4..895ba0cbc39 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1804,7 +1804,7 @@ namespace ts.server { const path = toNormalizedPath(uncheckedFileName); const info = this.getScriptInfoForNormalizedPath(path); if (info) return info; - const configProject = this.configuredProjects.get(uncheckedFileName); + const configProject = this.configuredProjects.get(this.toCanonicalFileName(uncheckedFileName)); return configProject && configProject.getCompilerOptions().configFile; } diff --git a/src/testRunner/unittests/tsserverProjectSystem.ts b/src/testRunner/unittests/tsserverProjectSystem.ts index c89d29ffc5b..7e41cf44201 100644 --- a/src/testRunner/unittests/tsserverProjectSystem.ts +++ b/src/testRunner/unittests/tsserverProjectSystem.ts @@ -9717,6 +9717,43 @@ export function Test2() { }); }); + describe("tsserverProjectSystem refactors", () => { + it("handles canonicalization of tsconfig path", () => { + const aTs: File = { path: "/Foo/a.ts", content: "const x = 0;" }; + const tsconfig: File = { path: "/Foo/tsconfig.json", content: '{ "files": ["./a.ts"] }' }; + const session = createSession(createServerHost([aTs, tsconfig])); + openFilesForSession([aTs], session); + + const result = executeSessionRequest(session, protocol.CommandTypes.GetEditsForRefactor, { + file: aTs.path, + startLine: 1, + startOffset: 1, + endLine: 2, + endOffset: aTs.content.length, + refactor: "Move to a new file", + action: "Move to a new file", + }); + assert.deepEqual(result, { + edits: [ + { + fileName: aTs.path, + textChanges: [{ start: { line: 1, offset: 1 }, end: { line: 1, offset: aTs.content.length + 1 }, newText: "" }], + }, + { + fileName: tsconfig.path, + textChanges: [{ start: { line: 1, offset: 21 }, end: { line: 1, offset: 21 }, newText: ', "./x.ts"' }], + }, + { + fileName: "/Foo/x.ts", + textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: "const x = 0;" }], + }, + ], + renameFilename: undefined, + renameLocation: undefined, + }); + }); + }); + function makeReferenceItem(file: File, isDefinition: boolean, text: string, lineText: string, options?: SpanFromSubstringOptions): protocol.ReferencesResponseItem { return { ...protocolFileSpanFromSubstring(file, text, options),