Skip to content

Commit 77494d6

Browse files
author
Andy Hanson
committed
getScriptInfoOrConfig: Canonicalize tsconfig path before lookup
1 parent 01f6093 commit 77494d6

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ namespace ts.server {
18041804
const path = toNormalizedPath(uncheckedFileName);
18051805
const info = this.getScriptInfoForNormalizedPath(path);
18061806
if (info) return info;
1807-
const configProject = this.configuredProjects.get(uncheckedFileName);
1807+
const configProject = this.configuredProjects.get(this.toCanonicalFileName(uncheckedFileName));
18081808
return configProject && configProject.getCompilerOptions().configFile;
18091809
}
18101810

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9717,6 +9717,43 @@ export function Test2() {
97179717
});
97189718
});
97199719

9720+
describe("tsserverProjectSystem refactors", () => {
9721+
it("handles canonicalization of tsconfig path", () => {
9722+
const aTs: File = { path: "/Foo/a.ts", content: "const x = 0;" };
9723+
const tsconfig: File = { path: "/Foo/tsconfig.json", content: '{ "files": ["./a.ts"] }' };
9724+
const session = createSession(createServerHost([aTs, tsconfig]));
9725+
openFilesForSession([aTs], session);
9726+
9727+
const result = executeSessionRequest<protocol.GetEditsForRefactorRequest, protocol.GetEditsForRefactorResponse>(session, protocol.CommandTypes.GetEditsForRefactor, {
9728+
file: aTs.path,
9729+
startLine: 1,
9730+
startOffset: 1,
9731+
endLine: 2,
9732+
endOffset: aTs.content.length,
9733+
refactor: "Move to a new file",
9734+
action: "Move to a new file",
9735+
});
9736+
assert.deepEqual<protocol.RefactorEditInfo | undefined>(result, {
9737+
edits: [
9738+
{
9739+
fileName: aTs.path,
9740+
textChanges: [{ start: { line: 1, offset: 1 }, end: { line: 1, offset: aTs.content.length + 1 }, newText: "" }],
9741+
},
9742+
{
9743+
fileName: tsconfig.path,
9744+
textChanges: [{ start: { line: 1, offset: 21 }, end: { line: 1, offset: 21 }, newText: ', "./x.ts"' }],
9745+
},
9746+
{
9747+
fileName: "/Foo/x.ts",
9748+
textChanges: [{ start: { line: 0, offset: 0 }, end: { line: 0, offset: 0 }, newText: "const x = 0;" }],
9749+
},
9750+
],
9751+
renameFilename: undefined,
9752+
renameLocation: undefined,
9753+
});
9754+
});
9755+
});
9756+
97209757
function makeReferenceItem(file: File, isDefinition: boolean, text: string, lineText: string, options?: SpanFromSubstringOptions): protocol.ReferencesResponseItem {
97219758
return {
97229759
...protocolFileSpanFromSubstring(file, text, options),

0 commit comments

Comments
 (0)