Skip to content

Commit 53ad019

Browse files
unionalmhegazy
authored andcommitted
Log top 5 largest files when TS language service is disabling. (microsoft#19315)
* Log top 5 largest files * Show same message on second pass. This second pass seemingly should be avoid. Bug there. * Get all files and sort when error. * Refactor * Push logic to error branch * Update to use array chain. * Update to return string * going functional.
1 parent 7985e66 commit 53ad019

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/server/editorServices.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,24 +1373,42 @@ namespace ts.server {
13731373
this.projectToSizeMap.forEach(val => (availableSpace -= (val || 0)));
13741374

13751375
let totalNonTsFileSize = 0;
1376+
13761377
for (const f of fileNames) {
13771378
const fileName = propertyReader.getFileName(f);
13781379
if (hasTypeScriptFileExtension(fileName)) {
13791380
continue;
13801381
}
1382+
13811383
totalNonTsFileSize += this.host.getFileSize(fileName);
1384+
13821385
if (totalNonTsFileSize > maxProgramSizeForNonTsFiles) {
1386+
this.logger.info(getExceedLimitMessage({ propertyReader, hasTypeScriptFileExtension, host: this.host }, totalNonTsFileSize));
13831387
// Keep the size as zero since it's disabled
13841388
return true;
13851389
}
13861390
}
13871391

13881392
if (totalNonTsFileSize > availableSpace) {
1393+
this.logger.info(getExceedLimitMessage({ propertyReader, hasTypeScriptFileExtension, host: this.host }, totalNonTsFileSize));
13891394
return true;
13901395
}
13911396

13921397
this.projectToSizeMap.set(name, totalNonTsFileSize);
13931398
return false;
1399+
1400+
function getExceedLimitMessage(context: { propertyReader: FilePropertyReader<any>, hasTypeScriptFileExtension: (filename: string) => boolean, host: ServerHost }, totalNonTsFileSize: number) {
1401+
const files = getTop5LargestFiles(context);
1402+
1403+
return `Non TS file size exceeded limit (${totalNonTsFileSize}). Largest files: ${files.map(file => `${file.name}:${file.size}`).join(", ")}`;
1404+
}
1405+
function getTop5LargestFiles({ propertyReader, hasTypeScriptFileExtension, host }: { propertyReader: FilePropertyReader<any>, hasTypeScriptFileExtension: (filename: string) => boolean, host: ServerHost }) {
1406+
return fileNames.map(f => propertyReader.getFileName(f))
1407+
.filter(name => hasTypeScriptFileExtension(name))
1408+
.map(name => ({ name, size: host.getFileSize(name) }))
1409+
.sort((a, b) => b.size - a.size)
1410+
.slice(0, 5);
1411+
}
13941412
}
13951413

13961414
private createExternalProject(projectFileName: string, files: protocol.ExternalFile[], options: protocol.ExternalProjectCompilerOptions, typeAcquisition: TypeAcquisition) {

0 commit comments

Comments
 (0)