Handle already released source files that dont match scriptKind (#54401)

This commit is contained in:
Sheetal Nandi
2023-05-25 15:58:22 -07:00
committed by GitHub
parent da686774dc
commit c64a378ef9
3 changed files with 249 additions and 1 deletions

View File

@@ -1,8 +1,11 @@
import * as ts from "../../_namespaces/ts";
import {
baselineTsserverLogs,
closeFilesForSession,
createLoggerWithInMemoryLogs,
createProjectService,
createSession,
openFilesForSession,
TestProjectService,
} from "../helpers/tsserver";
import {
@@ -103,3 +106,39 @@ describe("unittests:: tsserver:: documentRegistry:: document registry in project
baselineTsserverLogs("documentRegistry", "Caches the source file if script info is orphan, and orphan script info changes", service);
});
});
describe("unittests:: tsserver:: documentRegistry:: works when reusing orphan script info with different scriptKind", () => {
it("works when reusing orphan script info with different scriptKind", () => {
const host = createServerHost({});
const session = createSession(host, { useInferredProjectPerProjectRoot: true, logger: createLoggerWithInMemoryLogs(host) });
const newText = "exrpot const x = 10;";
const content = `import x from 'react';\n${newText}`;
openFilesForSession([
{ file: "^/inmemory/model/6", content, scriptKindName: "TSX", projectRootPath: "/users/user/projects/san" },
{ file: "^/inmemory/model/4", content, scriptKindName: "TSX", projectRootPath: "/users/user/projects/san" },
], session);
closeFilesForSession(["^/inmemory/model/4"], session);
session.executeCommandSeq<ts.server.protocol.UpdateOpenRequest>({
command: ts.server.protocol.CommandTypes.UpdateOpen,
arguments: {
changedFiles: [{
fileName: "^/inmemory/model/6",
textChanges: [{
newText,
start: { line: 1, offset: 1 },
end: { line: 2, offset: newText.length + 1 } // Remove the import so that structure is not reused
}]
}],
openFiles: [
{
file: "^/inmemory/model/4",
fileContent: newText,
projectRootPath: "/users/user/projects/san", // Add same document with different script kind
scriptKindName: "TS"
},
]
}
});
baselineTsserverLogs("documentRegistry", "works when reusing orphan script info with different scriptKind", session);
});
});