Merge pull request #28559 from amcasey/FileSize

Expose aggregate file sizes in FileStats
This commit is contained in:
Andrew Casey authored and GitHub committed 2018-11-16 13:52:12 -08:00
commit 642803c182
7 files changed
+190 -21

No files matched your search

+23 -2
View File
@@ -211,15 +211,36 @@ namespace ts.projectSystem {
}, "/jsconfig.json");
});
it("sends telemetry for file sizes", () => {
const jsFile = makeFile("/a.js", "1");
const tsFile = makeFile("/b.ts", "12");
const tsconfig = makeFile("/jsconfig.json", {
compilerOptions: autoJsCompilerOptions
});
const et = new TestServerEventManager([tsconfig, jsFile, tsFile]);
et.service.openClientFile(jsFile.path);
et.assertProjectInfoTelemetryEvent({
fileStats: fileStats({ js: 1, jsSize: 1, ts: 1, tsSize: 2 }),
compilerOptions: autoJsCompilerOptions,
typeAcquisition: {
enable: true,
include: false,
exclude: false,
},
configFileName: "jsconfig.json",
}, "/jsconfig.json");
});
it("detects whether language service was disabled", () => {
const file = makeFile("/a.js");
const tsconfig = makeFile("/jsconfig.json", {});
const et = new TestServerEventManager([tsconfig, file]);
et.host.getFileSize = () => server.maxProgramSizeForNonTsFiles + 1;
const fileSize = server.maxProgramSizeForNonTsFiles + 1;
et.host.getFileSize = () => fileSize;
et.service.openClientFile(file.path);
et.getEvent<server.ProjectLanguageServiceStateEvent>(server.ProjectLanguageServiceStateEvent);
et.assertProjectInfoTelemetryEvent({
fileStats: fileStats({ js: 1 }),
fileStats: fileStats({ js: 1, jsSize: fileSize }),
compilerOptions: autoJsCompilerOptions,
configFileName: "jsconfig.json",
typeAcquisition: {
+84 -7
View File
@@ -29,20 +29,20 @@ namespace ts.textStorage {
for (let offset = 0; offset < end - start; offset++) {
const pos1 = ts1.lineOffsetToPosition(line + 1, offset + 1);
const pos2 = ts2.lineOffsetToPosition(line + 1, offset + 1);
assert.isTrue(pos1 === pos2, `lineOffsetToPosition ${line + 1}-${offset + 1}: expected ${pos1} to equal ${pos2}`);
assert.strictEqual(pos1, pos2, `lineOffsetToPosition ${line + 1}-${offset + 1}: expected ${pos1} to equal ${pos2}`);
}
const {start: start1, length: length1 } = ts1.lineToTextSpan(line);
const {start: start2, length: length2 } = ts2.lineToTextSpan(line);
assert.isTrue(start1 === start2, `lineToTextSpan ${line}::start:: expected ${start1} to equal ${start2}`);
assert.isTrue(length1 === length2, `lineToTextSpan ${line}::length:: expected ${length1} to equal ${length2}`);
assert.strictEqual(start1, start2, `lineToTextSpan ${line}::start:: expected ${start1} to equal ${start2}`);
assert.strictEqual(length1, length2, `lineToTextSpan ${line}::length:: expected ${length1} to equal ${length2}`);
}
for (let pos = 0; pos < f.content.length; pos++) {
const { line: line1, offset: offset1 } = ts1.positionToLineOffset(pos);
const { line: line2, offset: offset2 } = ts2.positionToLineOffset(pos);
assert.isTrue(line1 === line2, `positionToLineOffset ${pos}::line:: expected ${line1} to equal ${line2}`);
assert.isTrue(offset1 === offset2, `positionToLineOffset ${pos}::offset:: expected ${offset1} to equal ${offset2}`);
assert.strictEqual(line1, line2, `positionToLineOffset ${pos}::line:: expected ${line1} to equal ${line2}`);
assert.strictEqual(offset1, offset2, `positionToLineOffset ${pos}::offset:: expected ${offset1} to equal ${offset2}`);
}
});
@@ -52,16 +52,93 @@ namespace ts.textStorage {
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path), /*initialVersion*/ undefined, /*info*/undefined!);
ts1.getSnapshot();
assert.isTrue(!ts1.hasScriptVersionCache_TestOnly(), "should not have script version cache - 1");
assert.isFalse(ts1.hasScriptVersionCache_TestOnly(), "should not have script version cache - 1");
ts1.edit(0, 5, " ");
assert.isTrue(ts1.hasScriptVersionCache_TestOnly(), "have script version cache - 1");
ts1.useText();
assert.isTrue(!ts1.hasScriptVersionCache_TestOnly(), "should not have script version cache - 2");
assert.isFalse(ts1.hasScriptVersionCache_TestOnly(), "should not have script version cache - 2");
ts1.getLineInfo(0);
assert.isTrue(ts1.hasScriptVersionCache_TestOnly(), "have script version cache - 2");
});
it("should be able to return the file size immediately after construction", () => {
const host = projectSystem.createServerHost([f]);
// Since script info is not used in these tests, just cheat by passing undefined
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path), /*initialVersion*/ undefined, /*info*/undefined!);
assert.strictEqual(f.content.length, ts1.getTelemetryFileSize());
});
it("should be able to return the file size when backed by text", () => {
const host = projectSystem.createServerHost([f]);
// Since script info is not used in these tests, just cheat by passing undefined
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path), /*initialVersion*/ undefined, /*info*/undefined!);
ts1.useText(f.content);
assert.isFalse(ts1.hasScriptVersionCache_TestOnly());
assert.strictEqual(f.content.length, ts1.getTelemetryFileSize());
});
it("should be able to return the file size when backed by a script version cache", () => {
const host = projectSystem.createServerHost([f]);
// Since script info is not used in these tests, just cheat by passing undefined
const ts1 = new server.TextStorage(host, server.asNormalizedPath(f.path), /*initialVersion*/ undefined, /*info*/undefined!);
ts1.useScriptVersionCache_TestOnly();
assert.isTrue(ts1.hasScriptVersionCache_TestOnly());
assert.strictEqual(f.content.length, ts1.getTelemetryFileSize());
});
it("should be able to return the file size when a JS file is too large to load into text", () => {
const largeFile = {
path: "/a/large.js",
content: " ".repeat(server.maxFileSize + 1)
};
const host = projectSystem.createServerHost([largeFile]);
// The large-file handling requires a ScriptInfo with a containing project
const projectService = projectSystem.createProjectService(host);
projectService.openClientFile(largeFile.path);
const scriptInfo = projectService.getScriptInfo(largeFile.path);
const ts1 = new server.TextStorage(host, server.asNormalizedPath(largeFile.path), /*initialVersion*/ undefined, scriptInfo!);
assert.isTrue(ts1.reloadFromDisk());
assert.isFalse(ts1.hasScriptVersionCache_TestOnly());
assert.strictEqual(largeFile.content.length, ts1.getTelemetryFileSize());
});
it("should return the file size without reloading the file", () => {
const oldText = "hello";
const newText = "goodbye";
const changingFile = {
path: "/a/changing.ts",
content: oldText
};
const host = projectSystem.createServerHost([changingFile]);
// Since script info is not used in these tests, just cheat by passing undefined
const ts1 = new server.TextStorage(host, server.asNormalizedPath(changingFile.path), /*initialVersion*/ undefined, /*info*/undefined!);
assert.isTrue(ts1.reloadFromDisk());
// Refresh the file and notify TextStorage
host.writeFile(changingFile.path, newText);
ts1.delayReloadFromFileIntoText();
assert.strictEqual(oldText.length, ts1.getTelemetryFileSize());
assert.isTrue(ts1.reloadWithFileText());
assert.strictEqual(newText.length, ts1.getTelemetryFileSize());
});
});
}
@@ -183,7 +183,7 @@ namespace ts.projectSystem {
}
export function fileStats(nonZeroStats: Partial<server.FileStats>): server.FileStats {
return { ts: 0, tsx: 0, dts: 0, js: 0, jsx: 0, deferred: 0, ...nonZeroStats };
return { ts: 0, tsSize: 0, tsx: 0, tsxSize: 0, dts: 0, dtsSize: 0, js: 0, jsSize: 0, jsx: 0, jsxSize: 0, deferred: 0, deferredSize: 0, ...nonZeroStats };
}
export interface ConfigFileDiagnostic {