@spyglassmc/core 0.4.19 → 0.4.20
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.
|
@@ -130,8 +130,8 @@ export class CacheService {
|
|
|
130
130
|
ans.unchangedFiles.push(uri);
|
|
131
131
|
continue;
|
|
132
132
|
}
|
|
133
|
-
if (this.project.
|
|
134
|
-
ans.
|
|
133
|
+
if (this.project.shouldExclude(uri)) {
|
|
134
|
+
ans.removedFiles.push(uri);
|
|
135
135
|
continue;
|
|
136
136
|
}
|
|
137
137
|
try {
|
package/lib/service/Config.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export interface EnvConfig {
|
|
|
59
59
|
*/
|
|
60
60
|
dependencies: string[];
|
|
61
61
|
/**
|
|
62
|
-
* A list of file patterns to exclude.
|
|
62
|
+
* A list of file patterns to exclude.
|
|
63
63
|
*/
|
|
64
64
|
exclude: string[];
|
|
65
65
|
/**
|
package/lib/service/Config.js
CHANGED
|
@@ -107,7 +107,7 @@ export const VanillaConfig = {
|
|
|
107
107
|
env: {
|
|
108
108
|
dataSource: 'GitHub',
|
|
109
109
|
dependencies: ['@vanilla-datapack', '@vanilla-resourcepack', '@vanilla-mcdoc'],
|
|
110
|
-
exclude: ['
|
|
110
|
+
exclude: ['.*/**'],
|
|
111
111
|
customResources: {},
|
|
112
112
|
feature: {
|
|
113
113
|
codeActions: true,
|
package/lib/service/Project.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Ignore } from 'ignore';
|
|
2
1
|
import type { TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument';
|
|
3
2
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
3
|
import type { ExternalEventEmitter, Externals } from '../common/index.js';
|
|
@@ -98,11 +97,9 @@ export type ProjectData = Pick<Project, 'cacheRoot' | 'config' | 'downloader' |
|
|
|
98
97
|
export declare class Project implements ExternalEventEmitter {
|
|
99
98
|
#private;
|
|
100
99
|
private static readonly RootSuffix;
|
|
101
|
-
private static readonly GitIgnore;
|
|
102
100
|
readonly cacheService: CacheService;
|
|
103
101
|
get isReady(): boolean;
|
|
104
102
|
config: Config;
|
|
105
|
-
ignore: Ignore;
|
|
106
103
|
readonly downloader: Downloader;
|
|
107
104
|
readonly externals: Externals;
|
|
108
105
|
readonly fs: FileService;
|
|
@@ -161,7 +158,6 @@ export declare class Project implements ExternalEventEmitter {
|
|
|
161
158
|
getTrackedFiles(): string[];
|
|
162
159
|
constructor({ cacheRoot, defaultConfig, downloader, externals, fs, initializers, isDebugging, logger, profilers, projectRoots, }: ProjectOptions);
|
|
163
160
|
private setInitPromise;
|
|
164
|
-
private readGitignore;
|
|
165
161
|
private setReadyPromise;
|
|
166
162
|
/**
|
|
167
163
|
* Load the config file and initialize parsers and processors.
|
|
@@ -203,6 +199,7 @@ export declare class Project implements ExternalEventEmitter {
|
|
|
203
199
|
ensureClientManagedChecked(uri: string): Promise<DocAndNode | undefined>;
|
|
204
200
|
getClientManaged(uri: string): DocAndNode | undefined;
|
|
205
201
|
showCacheRoot(): Promise<void>;
|
|
202
|
+
shouldExclude(uri: string): boolean;
|
|
206
203
|
private tryClearingCache;
|
|
207
204
|
private shouldRemove;
|
|
208
205
|
private isOnlyWatched;
|
package/lib/service/Project.js
CHANGED
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import
|
|
7
|
+
import * as micromatch from 'micromatch';
|
|
8
8
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
9
9
|
import { bufferToString, Logger, normalizeUri, SingletonPromise, StateProxy, } from '../common/index.js';
|
|
10
10
|
import { FileNode } from '../node/index.js';
|
|
@@ -63,7 +63,6 @@ const CacheAutoSaveInterval = 600_000; // 10 Minutes.
|
|
|
63
63
|
*/
|
|
64
64
|
export class Project {
|
|
65
65
|
static RootSuffix = '/pack.mcmeta';
|
|
66
|
-
static GitIgnore = '.gitignore';
|
|
67
66
|
/** Prevent circular binding. */
|
|
68
67
|
#bindingInProgressUris = new Set();
|
|
69
68
|
#cacheSaverIntervalId;
|
|
@@ -85,7 +84,6 @@ export class Project {
|
|
|
85
84
|
return this.#isReady;
|
|
86
85
|
}
|
|
87
86
|
config;
|
|
88
|
-
ignore = ignore();
|
|
89
87
|
downloader;
|
|
90
88
|
externals;
|
|
91
89
|
fs;
|
|
@@ -159,9 +157,7 @@ export class Project {
|
|
|
159
157
|
const supportedFiles = [...this.#dependencyFiles ?? [], ...this.#watchedFiles]
|
|
160
158
|
.filter((file) => extensions.includes(fileUtil.extname(file) ?? ''));
|
|
161
159
|
this.logger.info(`[Project#getTrackedFiles] Listed ${supportedFiles.length} supported files`);
|
|
162
|
-
|
|
163
|
-
this.logger.info(`[Project#getTrackedFiles] After ignoring, keeping ${filteredFiles.length} tracked files`);
|
|
164
|
-
return filteredFiles;
|
|
160
|
+
return supportedFiles;
|
|
165
161
|
}
|
|
166
162
|
constructor({ cacheRoot, defaultConfig, downloader, externals, fs = FileService.create(externals, cacheRoot), initializers = [], isDebugging = false, logger = Logger.create(), profilers = ProfilerFactory.noop(), projectRoots, }) {
|
|
167
163
|
this.#cacheRoot = cacheRoot;
|
|
@@ -227,21 +223,6 @@ export class Project {
|
|
|
227
223
|
});
|
|
228
224
|
}
|
|
229
225
|
setInitPromise() {
|
|
230
|
-
const loadConfig = async () => {
|
|
231
|
-
this.config = await this.#configService.load();
|
|
232
|
-
this.ignore = ignore();
|
|
233
|
-
for (const pattern of this.config.env.exclude) {
|
|
234
|
-
if (pattern === '@gitignore') {
|
|
235
|
-
const gitignore = await this.readGitignore();
|
|
236
|
-
if (gitignore) {
|
|
237
|
-
this.ignore.add(gitignore);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
this.ignore.add(pattern);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
226
|
const callIntializers = async () => {
|
|
246
227
|
const initCtx = {
|
|
247
228
|
cacheRoot: this.cacheRoot,
|
|
@@ -271,29 +252,13 @@ export class Project {
|
|
|
271
252
|
this.symbols = new SymbolUtil(symbols, this.externals.event.EventEmitter);
|
|
272
253
|
this.symbols.buildCache();
|
|
273
254
|
__profiler.task('Load Cache');
|
|
274
|
-
await
|
|
255
|
+
this.config = await this.#configService.load();
|
|
275
256
|
__profiler.task('Load Config');
|
|
276
257
|
await callIntializers();
|
|
277
258
|
__profiler.task('Initialize').finalize();
|
|
278
259
|
};
|
|
279
260
|
this.#initPromise = init();
|
|
280
261
|
}
|
|
281
|
-
async readGitignore() {
|
|
282
|
-
if (this.projectRoots.length === 0) {
|
|
283
|
-
return undefined;
|
|
284
|
-
}
|
|
285
|
-
try {
|
|
286
|
-
const uri = this.projectRoots[0] + Project.GitIgnore;
|
|
287
|
-
const contents = await this.externals.fs.readFile(uri);
|
|
288
|
-
return bufferToString(contents);
|
|
289
|
-
}
|
|
290
|
-
catch (e) {
|
|
291
|
-
if (!this.externals.error.isKind(e, 'ENOENT')) {
|
|
292
|
-
this.logger.error(`[Project] [readGitignore]`, e);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return undefined;
|
|
296
|
-
}
|
|
297
262
|
setReadyPromise() {
|
|
298
263
|
const getDependencies = async () => {
|
|
299
264
|
const ans = [];
|
|
@@ -339,15 +304,24 @@ export class Project {
|
|
|
339
304
|
this.#watcherReady = true;
|
|
340
305
|
resolve();
|
|
341
306
|
}).on('add', (uri) => {
|
|
307
|
+
if (this.shouldExclude(uri)) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
342
310
|
this.#watchedFiles.add(uri);
|
|
343
311
|
if (this.#watcherReady) {
|
|
344
312
|
this.emit('fileCreated', { uri });
|
|
345
313
|
}
|
|
346
314
|
}).on('change', (uri) => {
|
|
315
|
+
if (this.shouldExclude(uri)) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
347
318
|
if (this.#watcherReady) {
|
|
348
319
|
this.emit('fileModified', { uri });
|
|
349
320
|
}
|
|
350
321
|
}).on('unlink', (uri) => {
|
|
322
|
+
if (this.shouldExclude(uri)) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
351
325
|
this.#watchedFiles.delete(uri);
|
|
352
326
|
if (this.#watcherReady) {
|
|
353
327
|
this.emit('fileDeleted', { uri });
|
|
@@ -671,6 +645,9 @@ export class Project {
|
|
|
671
645
|
if (!fileUtil.isFileUri(uri)) {
|
|
672
646
|
return; // We only accept `file:` scheme for client-managed URIs.
|
|
673
647
|
}
|
|
648
|
+
if (this.shouldExclude(uri)) {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
674
651
|
const doc = TextDocument.create(uri, languageID, version, content);
|
|
675
652
|
const node = this.parse(doc);
|
|
676
653
|
this.#clientManagedUris.add(uri);
|
|
@@ -690,6 +667,9 @@ export class Project {
|
|
|
690
667
|
if (!fileUtil.isFileUri(uri)) {
|
|
691
668
|
return; // We only accept `file:` scheme for client-managed URIs.
|
|
692
669
|
}
|
|
670
|
+
if (this.shouldExclude(uri)) {
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
693
673
|
const doc = this.#clientManagedDocAndNodes.get(uri)?.doc;
|
|
694
674
|
if (!doc) {
|
|
695
675
|
throw new Error(`TextDocument for ${uri} is not cached. This should not happen. Did the language client send a didChange notification without sending a didOpen one, or is there a logic error on our side resulting the 'read' function overriding the 'TextDocument' created in the 'didOpen' notification handler?`);
|
|
@@ -744,6 +724,17 @@ export class Project {
|
|
|
744
724
|
this.logger.error('[Service#showCacheRoot]', e);
|
|
745
725
|
}
|
|
746
726
|
}
|
|
727
|
+
shouldExclude(uri) {
|
|
728
|
+
if (this.config.env.exclude.length === 0) {
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
for (const rel of fileUtil.getRels(uri, this.projectRoots)) {
|
|
732
|
+
if (micromatch.any(rel, this.config.env.exclude)) {
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
747
738
|
tryClearingCache(uri) {
|
|
748
739
|
if (this.shouldRemove(uri)) {
|
|
749
740
|
this.removeCachedTextDocument(uri);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -19,16 +19,17 @@
|
|
|
19
19
|
"chokidar": "^3.5.2",
|
|
20
20
|
"decompress": "^4.2.1",
|
|
21
21
|
"follow-redirects": "^1.14.8",
|
|
22
|
-
"
|
|
22
|
+
"micromatch": "^4.0.8",
|
|
23
23
|
"pako": "^2.0.4",
|
|
24
24
|
"rfdc": "^1.3.0",
|
|
25
25
|
"vscode-languageserver-textdocument": "^1.0.4",
|
|
26
26
|
"whatwg-url": "^14.0.0",
|
|
27
|
-
"@spyglassmc/locales": "0.3.
|
|
27
|
+
"@spyglassmc/locales": "0.3.11"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/decompress": "^4.2.3",
|
|
31
31
|
"@types/follow-redirects": "^1.14.1",
|
|
32
|
+
"@types/micromatch": "^4.0.9",
|
|
32
33
|
"@types/pako": "^2.0.0",
|
|
33
34
|
"@types/whatwg-url": "^11.0.4"
|
|
34
35
|
},
|