Skip to content

Commit 85e6c2f

Browse files
authored
Merge pull request #26280 from Microsoft/tsconfig_canonicalpath
getScriptInfoOrConfig: Canonicalize tsconfig path before lookup
2 parents 4c70bf0 + 76c9d9f commit 85e6c2f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@ namespace ts.server {
20082008
const path = toNormalizedPath(uncheckedFileName);
20092009
const info = this.getScriptInfoForNormalizedPath(path);
20102010
if (info) return info;
2011-
const configProject = this.configuredProjects.get(uncheckedFileName);
2011+
const configProject = this.configuredProjects.get(this.toPath(uncheckedFileName));
20122012
return configProject && configProject.getCompilerOptions().configFile;
20132013
}
20142014

src/testRunner/unittests/tsserver/refactors.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,40 @@ namespace ts.projectSystem {
116116
renameLocation: undefined,
117117
});
118118
});
119+
120+
it("handles canonicalization of tsconfig path", () => {
121+
const aTs: File = { path: "/Foo/a.ts", content: "const x = 0;" };
122+
const tsconfig: File = { path: "/Foo/tsconfig.json", content: '{ "files": ["./a.ts"] }' };
123+
const session = createSession(createServerHost([aTs, tsconfig]));
124+
openFilesForSession([aTs], session);
125+
126+
const result = executeSessionRequest<protocol.GetEditsForRefactorRequest, protocol.GetEditsForRefactorResponse>(session, protocol.CommandTypes.GetEditsForRefactor, {
127+
file: aTs.path,
128+
startLine: 1,
129+
startOffset: 1,
130+
endLine: 2,
131+
endOffset: aTs.content.length,
132+
refactor: "Move to a new file",
133+
action: "Move to a new file",
134+
});
135+
assert.deepEqual<protocol.RefactorEditInfo | undefined>(result, {
136+
edits: [
137+
{
138+
fileName: aTs.path,
139+
textChanges: [{ start: { line: 1, offset: 1 }, end: { line: 1, offset: aTs.content.length + 1 }, newText: "" }],
140+
},
141+
{
142+
fileName: tsconfig.path,
143+
textChanges: [{ start: { line: 1, offset: 21 }, end: { line: 1, offset: 21 }, newText: ', "./x.ts"' }],
144+
},
145+
{
146+
fileName: "/Foo/x.ts",
147+
textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: "const x = 0;\n" }],
148+
},
149+
],
150+
renameFilename: undefined,
151+
renameLocation: undefined,
152+
});
153+
});
119154
});
120155
}

0 commit comments

Comments
 (0)