@spyglassmc/core 0.4.25 → 0.4.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -35,14 +35,12 @@ export declare class CacheService {
|
|
|
35
35
|
private readonly project;
|
|
36
36
|
checksums: Checksums;
|
|
37
37
|
errors: ErrorCache;
|
|
38
|
-
dirtyFiles: Set<string>;
|
|
39
38
|
/**
|
|
40
39
|
* @param cacheRoot File path to the directory where cache files by Spyglass should be stored.
|
|
41
40
|
* @param project
|
|
42
41
|
*/
|
|
43
42
|
constructor(cacheRoot: RootUriString, project: Project);
|
|
44
43
|
private getCacheFileUri;
|
|
45
|
-
private flushDirtyFiles;
|
|
46
44
|
load(): Promise<LoadResult>;
|
|
47
45
|
validate(): Promise<ValidateResult>;
|
|
48
46
|
/**
|
|
@@ -18,7 +18,6 @@ export class CacheService {
|
|
|
18
18
|
project;
|
|
19
19
|
checksums = Checksums.create();
|
|
20
20
|
errors = {};
|
|
21
|
-
dirtyFiles = new Set();
|
|
22
21
|
#hasValidatedFiles = false;
|
|
23
22
|
/**
|
|
24
23
|
* @param cacheRoot File path to the directory where cache files by Spyglass should be stored.
|
|
@@ -31,9 +30,14 @@ export class CacheService {
|
|
|
31
30
|
if (!this.#hasValidatedFiles) {
|
|
32
31
|
return;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
await this.
|
|
33
|
+
try {
|
|
34
|
+
// TODO: Don't update this for every single change.
|
|
35
|
+
this.checksums.files[doc.uri] = await this.project.externals.crypto.getSha1(doc.getText());
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
if (!this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
39
|
+
this.project.logger.error(`[CacheService#hash-file] ${doc.uri}`);
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
});
|
|
39
43
|
this.project.on('rootsUpdated', async ({ roots }) => {
|
|
@@ -46,7 +50,7 @@ export class CacheService {
|
|
|
46
50
|
}
|
|
47
51
|
catch (e) {
|
|
48
52
|
if (!this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
49
|
-
this.project.logger.error(`[CacheService#hash-root] ${root}
|
|
53
|
+
this.project.logger.error(`[CacheService#hash-root] ${root}`);
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
}
|
|
@@ -69,19 +73,6 @@ export class CacheService {
|
|
|
69
73
|
}
|
|
70
74
|
return this.#cacheFilePath;
|
|
71
75
|
}
|
|
72
|
-
async flushDirtyFiles() {
|
|
73
|
-
for (const uri of this.dirtyFiles) {
|
|
74
|
-
try {
|
|
75
|
-
this.checksums.files[uri] = await this.project.fs.hash(uri);
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
if (!this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
79
|
-
this.project.logger.error(`[CacheService#flushDirtyFiles] ${uri}`, e);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
this.dirtyFiles.clear();
|
|
84
|
-
}
|
|
85
76
|
async load() {
|
|
86
77
|
const ans = { symbols: {} };
|
|
87
78
|
if (this.project.projectRoots.length === 0) {
|
|
@@ -129,7 +120,7 @@ export class CacheService {
|
|
|
129
120
|
}
|
|
130
121
|
catch (e) {
|
|
131
122
|
if (!this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
132
|
-
this.project.logger.error(`[CacheService#hash-file] ${uri}
|
|
123
|
+
this.project.logger.error(`[CacheService#hash-file] ${uri}`);
|
|
133
124
|
}
|
|
134
125
|
// Failed calculating hash. Assume the root has changed.
|
|
135
126
|
}
|
|
@@ -183,8 +174,6 @@ export class CacheService {
|
|
|
183
174
|
let filePath;
|
|
184
175
|
try {
|
|
185
176
|
filePath = await this.getCacheFileUri();
|
|
186
|
-
await this.flushDirtyFiles();
|
|
187
|
-
__profiler.task('Hash Files');
|
|
188
177
|
const cache = {
|
|
189
178
|
version: LatestCacheVersion,
|
|
190
179
|
projectRoots: this.project.projectRoots,
|
package/lib/service/Project.js
CHANGED
|
@@ -22,7 +22,7 @@ import { ArchiveUriSupporter, FileService, FileUriSupporter } from './FileServic
|
|
|
22
22
|
import { fileUtil } from './fileUtil.js';
|
|
23
23
|
import { MetaRegistry } from './MetaRegistry.js';
|
|
24
24
|
import { ProfilerFactory } from './Profiler.js';
|
|
25
|
-
const CacheAutoSaveInterval =
|
|
25
|
+
const CacheAutoSaveInterval = 600_000; // 10 Minutes.
|
|
26
26
|
/* istanbul ignore next */
|
|
27
27
|
/**
|
|
28
28
|
* Manage all tracked documents and errors.
|
|
@@ -65,7 +65,7 @@ export class Project {
|
|
|
65
65
|
static RootSuffix = '/pack.mcmeta';
|
|
66
66
|
/** Prevent circular binding. */
|
|
67
67
|
#bindingInProgressUris = new Set();
|
|
68
|
-
#cacheSaverIntervalId
|
|
68
|
+
#cacheSaverIntervalId;
|
|
69
69
|
cacheService;
|
|
70
70
|
/** URI of files that are currently managed by the language client. */
|
|
71
71
|
#clientManagedUris = new Set();
|
|
@@ -182,6 +182,7 @@ export class Project {
|
|
|
182
182
|
}).on('error', ({ error, uri }) => this.logger.error(`[Project] [Config] Failed loading ${uri}`, error));
|
|
183
183
|
this.setInitPromise();
|
|
184
184
|
this.setReadyPromise();
|
|
185
|
+
this.#cacheSaverIntervalId = setInterval(() => this.cacheService.save(), CacheAutoSaveInterval);
|
|
185
186
|
this.on('documentUpdated', ({ doc, node }) => {
|
|
186
187
|
// if (!this.#isReady) {
|
|
187
188
|
// return
|
|
@@ -386,9 +387,6 @@ export class Project {
|
|
|
386
387
|
__profiler.task('Bind Files');
|
|
387
388
|
__profiler.finalize();
|
|
388
389
|
this.emit('ready', {});
|
|
389
|
-
// Save the cache after ready and start the auto-cache interval
|
|
390
|
-
await this.cacheService.save();
|
|
391
|
-
this.#cacheSaverIntervalId = setInterval(() => this.cacheService.save(), CacheAutoSaveInterval);
|
|
392
390
|
};
|
|
393
391
|
this.#isReady = false;
|
|
394
392
|
this.#readyPromise = ready();
|