@spyglassmc/core 0.4.1 → 0.4.3
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.
- package/lib/common/Dev.d.ts +7 -7
- package/lib/common/Dev.js +20 -14
- package/lib/common/ReadonlyProxy.d.ts +9 -6
- package/lib/common/ReadonlyProxy.js +6 -4
- package/lib/common/StateProxy.d.ts +11 -11
- package/lib/common/StateProxy.js +21 -14
- package/lib/common/externals/NodeJsExternals.js +11 -3
- package/lib/common/externals/downloader.d.ts +8 -8
- package/lib/common/externals/downloader.js +12 -8
- package/lib/common/externals/index.d.ts +3 -3
- package/lib/common/util.d.ts +23 -21
- package/lib/common/util.js +13 -2
- package/lib/node/AstNode.d.ts +1 -1
- package/lib/node/AstNode.js +3 -1
- package/lib/node/CommentNode.d.ts +4 -4
- package/lib/node/CommentNode.js +6 -4
- package/lib/node/ResourceLocationNode.d.ts +1 -1
- package/lib/node/ResourceLocationNode.js +6 -8
- package/lib/node/StringNode.d.ts +3 -3
- package/lib/node/StringNode.js +4 -1
- package/lib/parser/Parser.d.ts +5 -5
- package/lib/parser/float.d.ts +1 -1
- package/lib/parser/integer.d.ts +1 -1
- package/lib/parser/long.d.ts +1 -1
- package/lib/parser/resourceLocation.js +1 -1
- package/lib/parser/string.js +4 -1
- package/lib/parser/util.d.ts +11 -7
- package/lib/parser/util.js +17 -2
- package/lib/processor/ColorInfoProvider.d.ts +3 -3
- package/lib/processor/ColorInfoProvider.js +4 -2
- package/lib/processor/InlayHintProvider.d.ts +4 -2
- package/lib/processor/SignatureHelpProvider.d.ts +1 -1
- package/lib/processor/binder/Binder.d.ts +9 -9
- package/lib/processor/binder/Binder.js +18 -12
- package/lib/processor/binder/builtin.d.ts +2 -2
- package/lib/processor/binder/builtin.js +3 -1
- package/lib/processor/binder/index.d.ts +1 -1
- package/lib/processor/binder/index.js +1 -1
- package/lib/processor/checker/Checker.d.ts +3 -3
- package/lib/processor/checker/builtin.d.ts +1 -1
- package/lib/processor/checker/builtin.js +2 -1
- package/lib/processor/colorizer/Colorizer.d.ts +3 -3
- package/lib/processor/completer/Completer.d.ts +1 -1
- package/lib/processor/completer/builtin.js +8 -4
- package/lib/processor/formatter/Formatter.d.ts +1 -1
- package/lib/processor/formatter/Formatter.js +3 -1
- package/lib/processor/linter/Linter.d.ts +1 -1
- package/lib/processor/util.d.ts +1 -1
- package/lib/service/CacheService.d.ts +1 -1
- package/lib/service/CacheService.js +2 -2
- package/lib/service/Config.d.ts +9 -9
- package/lib/service/Config.js +17 -3
- package/lib/service/Dependency.d.ts +3 -3
- package/lib/service/FileService.d.ts +3 -3
- package/lib/service/FileService.js +40 -32
- package/lib/service/Project.d.ts +5 -5
- package/lib/service/Project.js +9 -5
- package/lib/service/Service.js +12 -3
- package/lib/service/SymbolRegistrar.d.ts +1 -1
- package/lib/service/UriProcessor.d.ts +3 -3
- package/lib/service/fileUtil.d.ts +3 -2
- package/lib/service/fileUtil.js +4 -0
- package/lib/source/IndexMap.d.ts +1 -1
- package/lib/source/IndexMap.js +7 -7
- package/lib/source/LanguageError.d.ts +4 -4
- package/lib/source/LanguageError.js +9 -6
- package/lib/source/Location.d.ts +1 -1
- package/lib/source/Offset.d.ts +1 -1
- package/lib/source/Range.d.ts +1 -1
- package/lib/source/Source.d.ts +12 -10
- package/lib/source/Source.js +16 -9
- package/lib/symbol/Symbol.d.ts +16 -16
- package/lib/symbol/Symbol.js +15 -9
- package/lib/symbol/SymbolUtil.d.ts +4 -4
- package/lib/symbol/SymbolUtil.js +4 -3
- package/package.json +5 -3
|
@@ -77,7 +77,19 @@ export class FileServiceImpl {
|
|
|
77
77
|
try {
|
|
78
78
|
let mappedUri = this.map.getKey(virtualUri);
|
|
79
79
|
if (mappedUri === undefined) {
|
|
80
|
-
mappedUri = `${this.virtualUrisRoot}${await this.externals.crypto
|
|
80
|
+
mappedUri = `${this.virtualUrisRoot}${await this.externals.crypto
|
|
81
|
+
.getSha1(virtualUri)}/${fileUtil.basename(virtualUri)}`;
|
|
82
|
+
// Delete old mapped file if it exists. This makes sure the
|
|
83
|
+
// readonly permission on the file is not removed by it being
|
|
84
|
+
// overwritten.
|
|
85
|
+
try {
|
|
86
|
+
await fileUtil.unlink(this.externals, mappedUri);
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
if (!this.externals.error.isKind(e, 'ENOENT')) {
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
81
93
|
const buffer = await this.readFile(virtualUri);
|
|
82
94
|
await fileUtil.writeFile(this.externals, mappedUri, buffer, 0o444);
|
|
83
95
|
this.map.set(mappedUri, virtualUri);
|
|
@@ -159,58 +171,58 @@ export class ArchiveUriSupporter {
|
|
|
159
171
|
];
|
|
160
172
|
protocol = ArchiveUriSupporter.Protocol;
|
|
161
173
|
/**
|
|
162
|
-
* @param entries A map from archive
|
|
174
|
+
* @param entries A map from archive names to unzipped entries.
|
|
163
175
|
*/
|
|
164
176
|
constructor(externals, entries) {
|
|
165
177
|
this.externals = externals;
|
|
166
178
|
this.entries = entries;
|
|
167
179
|
}
|
|
168
180
|
async hash(uri) {
|
|
169
|
-
const {
|
|
181
|
+
const { archiveName, pathInArchive } = ArchiveUriSupporter.decodeUri(new Uri(uri));
|
|
170
182
|
if (!pathInArchive) {
|
|
171
183
|
// Hash the archive itself.
|
|
172
|
-
return hashFile(this.externals,
|
|
184
|
+
return hashFile(this.externals, archiveName);
|
|
173
185
|
}
|
|
174
186
|
else {
|
|
175
187
|
// Hash the corresponding file.
|
|
176
|
-
return this.externals.crypto.getSha1(this.getDataInArchive(
|
|
188
|
+
return this.externals.crypto.getSha1(this.getDataInArchive(archiveName, pathInArchive));
|
|
177
189
|
}
|
|
178
190
|
}
|
|
179
191
|
async readFile(uri) {
|
|
180
|
-
const {
|
|
181
|
-
return this.getDataInArchive(
|
|
192
|
+
const { archiveName, pathInArchive } = ArchiveUriSupporter.decodeUri(new Uri(uri));
|
|
193
|
+
return this.getDataInArchive(archiveName, pathInArchive);
|
|
182
194
|
}
|
|
183
195
|
/**
|
|
184
196
|
* @throws
|
|
185
197
|
*/
|
|
186
|
-
getDataInArchive(
|
|
187
|
-
const entries = this.entries.get(
|
|
198
|
+
getDataInArchive(archiveName, pathInArchive) {
|
|
199
|
+
const entries = this.entries.get(archiveName);
|
|
188
200
|
if (!entries) {
|
|
189
|
-
throw new Error(`Archive “${
|
|
201
|
+
throw new Error(`Archive “${archiveName}” has not been loaded into the memory`);
|
|
190
202
|
}
|
|
191
203
|
const entry = entries.get(pathInArchive);
|
|
192
204
|
if (!entry) {
|
|
193
|
-
throw new Error(`Path “${pathInArchive}” does not exist in archive “${
|
|
205
|
+
throw new Error(`Path “${pathInArchive}” does not exist in archive “${archiveName}”`);
|
|
194
206
|
}
|
|
195
207
|
if (entry.type !== 'file') {
|
|
196
|
-
throw new Error(`Path “${pathInArchive}” in archive “${
|
|
208
|
+
throw new Error(`Path “${pathInArchive}” in archive “${archiveName}” is not a file`);
|
|
197
209
|
}
|
|
198
210
|
return entry.data;
|
|
199
211
|
}
|
|
200
212
|
*listFiles() {
|
|
201
|
-
for (const [
|
|
213
|
+
for (const [archiveName, files] of this.entries.entries()) {
|
|
202
214
|
for (const file of files.values()) {
|
|
203
|
-
yield ArchiveUriSupporter.getUri(
|
|
215
|
+
yield ArchiveUriSupporter.getUri(archiveName, file.path);
|
|
204
216
|
}
|
|
205
217
|
}
|
|
206
218
|
}
|
|
207
219
|
*listRoots() {
|
|
208
|
-
for (const
|
|
209
|
-
yield ArchiveUriSupporter.getUri(
|
|
220
|
+
for (const archiveName of this.entries.keys()) {
|
|
221
|
+
yield ArchiveUriSupporter.getUri(archiveName);
|
|
210
222
|
}
|
|
211
223
|
}
|
|
212
|
-
static getUri(
|
|
213
|
-
return `${ArchiveUriSupporter.Protocol}
|
|
224
|
+
static getUri(archiveName, pathInArchive = '') {
|
|
225
|
+
return `${ArchiveUriSupporter.Protocol}//${archiveName}/${pathInArchive.replace(/\\/g, '/')}`;
|
|
214
226
|
}
|
|
215
227
|
/**
|
|
216
228
|
* @throws When `uri` has the wrong protocol or hostname.
|
|
@@ -219,36 +231,32 @@ export class ArchiveUriSupporter {
|
|
|
219
231
|
if (uri.protocol !== ArchiveUriSupporter.Protocol) {
|
|
220
232
|
throw new Error(`Expected protocol “${ArchiveUriSupporter.Protocol}” in “${uri}”`);
|
|
221
233
|
}
|
|
222
|
-
const path = uri.
|
|
234
|
+
const path = uri.pathname;
|
|
223
235
|
if (!path) {
|
|
224
236
|
throw new Error(`Missing path in archive uri “${uri.toString()}”`);
|
|
225
237
|
}
|
|
226
238
|
return {
|
|
227
|
-
|
|
239
|
+
archiveName: uri.host,
|
|
228
240
|
pathInArchive: path.charAt(0) === '/' ? path.slice(1) : path,
|
|
229
241
|
};
|
|
230
242
|
}
|
|
231
|
-
static async create(dependencies, externals, logger
|
|
243
|
+
static async create(dependencies, externals, logger) {
|
|
232
244
|
const entries = new Map();
|
|
233
245
|
for (const { uri, info } of dependencies) {
|
|
234
246
|
try {
|
|
235
247
|
if (uri.startsWith('file:') &&
|
|
236
248
|
ArchiveUriSupporter.SupportedArchiveExtnames.some((ext) => uri.endsWith(ext)) &&
|
|
237
249
|
(await externals.fs.stat(uri)).isFile()) {
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const checksum = await hashFile(externals, uri);
|
|
242
|
-
if (cachedChecksum === checksum) {
|
|
243
|
-
// The dependency has not changed since last cache.
|
|
244
|
-
logger.info(`[SpyglassUriSupporter#create] Skipped decompressing “${uri}” thanks to cache ${checksum}`);
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
250
|
+
const archiveName = fileUtil.basename(uri);
|
|
251
|
+
if (entries.has(archiveName)) {
|
|
252
|
+
throw new Error(`A different URI with ${archiveName} already exists`);
|
|
247
253
|
}
|
|
248
254
|
const files = await externals.archive.decompressBall(await externals.fs.readFile(uri), {
|
|
249
|
-
stripLevel: typeof info?.startDepth === 'number'
|
|
255
|
+
stripLevel: typeof info?.startDepth === 'number'
|
|
256
|
+
? info.startDepth
|
|
257
|
+
: 0,
|
|
250
258
|
});
|
|
251
|
-
entries.set(
|
|
259
|
+
entries.set(archiveName, new Map(files.map((f) => [f.path.replace(/\\/g, '/'), f])));
|
|
252
260
|
}
|
|
253
261
|
}
|
|
254
262
|
catch (e) {
|
package/lib/service/Project.d.ts
CHANGED
|
@@ -13,10 +13,10 @@ import { FileService } from './FileService.js';
|
|
|
13
13
|
import type { RootUriString } from './fileUtil.js';
|
|
14
14
|
import { MetaRegistry } from './MetaRegistry.js';
|
|
15
15
|
import { ProfilerFactory } from './Profiler.js';
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
16
|
+
export type ProjectInitializerContext = Pick<Project, 'cacheRoot' | 'config' | 'downloader' | 'externals' | 'logger' | 'meta' | 'projectRoot'>;
|
|
17
|
+
export type SyncProjectInitializer = (this: void, ctx: ProjectInitializerContext) => Record<string, string> | void;
|
|
18
|
+
export type AsyncProjectInitializer = (this: void, ctx: ProjectInitializerContext) => PromiseLike<Record<string, string> | void>;
|
|
19
|
+
export type ProjectInitializer = SyncProjectInitializer | AsyncProjectInitializer;
|
|
20
20
|
export interface ProjectOptions {
|
|
21
21
|
cacheRoot: RootUriString;
|
|
22
22
|
defaultConfig?: Config;
|
|
@@ -55,7 +55,7 @@ interface SymbolRegistrarEvent {
|
|
|
55
55
|
id: string;
|
|
56
56
|
checksum: string | undefined;
|
|
57
57
|
}
|
|
58
|
-
export
|
|
58
|
+
export type ProjectData = Pick<Project, 'cacheRoot' | 'config' | 'downloader' | 'ensureBindingStarted' | 'externals' | 'fs' | 'logger' | 'meta' | 'profilers' | 'projectRoot' | 'roots' | 'symbols' | 'ctx'>;
|
|
59
59
|
/**
|
|
60
60
|
* Manage all tracked documents and errors.
|
|
61
61
|
*
|
package/lib/service/Project.js
CHANGED
|
@@ -21,7 +21,7 @@ import { ArchiveUriSupporter, FileService, FileUriSupporter, } from './FileServi
|
|
|
21
21
|
import { fileUtil } from './fileUtil.js';
|
|
22
22
|
import { MetaRegistry } from './MetaRegistry.js';
|
|
23
23
|
import { ProfilerFactory } from './Profiler.js';
|
|
24
|
-
const CacheAutoSaveInterval =
|
|
24
|
+
const CacheAutoSaveInterval = 600_000; // 10 Minutes.
|
|
25
25
|
/* istanbul ignore next */
|
|
26
26
|
/**
|
|
27
27
|
* Manage all tracked documents and errors.
|
|
@@ -165,7 +165,8 @@ export class Project {
|
|
|
165
165
|
this.projectRoot = projectRoot;
|
|
166
166
|
this.cacheService = new CacheService(cacheRoot, this);
|
|
167
167
|
this.#configService = new ConfigService(this, defaultConfig);
|
|
168
|
-
this.downloader = downloader ??
|
|
168
|
+
this.downloader = downloader ??
|
|
169
|
+
new Downloader(cacheRoot, externals, logger);
|
|
169
170
|
this.symbols = new SymbolUtil({}, externals.event.EventEmitter);
|
|
170
171
|
this.#ctx = {};
|
|
171
172
|
this.logger.info(`[Project] [init] cacheRoot = “${cacheRoot}”`);
|
|
@@ -289,7 +290,7 @@ export class Project {
|
|
|
289
290
|
const listDependencyFiles = async () => {
|
|
290
291
|
const dependencies = await getDependencies();
|
|
291
292
|
const fileUriSupporter = await FileUriSupporter.create(dependencies, this.externals, this.logger);
|
|
292
|
-
const archiveUriSupporter = await ArchiveUriSupporter.create(dependencies, this.externals, this.logger
|
|
293
|
+
const archiveUriSupporter = await ArchiveUriSupporter.create(dependencies, this.externals, this.logger);
|
|
293
294
|
this.fs.register('file:', fileUriSupporter, true);
|
|
294
295
|
this.fs.register(ArchiveUriSupporter.Protocol, archiveUriSupporter, true);
|
|
295
296
|
};
|
|
@@ -349,7 +350,9 @@ export class Project {
|
|
|
349
350
|
this.emit('documentErrored', { errors: values, uri });
|
|
350
351
|
}
|
|
351
352
|
__profiler.task('Pop Errors');
|
|
352
|
-
const { addedFiles, changedFiles, removedFiles } = await this
|
|
353
|
+
const { addedFiles, changedFiles, removedFiles } = await this
|
|
354
|
+
.cacheService
|
|
355
|
+
.validate();
|
|
353
356
|
for (const uri of removedFiles) {
|
|
354
357
|
this.emit('fileDeleted', { uri });
|
|
355
358
|
}
|
|
@@ -559,7 +562,8 @@ export class Project {
|
|
|
559
562
|
continue;
|
|
560
563
|
}
|
|
561
564
|
const { ruleSeverity, ruleValue } = result;
|
|
562
|
-
const { configValidator, linter, nodePredicate } = this.meta
|
|
565
|
+
const { configValidator, linter, nodePredicate } = this.meta
|
|
566
|
+
.getLinter(ruleName);
|
|
563
567
|
if (!configValidator(ruleName, ruleValue, this.logger)) {
|
|
564
568
|
// Config value is invalid.
|
|
565
569
|
continue;
|
package/lib/service/Service.js
CHANGED
|
@@ -45,7 +45,9 @@ export class Service {
|
|
|
45
45
|
this.debug(`Getting color info for '${doc.uri}' # ${doc.version}`);
|
|
46
46
|
const ans = [];
|
|
47
47
|
traversePreOrder(node, (_) => true, (node) => node.color, (node) => ans.push({
|
|
48
|
-
color: Array.isArray(node.color)
|
|
48
|
+
color: Array.isArray(node.color)
|
|
49
|
+
? node.color
|
|
50
|
+
: node.color.value,
|
|
49
51
|
range: Array.isArray(node.color)
|
|
50
52
|
? node.range
|
|
51
53
|
: node.color.range ?? node.range,
|
|
@@ -60,7 +62,10 @@ export class Service {
|
|
|
60
62
|
getColorPresentation(file, doc, range, color) {
|
|
61
63
|
try {
|
|
62
64
|
this.debug(`Getting color presentation for '${doc.uri}' # ${doc.version} @ ${Range.toString(range)}`);
|
|
63
|
-
let node = AstNode.findDeepestChild({
|
|
65
|
+
let node = AstNode.findDeepestChild({
|
|
66
|
+
node: file,
|
|
67
|
+
needle: range.start,
|
|
68
|
+
});
|
|
64
69
|
while (node) {
|
|
65
70
|
const nodeColor = node.color;
|
|
66
71
|
if (nodeColor && !Array.isArray(nodeColor)) {
|
|
@@ -113,7 +118,11 @@ export class Service {
|
|
|
113
118
|
try {
|
|
114
119
|
this.debug(`Formatting '${doc.uri}' # ${doc.version}`);
|
|
115
120
|
const formatter = this.project.meta.getFormatter(node.type);
|
|
116
|
-
return formatter(node, FormatterContext.create(this.project, {
|
|
121
|
+
return formatter(node, FormatterContext.create(this.project, {
|
|
122
|
+
doc,
|
|
123
|
+
tabSize,
|
|
124
|
+
insertSpaces,
|
|
125
|
+
}));
|
|
117
126
|
}
|
|
118
127
|
catch (e) {
|
|
119
128
|
this.logger.error(`[Service] [format] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SymbolUtil } from '../symbol/index.js';
|
|
2
|
-
export
|
|
2
|
+
export type SymbolRegistrar = (this: void, symbols: SymbolUtil, ctx: SymbolRegistrarContext) => void;
|
|
3
3
|
export interface SymbolRegistrarContext {
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=SymbolRegistrar.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UriBinderContext } from './Context.js';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export type UriBinder = (uris: readonly string[], ctx: UriBinderContext) => void;
|
|
3
|
+
export type UriSorterRegistration = (this: void, a: string, b: string, next: UriSorter) => number;
|
|
4
|
+
export type UriSorter = (this: void, a: string, b: string) => number;
|
|
5
5
|
//# sourceMappingURL=UriProcessor.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Externals, FsLocation } from '../common/index.js';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type RootUriString = `${string}/`;
|
|
3
|
+
export type FileExtension = `.${string}`;
|
|
4
4
|
export declare namespace fileUtil {
|
|
5
5
|
/**
|
|
6
6
|
* @param rootUris The root URIs. Each URI in this array must end with a slash (`/`).
|
|
@@ -57,6 +57,7 @@ export declare namespace fileUtil {
|
|
|
57
57
|
function chmod(externals: Externals, path: FsLocation, mode: number): Promise<void>;
|
|
58
58
|
function ensureWritable(externals: Externals, path: FsLocation): Promise<void>;
|
|
59
59
|
function markReadOnly(externals: Externals, path: FsLocation): Promise<void>;
|
|
60
|
+
function unlink(externals: Externals, path: FsLocation): Promise<void>;
|
|
60
61
|
function readFile(externals: Externals, path: FsLocation): Promise<Uint8Array>;
|
|
61
62
|
/**
|
|
62
63
|
* @throws
|
package/lib/service/fileUtil.js
CHANGED
|
@@ -123,6 +123,10 @@ export var fileUtil;
|
|
|
123
123
|
return chmod(externals, path, 0o444);
|
|
124
124
|
}
|
|
125
125
|
fileUtil.markReadOnly = markReadOnly;
|
|
126
|
+
async function unlink(externals, path) {
|
|
127
|
+
return externals.fs.unlink(path);
|
|
128
|
+
}
|
|
129
|
+
fileUtil.unlink = unlink;
|
|
126
130
|
async function readFile(externals, path) {
|
|
127
131
|
return externals.fs.readFile(path);
|
|
128
132
|
}
|
package/lib/source/IndexMap.d.ts
CHANGED
package/lib/source/IndexMap.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Range } from './Range.js';
|
|
2
2
|
export var IndexMap;
|
|
3
3
|
(function (IndexMap) {
|
|
4
|
-
function convertOffset(map, offset, from, to
|
|
4
|
+
function convertOffset(map, offset, from, to) {
|
|
5
5
|
let ans = offset;
|
|
6
6
|
for (const pair of map) {
|
|
7
|
-
if (Range.contains(pair[from], offset
|
|
8
|
-
return
|
|
7
|
+
if (Range.contains(pair[from], offset)) {
|
|
8
|
+
return pair[to].start;
|
|
9
9
|
}
|
|
10
10
|
else if (Range.endsBefore(pair[from], offset)) {
|
|
11
11
|
ans = offset - pair[from].end + pair[to].end;
|
|
@@ -17,19 +17,19 @@ export var IndexMap;
|
|
|
17
17
|
return ans;
|
|
18
18
|
}
|
|
19
19
|
function toInnerOffset(map, offset) {
|
|
20
|
-
return convertOffset(map, offset, 'outer', 'inner'
|
|
20
|
+
return convertOffset(map, offset, 'outer', 'inner');
|
|
21
21
|
}
|
|
22
22
|
IndexMap.toInnerOffset = toInnerOffset;
|
|
23
23
|
function toInnerRange(map, outer) {
|
|
24
|
-
return Range.create(toInnerOffset(map, outer.start),
|
|
24
|
+
return Range.create(toInnerOffset(map, outer.start), toInnerOffset(map, outer.end));
|
|
25
25
|
}
|
|
26
26
|
IndexMap.toInnerRange = toInnerRange;
|
|
27
27
|
function toOuterOffset(map, offset) {
|
|
28
|
-
return convertOffset(map, offset, 'inner', 'outer'
|
|
28
|
+
return convertOffset(map, offset, 'inner', 'outer');
|
|
29
29
|
}
|
|
30
30
|
IndexMap.toOuterOffset = toOuterOffset;
|
|
31
31
|
function toOuterRange(map, inner) {
|
|
32
|
-
return Range.create(toOuterOffset(map, inner.start),
|
|
32
|
+
return Range.create(toOuterOffset(map, inner.start), toOuterOffset(map, inner.end));
|
|
33
33
|
}
|
|
34
34
|
IndexMap.toOuterRange = toOuterRange;
|
|
35
35
|
function merge(outerMap, innerMap) {
|
|
@@ -16,13 +16,13 @@ export interface LanguageError extends LanguageErrorData {
|
|
|
16
16
|
export interface PosRangeLanguageError extends LanguageErrorData {
|
|
17
17
|
posRange: PositionRange;
|
|
18
18
|
}
|
|
19
|
-
export declare
|
|
20
|
-
create(message: string, range: Range, severity?: ErrorSeverity, info?: LanguageErrorInfo): LanguageError;
|
|
19
|
+
export declare namespace LanguageError {
|
|
20
|
+
function create(message: string, range: Range, severity?: ErrorSeverity, info?: LanguageErrorInfo): LanguageError;
|
|
21
21
|
/**
|
|
22
22
|
* @returns A {@link PosRangeLanguageError}.
|
|
23
23
|
*/
|
|
24
|
-
withPosRange(error: LanguageError, doc: TextDocument): PosRangeLanguageError;
|
|
25
|
-
}
|
|
24
|
+
function withPosRange(error: LanguageError, doc: TextDocument): PosRangeLanguageError;
|
|
25
|
+
}
|
|
26
26
|
export declare const enum ErrorSeverity {
|
|
27
27
|
Hint = 0,
|
|
28
28
|
Information = 1,
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { PositionRange } from './PositionRange.js';
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export var LanguageError;
|
|
3
|
+
(function (LanguageError) {
|
|
4
|
+
function create(message, range, severity = 3 /* ErrorSeverity.Error */, info) {
|
|
4
5
|
const ans = { range, message, severity };
|
|
5
6
|
if (info) {
|
|
6
7
|
ans.info = info;
|
|
7
8
|
}
|
|
8
9
|
return ans;
|
|
9
|
-
}
|
|
10
|
+
}
|
|
11
|
+
LanguageError.create = create;
|
|
10
12
|
/**
|
|
11
13
|
* @returns A {@link PosRangeLanguageError}.
|
|
12
14
|
*/
|
|
13
|
-
withPosRange(error, doc) {
|
|
15
|
+
function withPosRange(error, doc) {
|
|
14
16
|
return {
|
|
15
17
|
posRange: PositionRange.from(error.range, doc),
|
|
16
18
|
message: error.message,
|
|
17
19
|
severity: error.severity,
|
|
18
20
|
...(error.info && { info: error.info }),
|
|
19
21
|
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
+
}
|
|
23
|
+
LanguageError.withPosRange = withPosRange;
|
|
24
|
+
})(LanguageError || (LanguageError = {}));
|
|
22
25
|
//# sourceMappingURL=LanguageError.js.map
|
package/lib/source/Location.d.ts
CHANGED
package/lib/source/Offset.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReadonlySource } from './Source.js';
|
|
2
|
-
export
|
|
2
|
+
export type OffsetLike = number | ReadonlySource | ((this: void) => number | ReadonlySource);
|
|
3
3
|
export declare namespace Offset {
|
|
4
4
|
/**
|
|
5
5
|
* Get an offset from a `OffsetLike`.
|
package/lib/source/Range.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OffsetLike } from './Offset.js';
|
|
2
|
-
export
|
|
2
|
+
export type RangeLike = Range | RangeContainer | OffsetLike | ((this: void) => Range | RangeContainer | OffsetLike);
|
|
3
3
|
export interface Range {
|
|
4
4
|
start: number;
|
|
5
5
|
end: number;
|
package/lib/source/Source.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { IndexMap } from './IndexMap.js';
|
|
2
2
|
import type { RangeContainer } from './Range.js';
|
|
3
3
|
import { Range } from './Range.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
5
|
+
type Space = ' ' | '\t';
|
|
6
|
+
type Newline = '\r\n' | '\r' | '\n';
|
|
7
|
+
type Whitespace = Space | Newline;
|
|
8
8
|
export declare const CRLF = "\r\n";
|
|
9
9
|
export declare const CR = "\r";
|
|
10
10
|
export declare const LF = "\n";
|
|
@@ -62,7 +62,7 @@ export declare class Source extends ReadonlySource {
|
|
|
62
62
|
read(): string;
|
|
63
63
|
/**
|
|
64
64
|
* Skips the current character.
|
|
65
|
-
* @param step The step to skip.
|
|
65
|
+
* @param step The step to skip. Defaults to 1
|
|
66
66
|
*/
|
|
67
67
|
skip(step?: number): this;
|
|
68
68
|
/**
|
|
@@ -110,11 +110,13 @@ export declare class Source extends ReadonlySource {
|
|
|
110
110
|
skipUntilLineEnd(): this;
|
|
111
111
|
readRemaining(): string;
|
|
112
112
|
skipRemaining(): this;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
}
|
|
114
|
+
export declare namespace Source {
|
|
115
|
+
function isDigit(c: string): c is Digit;
|
|
116
|
+
function isBrigadierQuote(c: string): c is '"' | "'";
|
|
117
|
+
function isNewline(c: string): c is Newline;
|
|
118
|
+
function isSpace(c: string): c is Space;
|
|
119
|
+
function isWhitespace(c: string): c is Whitespace;
|
|
118
120
|
}
|
|
119
121
|
export {};
|
|
120
122
|
//# sourceMappingURL=Source.d.ts.map
|
package/lib/source/Source.js
CHANGED
|
@@ -79,10 +79,10 @@ export class ReadonlySource {
|
|
|
79
79
|
hasNonSpaceAheadInLine() {
|
|
80
80
|
for (let cursor = this.innerCursor; cursor < this.string.length; cursor++) {
|
|
81
81
|
const c = this.string.charAt(cursor);
|
|
82
|
-
if (c
|
|
82
|
+
if (Source.isNewline(c)) {
|
|
83
83
|
break;
|
|
84
84
|
}
|
|
85
|
-
if (!(c
|
|
85
|
+
if (!Source.isSpace(c)) {
|
|
86
86
|
return true;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -134,7 +134,7 @@ export class Source extends ReadonlySource {
|
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* Skips the current character.
|
|
137
|
-
* @param step The step to skip.
|
|
137
|
+
* @param step The step to skip. Defaults to 1
|
|
138
138
|
*/
|
|
139
139
|
skip(step = 1) {
|
|
140
140
|
this.innerCursor += step;
|
|
@@ -266,20 +266,27 @@ export class Source extends ReadonlySource {
|
|
|
266
266
|
this.readRemaining();
|
|
267
267
|
return this;
|
|
268
268
|
}
|
|
269
|
-
|
|
269
|
+
}
|
|
270
|
+
(function (Source) {
|
|
271
|
+
function isDigit(c) {
|
|
270
272
|
return c >= '0' && c <= '9';
|
|
271
273
|
}
|
|
272
|
-
|
|
274
|
+
Source.isDigit = isDigit;
|
|
275
|
+
function isBrigadierQuote(c) {
|
|
273
276
|
return c === '"' || c === "'";
|
|
274
277
|
}
|
|
275
|
-
|
|
278
|
+
Source.isBrigadierQuote = isBrigadierQuote;
|
|
279
|
+
function isNewline(c) {
|
|
276
280
|
return c === '\r\n' || c === '\r' || c === '\n';
|
|
277
281
|
}
|
|
278
|
-
|
|
282
|
+
Source.isNewline = isNewline;
|
|
283
|
+
function isSpace(c) {
|
|
279
284
|
return c === ' ' || c === '\t';
|
|
280
285
|
}
|
|
281
|
-
|
|
286
|
+
Source.isSpace = isSpace;
|
|
287
|
+
function isWhitespace(c) {
|
|
282
288
|
return Source.isSpace(c) || Source.isNewline(c);
|
|
283
289
|
}
|
|
284
|
-
|
|
290
|
+
Source.isWhitespace = isWhitespace;
|
|
291
|
+
})(Source || (Source = {}));
|
|
285
292
|
//# sourceMappingURL=Source.js.map
|