From 77494d629468533cbb237ece5f18a6d7ad306b2f Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 7 Aug 2018 15:35:43 -0700 Subject: [PATCH 1/4] getScriptInfoOrConfig: Canonicalize tsconfig path before lookup --- src/server/editorServices.ts | 2 +- .../unittests/tsserverProjectSystem.ts | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 56026bb70d46f..895ba0cbc3946 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 c89d29ffc5b51..7e41cf44201ea 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), From ac460e30e74f40ffc84d1868d975be2297cc4832 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 10 Aug 2018 11:50:39 -0700 Subject: [PATCH 2/4] code review --- src/server/editorServices.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 895ba0cbc3946..9a74ff3e53f86 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(this.toCanonicalFileName(uncheckedFileName)); + const configProject = this.configuredProjects.get(this.toCanonicalFileName(path)); return configProject && configProject.getCompilerOptions().configFile; } From 0f5d62630b7faa5b0820a8859bd5159d9472366e Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 17 Sep 2018 11:26:35 -0700 Subject: [PATCH 3/4] Use this.toPath --- src/server/editorServices.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 21eb931d49191..606e3bbe4051e 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1884,7 +1884,7 @@ namespace ts.server { const path = toNormalizedPath(uncheckedFileName); const info = this.getScriptInfoForNormalizedPath(path); if (info) return info; - const configProject = this.configuredProjects.get(this.toCanonicalFileName(path)); + const configProject = this.configuredProjects.get(this.toPath(uncheckedFileName)); return configProject && configProject.getCompilerOptions().configFile; } From 76c9d9f71758b31c885bef994311bf90928503c7 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 8 Jan 2019 16:08:43 -0800 Subject: [PATCH 4/4] Fix the failing test case --- src/testRunner/unittests/tsserver/refactors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testRunner/unittests/tsserver/refactors.ts b/src/testRunner/unittests/tsserver/refactors.ts index 31603ded8cd3b..04eb552c31614 100644 --- a/src/testRunner/unittests/tsserver/refactors.ts +++ b/src/testRunner/unittests/tsserver/refactors.ts @@ -144,7 +144,7 @@ namespace ts.projectSystem { }, { fileName: "/Foo/x.ts", - textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: "const x = 0;" }], + textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: "const x = 0;\n" }], }, ], renameFilename: undefined,