Skip to content

Commit

Permalink
getScriptInfoOrConfig: Canonicalize tsconfig path before lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Hanson committed Aug 7, 2018
1 parent 1a05f13 commit af2dfe9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ namespace ts.server {
pendingEnsureProjectForOpenFiles: boolean;

readonly currentDirectory: NormalizedPath;
readonly toCanonicalFileName: (f: string) => string;
readonly toCanonicalFileName: GetCanonicalFileName;

public readonly host: ServerHost;
public readonly logger: Logger;
Expand Down Expand Up @@ -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;
}

Expand Down
37 changes: 37 additions & 0 deletions src/testRunner/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<protocol.GetEditsForRefactorRequest, protocol.GetEditsForRefactorResponse>(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<protocol.RefactorEditInfo | undefined>(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),
Expand Down

0 comments on commit af2dfe9

Please sign in to comment.