Check large file size only for non ts files
This commit is contained in:
parent
ad63468ed5
commit
7e117f2707
2 changed files with 68 additions and 53 deletions
|
@ -166,6 +166,8 @@ namespace ts.server {
|
|||
let text: string;
|
||||
const fileName = tempFileName || this.fileName;
|
||||
const getText = () => text === undefined ? (text = this.host.readFile(fileName) || "") : text;
|
||||
// Only non typescript files have size limitation
|
||||
if (!hasTypeScriptFileExtension(this.fileName)) {
|
||||
const fileSize = this.host.getFileSize ? this.host.getFileSize(fileName) : getText().length;
|
||||
if (fileSize > maxFileSize) {
|
||||
Debug.assert(!!this.info.containingProjects.length);
|
||||
|
@ -174,6 +176,7 @@ namespace ts.server {
|
|||
this.info.containingProjects[0].projectService.sendLargeFileReferencedEvent(fileName, fileSize);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return getText();
|
||||
}
|
||||
|
||||
|
|
|
@ -9022,13 +9022,19 @@ export const x = 10;`
|
|||
|
||||
describe("tsserverProjectSystem with large file", () => {
|
||||
const projectRoot = "/user/username/projects/project";
|
||||
|
||||
function getLargeFile(useLargeTsFile: boolean) {
|
||||
return `src/large.${useLargeTsFile ? "ts" : "js"}`;
|
||||
}
|
||||
|
||||
function createSessionWithEventHandler(files: File[], useLargeTsFile: boolean) {
|
||||
const largeFile: File = {
|
||||
path: `${projectRoot}/src/large.ts`,
|
||||
path: `${projectRoot}/${getLargeFile(useLargeTsFile)}`,
|
||||
content: "export var x = 10;",
|
||||
fileSize: server.maxFileSize + 1
|
||||
};
|
||||
|
||||
function createSessionWithEventHandler(host: TestServerHost) {
|
||||
files.push(largeFile);
|
||||
const host = createServerHost(files);
|
||||
const largeFileReferencedEvents: server.LargeFileReferencedEvent[] = [];
|
||||
const session = createSession(host, {
|
||||
eventHandler: e => {
|
||||
|
@ -9038,17 +9044,24 @@ export const x = 10;`
|
|||
}
|
||||
});
|
||||
|
||||
return { session, verifyLargeFileReferencedEvent };
|
||||
return { session, verifyLargeFile };
|
||||
|
||||
function verifyLargeFileReferencedEvent() {
|
||||
assert.equal(largeFileReferencedEvents.length, 1);
|
||||
assert.deepEqual(largeFileReferencedEvents, [{
|
||||
function verifyLargeFile(project: server.Project) {
|
||||
checkProjectActualFiles(project, files.map(f => f.path));
|
||||
|
||||
// large file for non ts file should be empty and for ts file should have content
|
||||
const service = session.getProjectService();
|
||||
const info = service.getScriptInfo(largeFile.path)!;
|
||||
assert.equal(info.cacheSourceFile.sourceFile.text, useLargeTsFile ? largeFile.content : "");
|
||||
|
||||
assert.deepEqual(largeFileReferencedEvents, useLargeTsFile ? emptyArray : [{
|
||||
eventName: server.LargeFileReferencedEvent,
|
||||
data: { file: largeFile.path, fileSize: largeFile.fileSize, maxFileSize: server.maxFileSize }
|
||||
}]);
|
||||
}
|
||||
}
|
||||
|
||||
function verifyLargeFile(useLargeTsFile: boolean) {
|
||||
it("when large file is included by tsconfig", () => {
|
||||
const file: File = {
|
||||
path: `${projectRoot}/src/file.ts`,
|
||||
|
@ -9056,19 +9069,14 @@ export const x = 10;`
|
|||
};
|
||||
const tsconfig: File = {
|
||||
path: `${projectRoot}/tsconfig.json`,
|
||||
content: JSON.stringify({ files: ["src/file.ts", "src/large.ts"] })
|
||||
content: JSON.stringify({ files: ["src/file.ts", getLargeFile(useLargeTsFile)], compilerOptions: { target: 1, allowJs: true } })
|
||||
};
|
||||
const files = [file, largeFile, libFile, tsconfig];
|
||||
const host = createServerHost(files);
|
||||
const { session, verifyLargeFileReferencedEvent } = createSessionWithEventHandler(host);
|
||||
const files = [file, libFile, tsconfig];
|
||||
const { session, verifyLargeFile } = createSessionWithEventHandler(files, useLargeTsFile);
|
||||
const service = session.getProjectService();
|
||||
openFilesForSession([file], session);
|
||||
checkNumberOfProjects(service, { configuredProjects: 1 });
|
||||
const project = service.configuredProjects.get(tsconfig.path)!;
|
||||
checkProjectActualFiles(project, [file.path, libFile.path, largeFile.path, tsconfig.path]);
|
||||
const info = service.getScriptInfo(largeFile.path)!;
|
||||
assert.equal(info.cacheSourceFile.sourceFile.text, "");
|
||||
verifyLargeFileReferencedEvent();
|
||||
verifyLargeFile(service.configuredProjects.get(tsconfig.path)!);
|
||||
});
|
||||
|
||||
it("when large file is included by module resolution", () => {
|
||||
|
@ -9076,17 +9084,21 @@ export const x = 10;`
|
|||
path: `${projectRoot}/src/file.ts`,
|
||||
content: `export var y = 10;import {x} from "./large"`
|
||||
};
|
||||
const files = [file, largeFile, libFile];
|
||||
const host = createServerHost(files);
|
||||
const { session, verifyLargeFileReferencedEvent } = createSessionWithEventHandler(host);
|
||||
const files = [file, libFile];
|
||||
const { session, verifyLargeFile } = createSessionWithEventHandler(files, useLargeTsFile);
|
||||
const service = session.getProjectService();
|
||||
openFilesForSession([file], session);
|
||||
checkNumberOfProjects(service, { inferredProjects: 1 });
|
||||
const project = service.inferredProjects[0];
|
||||
checkProjectActualFiles(project, [file.path, libFile.path, largeFile.path]);
|
||||
const info = service.getScriptInfo(largeFile.path)!;
|
||||
assert.equal(info.cacheSourceFile.sourceFile.text, "");
|
||||
verifyLargeFileReferencedEvent();
|
||||
verifyLargeFile(service.inferredProjects[0]);
|
||||
});
|
||||
}
|
||||
|
||||
describe("large file is ts file", () => {
|
||||
verifyLargeFile(/*useLargeTsFile*/ true);
|
||||
});
|
||||
|
||||
describe("large file is js file", () => {
|
||||
verifyLargeFile(/*useLargeTsFile*/ false);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue