Skip to content

Commit 2bb3cdd

Browse files
authored
add file statistics logging (#203)
1 parent 0fdf2a9 commit 2bb3cdd

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

packages/language-server/src/plugins/typescript/SnapshotManager.ts

+29-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { DocumentSnapshot, SvelteSnapshotOptions } from './DocumentSnapshot';
2+
import { Logger } from '../../logger';
23

34
export class SnapshotManager {
4-
constructor(
5-
private projectFiles: string[]
6-
) { }
7-
85
private documents: Map<string, DocumentSnapshot> = new Map();
6+
private lastLogged = new Date(new Date().getTime() - 60_001);
7+
8+
constructor(private projectFiles: string[]) {}
99

1010
updateByFileName(fileName: string, options: SvelteSnapshotOptions) {
1111
if (!this.has(fileName)) {
@@ -36,6 +36,8 @@ export class SnapshotManager {
3636
prev.destroyFragment();
3737
}
3838

39+
this.logStatistics();
40+
3941
return this.documents.set(fileName, snapshot);
4042
}
4143

@@ -44,8 +46,7 @@ export class SnapshotManager {
4446
}
4547

4648
delete(fileName: string) {
47-
this.projectFiles = this.projectFiles
48-
.filter(s => s !== fileName);
49+
this.projectFiles = this.projectFiles.filter((s) => s !== fileName);
4950
return this.documents.delete(fileName);
5051
}
5152

@@ -56,4 +57,26 @@ export class SnapshotManager {
5657
getProjectFileNames() {
5758
return [...this.projectFiles];
5859
}
60+
61+
private logStatistics() {
62+
const date = new Date();
63+
// Don't use setInterval because that will keep tests running forever
64+
if (date.getTime() - this.lastLogged.getTime() > 60_000) {
65+
this.lastLogged = date;
66+
67+
const projectFiles = this.getProjectFileNames();
68+
const allFiles = Array.from(new Set([...projectFiles, ...this.getFileNames()]));
69+
Logger.log(
70+
`SnapshotManager File Statistics:\n` +
71+
`Project files: ${projectFiles.length}\n` +
72+
`Svelte files: ${
73+
allFiles.filter((name) => name.endsWith('.svelte')).length
74+
}\n` +
75+
`From node_modules: ${
76+
allFiles.filter((name) => name.includes('node_modules')).length
77+
}\n` +
78+
`Total: ${allFiles.length}`,
79+
);
80+
}
81+
}
5982
}

0 commit comments

Comments
 (0)