@spyglassmc/core 0.4.8 → 0.4.10
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.
|
@@ -7,7 +7,7 @@ import type { Project } from './Project.js';
|
|
|
7
7
|
* The format version of the cache. Should be increased when any changes that
|
|
8
8
|
* could invalidate the cache are introduced to the Spyglass codebase.
|
|
9
9
|
*/
|
|
10
|
-
export declare const LatestCacheVersion =
|
|
10
|
+
export declare const LatestCacheVersion = 5;
|
|
11
11
|
/**
|
|
12
12
|
* Checksums of cached files or roots.
|
|
13
13
|
*/
|
|
@@ -5,7 +5,7 @@ import { fileUtil } from './fileUtil.js';
|
|
|
5
5
|
* The format version of the cache. Should be increased when any changes that
|
|
6
6
|
* could invalidate the cache are introduced to the Spyglass codebase.
|
|
7
7
|
*/
|
|
8
|
-
export const LatestCacheVersion =
|
|
8
|
+
export const LatestCacheVersion = 5;
|
|
9
9
|
var Checksums;
|
|
10
10
|
(function (Checksums) {
|
|
11
11
|
function create() {
|
|
@@ -82,7 +82,7 @@ export class CacheService {
|
|
|
82
82
|
let filePath;
|
|
83
83
|
try {
|
|
84
84
|
filePath = await this.getCacheFileUri();
|
|
85
|
-
this.project.logger.info(`[CacheService#load] symbolCachePath =
|
|
85
|
+
this.project.logger.info(`[CacheService#load] symbolCachePath = ${filePath}`);
|
|
86
86
|
const cache = (await fileUtil.readGzippedJson(this.project.externals, filePath));
|
|
87
87
|
__profiler.task('Read File');
|
|
88
88
|
if (cache.version === LatestCacheVersion) {
|
|
@@ -187,7 +187,7 @@ export class CacheService {
|
|
|
187
187
|
return true;
|
|
188
188
|
}
|
|
189
189
|
catch (e) {
|
|
190
|
-
this.project.logger.error(`[CacheService#save] path =
|
|
190
|
+
this.project.logger.error(`[CacheService#save] path = ${filePath}`, e);
|
|
191
191
|
}
|
|
192
192
|
return false;
|
|
193
193
|
}
|
|
@@ -57,7 +57,7 @@ export class Downloader {
|
|
|
57
57
|
return ans;
|
|
58
58
|
}
|
|
59
59
|
catch (e) {
|
|
60
|
-
this.logger.error(`[Downloader] [${id}] Loading cached file
|
|
60
|
+
this.logger.error(`[Downloader] [${id}] Loading cached file ${cacheUri}`, e);
|
|
61
61
|
if (this.externals.error.isKind(e, 'ENOENT')) {
|
|
62
62
|
// Cache checksum exists, but cached file doesn't.
|
|
63
63
|
// Remove the invalid cache checksum.
|
|
@@ -65,7 +65,7 @@ export class Downloader {
|
|
|
65
65
|
await this.externals.fs.unlink(cacheChecksumUri);
|
|
66
66
|
}
|
|
67
67
|
catch (e) {
|
|
68
|
-
this.logger.error(`[Downloader] [${id}] Removing invalid cache checksum
|
|
68
|
+
this.logger.error(`[Downloader] [${id}] Removing invalid cache checksum ${cacheChecksumUri}`, e);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -73,12 +73,12 @@ export class Downloader {
|
|
|
73
73
|
}
|
|
74
74
|
catch (e) {
|
|
75
75
|
if (!this.externals.error.isKind(e, 'ENOENT')) {
|
|
76
|
-
this.logger.error(`[Downloader] [${id}] Loading cache checksum
|
|
76
|
+
this.logger.error(`[Downloader] [${id}] Loading cache checksum ${cacheChecksumUri}`, e);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
catch (e) {
|
|
81
|
-
this.logger.error(`[Downloader] [${id}] Fetching latest checksum
|
|
81
|
+
this.logger.error(`[Downloader] [${id}] Fetching latest checksum ${checksumJob.uri}`, e);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
try {
|
|
@@ -92,7 +92,7 @@ export class Downloader {
|
|
|
92
92
|
await fileUtil.writeFile(this.externals, cacheChecksumUri, `${checksum}\n`);
|
|
93
93
|
}
|
|
94
94
|
catch (e) {
|
|
95
|
-
this.logger.error(`[Downloader] [${id}] Saving cache checksum
|
|
95
|
+
this.logger.error(`[Downloader] [${id}] Saving cache checksum ${cacheChecksumUri}`, e);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
try {
|
|
@@ -100,24 +100,24 @@ export class Downloader {
|
|
|
100
100
|
await fileUtil.writeFile(this.externals, cacheUri, serializer(buffer));
|
|
101
101
|
}
|
|
102
102
|
catch (e) {
|
|
103
|
-
this.logger.error(`[Downloader] [${id}] Caching file
|
|
103
|
+
this.logger.error(`[Downloader] [${id}] Caching file ${cacheUri}`, e);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
this.logger.info(`[Downloader] [${id}] Downloaded from
|
|
106
|
+
this.logger.info(`[Downloader] [${id}] Downloaded from ${uri}`);
|
|
107
107
|
return await transformer(buffer);
|
|
108
108
|
}
|
|
109
109
|
catch (e) {
|
|
110
|
-
this.logger.error(`[Downloader] [${id}] Downloading
|
|
110
|
+
this.logger.error(`[Downloader] [${id}] Downloading ${uri}`, e);
|
|
111
111
|
if (cache && cacheUri) {
|
|
112
112
|
try {
|
|
113
113
|
const cachedBuffer = await fileUtil.readFile(this.externals, cacheUri);
|
|
114
114
|
const deserializer = cache.deserializer ?? ((b) => b);
|
|
115
115
|
const ans = await transformer(deserializer(cachedBuffer));
|
|
116
|
-
this.logger.warn(`[Downloader] [${id}] Fell back to cached file
|
|
116
|
+
this.logger.warn(`[Downloader] [${id}] Fell back to cached file ${cacheUri}`);
|
|
117
117
|
return ans;
|
|
118
118
|
}
|
|
119
119
|
catch (e) {
|
|
120
|
-
this.logger.error(`[Downloader] [${id}] Fallback: loading cached file
|
|
120
|
+
this.logger.error(`[Downloader] [${id}] Fallback: loading cached file ${cacheUri}`, e);
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
}
|
|
@@ -146,7 +146,7 @@ export class FileUriSupporter {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
catch (e) {
|
|
149
|
-
logger.error(`[FileUriSupporter#create] Bad dependency
|
|
149
|
+
logger.error(`[FileUriSupporter#create] Bad dependency ${uri}`, e);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
return new FileUriSupporter(externals, roots, files);
|
|
@@ -217,11 +217,11 @@ export class ArchiveUriSupporter {
|
|
|
217
217
|
*/
|
|
218
218
|
static decodeUri(uri) {
|
|
219
219
|
if (uri.protocol !== ArchiveUriSupporter.Protocol) {
|
|
220
|
-
throw new Error(`Expected protocol “${ArchiveUriSupporter.Protocol}” in
|
|
220
|
+
throw new Error(`Expected protocol “${ArchiveUriSupporter.Protocol}” in ${uri}`);
|
|
221
221
|
}
|
|
222
222
|
const path = uri.pathname;
|
|
223
223
|
if (!path) {
|
|
224
|
-
throw new Error(`Missing path in archive uri
|
|
224
|
+
throw new Error(`Missing path in archive uri ${uri}`);
|
|
225
225
|
}
|
|
226
226
|
return { archiveName: uri.host, pathInArchive: path.charAt(0) === '/' ? path.slice(1) : path };
|
|
227
227
|
}
|
|
@@ -241,7 +241,7 @@ export class ArchiveUriSupporter {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
catch (e) {
|
|
244
|
-
logger.error(`[SpyglassUriSupporter#create] Bad dependency
|
|
244
|
+
logger.error(`[SpyglassUriSupporter#create] Bad dependency ${uri}`, e);
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
return new ArchiveUriSupporter(externals, entries);
|
package/lib/service/Project.js
CHANGED
|
@@ -175,11 +175,12 @@ export class Project {
|
|
|
175
175
|
this.downloader = downloader ?? new Downloader(cacheRoot, externals, logger);
|
|
176
176
|
this.symbols = new SymbolUtil({}, externals.event.EventEmitter);
|
|
177
177
|
this.#ctx = {};
|
|
178
|
-
this.logger.info(`[Project] [init] cacheRoot =
|
|
178
|
+
this.logger.info(`[Project] [init] cacheRoot = ${cacheRoot}`);
|
|
179
|
+
this.logger.info(`[Project] [init] projectRoots = ${projectRoots.join(' ')}`);
|
|
179
180
|
this.#configService.on('changed', ({ config }) => {
|
|
180
181
|
this.config = config;
|
|
181
182
|
this.logger.info('[Project] [Config] Changed');
|
|
182
|
-
}).on('error', ({ error, uri }) => this.logger.error(`[Project] [Config] Failed loading
|
|
183
|
+
}).on('error', ({ error, uri }) => this.logger.error(`[Project] [Config] Failed loading ${uri}`, error));
|
|
183
184
|
this.setInitPromise();
|
|
184
185
|
this.setReadyPromise();
|
|
185
186
|
this.#cacheSaverIntervalId = setInterval(() => this.cacheService.save(), CacheAutoSaveInterval);
|
|
@@ -474,7 +475,7 @@ export class Project {
|
|
|
474
475
|
return TextDocument.create(uri, languageId, -1, content);
|
|
475
476
|
}
|
|
476
477
|
catch (e) {
|
|
477
|
-
this.logger.warn(`[Project] [read] Failed creating TextDocument for
|
|
478
|
+
this.logger.warn(`[Project] [read] Failed creating TextDocument for ${uri}`, e);
|
|
478
479
|
return undefined;
|
|
479
480
|
}
|
|
480
481
|
};
|
|
@@ -524,7 +525,7 @@ export class Project {
|
|
|
524
525
|
if (result) {
|
|
525
526
|
return result.doc;
|
|
526
527
|
}
|
|
527
|
-
throw new Error(`[Project] [read] Client-managed URI
|
|
528
|
+
throw new Error(`[Project] [read] Client-managed URI ${uri} does not have a TextDocument in the cache`);
|
|
528
529
|
}
|
|
529
530
|
return getCacheHandlingPromise(uri);
|
|
530
531
|
}
|
|
@@ -561,7 +562,7 @@ export class Project {
|
|
|
561
562
|
this.#symbolUpToDateUris.add(doc.uri);
|
|
562
563
|
}
|
|
563
564
|
catch (e) {
|
|
564
|
-
this.logger.error(`[Project] [bind] Failed for
|
|
565
|
+
this.logger.error(`[Project] [bind] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
565
566
|
}
|
|
566
567
|
}
|
|
567
568
|
async check(doc, node) {
|
|
@@ -579,7 +580,7 @@ export class Project {
|
|
|
579
580
|
});
|
|
580
581
|
}
|
|
581
582
|
catch (e) {
|
|
582
|
-
this.logger.error(`[Project] [check] Failed for
|
|
583
|
+
this.logger.error(`[Project] [check] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
583
584
|
}
|
|
584
585
|
}
|
|
585
586
|
lint(doc, node) {
|
|
@@ -616,7 +617,7 @@ export class Project {
|
|
|
616
617
|
}
|
|
617
618
|
}
|
|
618
619
|
catch (e) {
|
|
619
|
-
this.logger.error(`[Project] [lint] Failed for
|
|
620
|
+
this.logger.error(`[Project] [lint] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
620
621
|
}
|
|
621
622
|
}
|
|
622
623
|
// @SingletonPromise()
|
|
@@ -675,7 +676,7 @@ export class Project {
|
|
|
675
676
|
}
|
|
676
677
|
const doc = this.#clientManagedDocAndNodes.get(uri)?.doc;
|
|
677
678
|
if (!doc) {
|
|
678
|
-
throw new Error(`TextDocument for
|
|
679
|
+
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?`);
|
|
679
680
|
}
|
|
680
681
|
TextDocument.update(doc, changes, version);
|
|
681
682
|
const node = this.parse(doc);
|
package/lib/service/Service.js
CHANGED
|
@@ -27,18 +27,18 @@ export class Service {
|
|
|
27
27
|
}
|
|
28
28
|
colorize(node, doc, range) {
|
|
29
29
|
try {
|
|
30
|
-
this.debug(`Colorizing
|
|
30
|
+
this.debug(`Colorizing ${doc.uri} # ${doc.version}`);
|
|
31
31
|
const colorizer = this.project.meta.getColorizer(node.type);
|
|
32
32
|
return colorizer(node, ColorizerContext.create(this.project, { doc, range }));
|
|
33
33
|
}
|
|
34
34
|
catch (e) {
|
|
35
|
-
this.logger.error(`[Service] [colorize] Failed for
|
|
35
|
+
this.logger.error(`[Service] [colorize] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
36
36
|
}
|
|
37
37
|
return [];
|
|
38
38
|
}
|
|
39
39
|
getColorInfo(node, doc) {
|
|
40
40
|
try {
|
|
41
|
-
this.debug(`Getting color info for
|
|
41
|
+
this.debug(`Getting color info for ${doc.uri} # ${doc.version}`);
|
|
42
42
|
const ans = [];
|
|
43
43
|
traversePreOrder(node, (_) => true, (node) => node.color, (node) => ans.push({
|
|
44
44
|
color: Array.isArray(node.color) ? node.color : node.color.value,
|
|
@@ -47,13 +47,13 @@ export class Service {
|
|
|
47
47
|
return ans;
|
|
48
48
|
}
|
|
49
49
|
catch (e) {
|
|
50
|
-
this.logger.error(`[Service] [getColorInfo] Failed for
|
|
50
|
+
this.logger.error(`[Service] [getColorInfo] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
51
51
|
}
|
|
52
52
|
return [];
|
|
53
53
|
}
|
|
54
54
|
getColorPresentation(file, doc, range, color) {
|
|
55
55
|
try {
|
|
56
|
-
this.debug(`Getting color presentation for
|
|
56
|
+
this.debug(`Getting color presentation for ${doc.uri} # ${doc.version} @ ${Range.toString(range)}`);
|
|
57
57
|
let node = AstNode.findDeepestChild({ node: file, needle: range.start });
|
|
58
58
|
while (node) {
|
|
59
59
|
const nodeColor = node.color;
|
|
@@ -65,20 +65,20 @@ export class Service {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
catch (e) {
|
|
68
|
-
this.logger.error(`[Service] [getColorPresentation] Failed for
|
|
68
|
+
this.logger.error(`[Service] [getColorPresentation] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
69
69
|
}
|
|
70
70
|
return [];
|
|
71
71
|
}
|
|
72
72
|
complete(node, doc, offset, triggerCharacter) {
|
|
73
73
|
try {
|
|
74
|
-
this.debug(`Getting completion for
|
|
74
|
+
this.debug(`Getting completion for ${doc.uri} # ${doc.version} @ ${offset}`);
|
|
75
75
|
const shouldComplete = this.project.meta.shouldComplete(doc.languageId, triggerCharacter);
|
|
76
76
|
if (shouldComplete) {
|
|
77
77
|
return completer.file(node, CompleterContext.create(this.project, { doc, offset, triggerCharacter }));
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
catch (e) {
|
|
81
|
-
this.logger.error(`[Service] [complete] Failed for
|
|
81
|
+
this.logger.error(`[Service] [complete] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
82
82
|
}
|
|
83
83
|
return [];
|
|
84
84
|
}
|
|
@@ -99,18 +99,18 @@ export class Service {
|
|
|
99
99
|
}
|
|
100
100
|
format(node, doc, tabSize, insertSpaces) {
|
|
101
101
|
try {
|
|
102
|
-
this.debug(`Formatting
|
|
102
|
+
this.debug(`Formatting ${doc.uri} # ${doc.version}`);
|
|
103
103
|
const formatter = this.project.meta.getFormatter(node.type);
|
|
104
104
|
return formatter(node, FormatterContext.create(this.project, { doc, tabSize, insertSpaces }));
|
|
105
105
|
}
|
|
106
106
|
catch (e) {
|
|
107
|
-
this.logger.error(`[Service] [format] Failed for
|
|
107
|
+
this.logger.error(`[Service] [format] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
108
108
|
throw e;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
getHover(file, doc, offset) {
|
|
112
112
|
try {
|
|
113
|
-
this.debug(`Getting hover for
|
|
113
|
+
this.debug(`Getting hover for ${doc.uri} # ${doc.version} @ ${offset}`);
|
|
114
114
|
let node = AstNode.findDeepestChild({ node: file, needle: offset });
|
|
115
115
|
while (node) {
|
|
116
116
|
const symbol = this.project.symbols.resolveAlias(node.symbol);
|
|
@@ -125,14 +125,14 @@ export class Service {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
catch (e) {
|
|
128
|
-
this.logger.error(`[Service] [getHover] Failed for
|
|
128
|
+
this.logger.error(`[Service] [getHover] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
129
129
|
}
|
|
130
130
|
return undefined;
|
|
131
131
|
}
|
|
132
132
|
getInlayHints(node, doc, range) {
|
|
133
133
|
try {
|
|
134
134
|
// TODO: `range` argument is not used.
|
|
135
|
-
this.debug(`Getting inlay hints for
|
|
135
|
+
this.debug(`Getting inlay hints for ${doc.uri} # ${doc.version}`);
|
|
136
136
|
const ans = [];
|
|
137
137
|
const ctx = ProcessorContext.create(this.project, { doc });
|
|
138
138
|
for (const provider of this.project.meta.inlayHintProviders) {
|
|
@@ -141,13 +141,13 @@ export class Service {
|
|
|
141
141
|
return ans;
|
|
142
142
|
}
|
|
143
143
|
catch (e) {
|
|
144
|
-
this.logger.error(`[Service] [getInlayHints] Failed for
|
|
144
|
+
this.logger.error(`[Service] [getInlayHints] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
145
145
|
}
|
|
146
146
|
return [];
|
|
147
147
|
}
|
|
148
148
|
getSignatureHelp(node, doc, offset) {
|
|
149
149
|
try {
|
|
150
|
-
this.debug(`Getting signature help for
|
|
150
|
+
this.debug(`Getting signature help for ${doc.uri} # ${doc.version} @ ${offset}`);
|
|
151
151
|
const ctx = SignatureHelpProviderContext.create(this.project, { doc, offset });
|
|
152
152
|
for (const provider of this.project.meta.signatureHelpProviders) {
|
|
153
153
|
const result = provider(node, ctx);
|
|
@@ -157,7 +157,7 @@ export class Service {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
catch (e) {
|
|
160
|
-
this.logger.error(`[Service] [getSignatureHelp] Failed for
|
|
160
|
+
this.logger.error(`[Service] [getSignatureHelp] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
161
161
|
}
|
|
162
162
|
return undefined;
|
|
163
163
|
}
|
|
@@ -169,7 +169,7 @@ export class Service {
|
|
|
169
169
|
*/
|
|
170
170
|
async getSymbolLocations(file, doc, offset, searchedUsages = SymbolUsageTypes, currentFileOnly = false) {
|
|
171
171
|
try {
|
|
172
|
-
this.debug(`Getting symbol locations of usage '${searchedUsages.join(',')}' for
|
|
172
|
+
this.debug(`Getting symbol locations of usage '${searchedUsages.join(',')}' for ${doc.uri} # ${doc.version} @ ${offset} with currentFileOnly=${currentFileOnly}`);
|
|
173
173
|
let node = AstNode.findDeepestChild({ node: file, needle: offset });
|
|
174
174
|
while (node) {
|
|
175
175
|
const symbol = this.project.symbols.resolveAlias(node.symbol);
|
|
@@ -197,7 +197,7 @@ export class Service {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
catch (e) {
|
|
200
|
-
this.logger.error(`[Service] [getSymbolLocations] Failed for
|
|
200
|
+
this.logger.error(`[Service] [getSymbolLocations] Failed for ${doc.uri} # ${doc.version}`, e);
|
|
201
201
|
}
|
|
202
202
|
return undefined;
|
|
203
203
|
}
|