@spyglassmc/core 0.4.1 → 0.4.2

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.
Files changed (64) hide show
  1. package/lib/common/Dev.js +2 -2
  2. package/lib/common/ReadonlyProxy.d.ts +2 -2
  3. package/lib/common/StateProxy.d.ts +2 -2
  4. package/lib/common/externals/NodeJsExternals.js +4 -1
  5. package/lib/common/externals/downloader.d.ts +2 -2
  6. package/lib/common/externals/index.d.ts +2 -2
  7. package/lib/common/util.d.ts +7 -7
  8. package/lib/common/util.js +2 -2
  9. package/lib/node/AstNode.d.ts +1 -1
  10. package/lib/node/AstNode.js +3 -1
  11. package/lib/node/CommentNode.d.ts +2 -2
  12. package/lib/node/ResourceLocationNode.d.ts +1 -1
  13. package/lib/node/ResourceLocationNode.js +6 -8
  14. package/lib/node/StringNode.d.ts +3 -3
  15. package/lib/node/StringNode.js +4 -1
  16. package/lib/parser/Parser.d.ts +5 -5
  17. package/lib/parser/float.d.ts +1 -1
  18. package/lib/parser/integer.d.ts +1 -1
  19. package/lib/parser/long.d.ts +1 -1
  20. package/lib/parser/string.js +4 -1
  21. package/lib/parser/util.d.ts +7 -7
  22. package/lib/parser/util.js +7 -2
  23. package/lib/processor/ColorInfoProvider.d.ts +3 -3
  24. package/lib/processor/ColorInfoProvider.js +4 -2
  25. package/lib/processor/InlayHintProvider.d.ts +1 -1
  26. package/lib/processor/SignatureHelpProvider.d.ts +1 -1
  27. package/lib/processor/binder/Binder.d.ts +1 -1
  28. package/lib/processor/binder/builtin.d.ts +2 -2
  29. package/lib/processor/binder/builtin.js +3 -1
  30. package/lib/processor/binder/index.d.ts +1 -1
  31. package/lib/processor/binder/index.js +1 -1
  32. package/lib/processor/checker/Checker.d.ts +3 -3
  33. package/lib/processor/checker/builtin.d.ts +1 -1
  34. package/lib/processor/checker/builtin.js +2 -1
  35. package/lib/processor/colorizer/Colorizer.d.ts +3 -3
  36. package/lib/processor/completer/Completer.d.ts +1 -1
  37. package/lib/processor/completer/builtin.js +8 -4
  38. package/lib/processor/formatter/Formatter.d.ts +1 -1
  39. package/lib/processor/formatter/Formatter.js +3 -1
  40. package/lib/processor/linter/Linter.d.ts +1 -1
  41. package/lib/processor/util.d.ts +1 -1
  42. package/lib/service/CacheService.d.ts +1 -1
  43. package/lib/service/CacheService.js +2 -2
  44. package/lib/service/Config.d.ts +9 -9
  45. package/lib/service/Config.js +5 -2
  46. package/lib/service/Dependency.d.ts +3 -3
  47. package/lib/service/FileService.d.ts +1 -1
  48. package/lib/service/FileService.js +7 -3
  49. package/lib/service/Project.d.ts +5 -5
  50. package/lib/service/Project.js +9 -4
  51. package/lib/service/Service.js +12 -3
  52. package/lib/service/SymbolRegistrar.d.ts +1 -1
  53. package/lib/service/UriProcessor.d.ts +3 -3
  54. package/lib/service/fileUtil.d.ts +2 -2
  55. package/lib/source/IndexMap.d.ts +1 -1
  56. package/lib/source/Location.d.ts +1 -1
  57. package/lib/source/Offset.d.ts +1 -1
  58. package/lib/source/Range.d.ts +1 -1
  59. package/lib/source/Source.d.ts +4 -4
  60. package/lib/symbol/Symbol.d.ts +12 -12
  61. package/lib/symbol/Symbol.js +9 -7
  62. package/lib/symbol/SymbolUtil.d.ts +4 -4
  63. package/lib/symbol/SymbolUtil.js +4 -3
  64. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  import type { StateProxy } from '../../index.js';
2
2
  import type { AstNode } from '../../node/index.js';
3
3
  import type { LinterContext } from '../../service/index.js';
4
- export declare type Linter<N extends AstNode> = (node: StateProxy<N>, ctx: LinterContext) => void;
4
+ export type Linter<N extends AstNode> = (node: StateProxy<N>, ctx: LinterContext) => void;
5
5
  //# sourceMappingURL=Linter.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import type { DeepReadonly } from '../index.js';
2
2
  import type { AstNode } from '../node/index.js';
3
- declare type Callback<R> = (this: void, node: AstNode, parents: AstNode[]) => R;
3
+ type Callback<R> = (this: void, node: AstNode, parents: AstNode[]) => R;
4
4
  export declare function traversePreOrder<CN extends AstNode>(node: DeepReadonly<AstNode>, shouldContinue: Callback<unknown>, shouldCallFn: (this: void, node: AstNode, parents: AstNode[]) => node is CN, fn: (this: void, node: CN, parents: AstNode[]) => void): void;
5
5
  export declare function traversePreOrder(node: DeepReadonly<AstNode>, shouldContinue: Callback<unknown>, shouldCallFn: Callback<unknown>, fn: Callback<void>): void;
6
6
  export {};
@@ -19,7 +19,7 @@ interface Checksums {
19
19
  declare namespace Checksums {
20
20
  function create(): Checksums;
21
21
  }
22
- declare type ErrorCache = Record<string, readonly PosRangeLanguageError[]>;
22
+ type ErrorCache = Record<string, readonly PosRangeLanguageError[]>;
23
23
  interface LoadResult {
24
24
  symbols: SymbolTable;
25
25
  }
@@ -36,8 +36,8 @@ export class CacheService {
36
36
  }
37
37
  try {
38
38
  // TODO: Don't update this for every single change.
39
- this.checksums.files[doc.uri] =
40
- await this.project.externals.crypto.getSha1(doc.getText());
39
+ this.checksums.files[doc.uri] = await this.project.externals.crypto
40
+ .getSha1(doc.getText());
41
41
  }
42
42
  catch (e) {
43
43
  if (!this.project.externals.error.isKind(e, 'EISDIR')) {
@@ -13,7 +13,7 @@ export interface Config {
13
13
  */
14
14
  format: FormatterConfig;
15
15
  /**
16
- *t Linter rules.
16
+ * t Linter rules.
17
17
  */
18
18
  lint: LinterConfig;
19
19
  /**
@@ -77,19 +77,19 @@ export interface EnvConfig {
77
77
  permissionLevel: 1 | 2 | 3 | 4;
78
78
  plugins: string[];
79
79
  }
80
- export declare type LinterSeverity = 'hint' | 'information' | 'warning' | 'error';
80
+ export type LinterSeverity = 'hint' | 'information' | 'warning' | 'error';
81
81
  export declare namespace LinterSeverity {
82
82
  function is(value: unknown): value is LinterSeverity;
83
83
  function toErrorSeverity(value: LinterSeverity): ErrorSeverity;
84
84
  }
85
- declare type BracketSpacingConfig = any;
86
- declare type SepSpacingConfig = any;
87
- export declare type QuoteConfig = {
85
+ type BracketSpacingConfig = any;
86
+ type SepSpacingConfig = any;
87
+ export type QuoteConfig = {
88
88
  always?: boolean;
89
89
  avoidEscape?: boolean | null;
90
90
  type?: 'double' | 'single';
91
91
  };
92
- declare type LinterConfigValue<T> = T extends boolean ? null | T | [LinterSeverity, T] | LinterSeverity : null | T | [LinterSeverity, T];
92
+ type LinterConfigValue<T> = T extends boolean ? null | T | [LinterSeverity, T] | LinterSeverity : null | T | [LinterSeverity, T];
93
93
  export declare namespace LinterConfigValue {
94
94
  function destruct(value: LinterConfigValue<boolean | string | number | object>): {
95
95
  ruleSeverity: ErrorSeverity;
@@ -151,7 +151,7 @@ export interface LinterConfig {
151
151
  export interface SnippetsConfig {
152
152
  [label: string]: string;
153
153
  }
154
- export declare type SymbolLinterConfig = Arrayable<SymbolLinterConfig.Complex> | SymbolLinterConfig.Action;
154
+ export type SymbolLinterConfig = Arrayable<SymbolLinterConfig.Complex> | SymbolLinterConfig.Action;
155
155
  export declare namespace SymbolLinterConfig {
156
156
  function is(value: unknown): value is SymbolLinterConfig;
157
157
  interface Complex {
@@ -192,10 +192,10 @@ export declare namespace SymbolLinterConfig {
192
192
  * Config which simulates the default vanilla command system.
193
193
  */
194
194
  export declare const VanillaConfig: Config;
195
- declare type ConfigEvent = {
195
+ type ConfigEvent = {
196
196
  config: Config;
197
197
  };
198
- declare type ErrorEvent = {
198
+ type ErrorEvent = {
199
199
  error: unknown;
200
200
  uri: string;
201
201
  };
@@ -192,7 +192,9 @@ export const VanillaConfig = {
192
192
  {
193
193
  if: [
194
194
  { category: RegistryCategories, namespace: 'minecraft' },
195
- { category: [...FileCategories, 'bossbar', 'objective', 'team'] },
195
+ {
196
+ category: [...FileCategories, 'bossbar', 'objective', 'team'],
197
+ },
196
198
  ],
197
199
  then: { report: 'warning' },
198
200
  },
@@ -206,7 +208,7 @@ export const VanillaConfig = {
206
208
  summonAec: 'summon minecraft:area_effect_cloud ~ ~ ~ {Age: -2147483648, Duration: -1, WaitTime: -2147483648, Tags: ["${1:tag}"]}',
207
209
  },
208
210
  };
209
- export class ConfigService {
211
+ class ConfigService {
210
212
  project;
211
213
  defaultConfig;
212
214
  static ConfigFileNames = Object.freeze([
@@ -270,4 +272,5 @@ export class ConfigService {
270
272
  return ans;
271
273
  }
272
274
  }
275
+ export { ConfigService };
273
276
  //# sourceMappingURL=Config.js.map
@@ -1,10 +1,10 @@
1
- export declare type Dependency = {
1
+ export type Dependency = {
2
2
  uri: string;
3
3
  info?: Record<string, any>;
4
4
  };
5
- export declare type DependencyKey = `@${string}`;
5
+ export type DependencyKey = `@${string}`;
6
6
  export declare namespace DependencyKey {
7
7
  function is(value: string): value is DependencyKey;
8
8
  }
9
- export declare type DependencyProvider = () => PromiseLike<Dependency> | Dependency;
9
+ export type DependencyProvider = () => PromiseLike<Dependency> | Dependency;
10
10
  //# sourceMappingURL=Dependency.d.ts.map
@@ -22,7 +22,7 @@ export interface UriProtocolSupporter {
22
22
  */
23
23
  listRoots(): Iterable<RootUriString>;
24
24
  }
25
- declare type Protocol = `${string}:`;
25
+ type Protocol = `${string}:`;
26
26
  export interface FileService extends UriProtocolSupporter {
27
27
  /**
28
28
  * @param protocol A protocol of URI, including the colon. e.g. `file:`.
@@ -77,7 +77,8 @@ 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.getSha1(virtualUri)}/${fileUtil.basename(virtualUri)}`;
80
+ mappedUri = `${this.virtualUrisRoot}${await this.externals.crypto
81
+ .getSha1(virtualUri)}/${fileUtil.basename(virtualUri)}`;
81
82
  const buffer = await this.readFile(virtualUri);
82
83
  await fileUtil.writeFile(this.externals, mappedUri, buffer, 0o444);
83
84
  this.map.set(mappedUri, virtualUri);
@@ -147,7 +148,7 @@ export class FileUriSupporter {
147
148
  // return uri.protocol === Protocol && uri.hostname === Hostname
148
149
  // }
149
150
  // }
150
- export class ArchiveUriSupporter {
151
+ class ArchiveUriSupporter {
151
152
  externals;
152
153
  entries;
153
154
  static Protocol = 'archive:';
@@ -246,7 +247,9 @@ export class ArchiveUriSupporter {
246
247
  }
247
248
  }
248
249
  const files = await externals.archive.decompressBall(await externals.fs.readFile(uri), {
249
- stripLevel: typeof info?.startDepth === 'number' ? info.startDepth : 0,
250
+ stripLevel: typeof info?.startDepth === 'number'
251
+ ? info.startDepth
252
+ : 0,
250
253
  });
251
254
  entries.set(uri, new Map(files.map((f) => [f.path.replace(/\\/g, '/'), f])));
252
255
  }
@@ -258,6 +261,7 @@ export class ArchiveUriSupporter {
258
261
  return new ArchiveUriSupporter(externals, entries);
259
262
  }
260
263
  }
264
+ export { ArchiveUriSupporter };
261
265
  async function hashFile(externals, uri) {
262
266
  return externals.crypto.getSha1(await externals.fs.readFile(uri));
263
267
  }
@@ -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 declare type ProjectInitializerContext = Pick<Project, 'cacheRoot' | 'config' | 'downloader' | 'externals' | 'logger' | 'meta' | 'projectRoot'>;
17
- export declare type SyncProjectInitializer = (this: void, ctx: ProjectInitializerContext) => Record<string, string> | void;
18
- export declare type AsyncProjectInitializer = (this: void, ctx: ProjectInitializerContext) => PromiseLike<Record<string, string> | void>;
19
- export declare type ProjectInitializer = SyncProjectInitializer | AsyncProjectInitializer;
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 declare type ProjectData = Pick<Project, 'cacheRoot' | 'config' | 'downloader' | 'ensureBindingStarted' | 'externals' | 'fs' | 'logger' | 'meta' | 'profilers' | 'projectRoot' | 'roots' | 'symbols' | 'ctx'>;
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
  *
@@ -60,7 +60,7 @@ const CacheAutoSaveInterval = 600000; // 10 Minutes.
60
60
  *
61
61
  * After the READY process is complete, editing text documents as signaled by the client or the file watcher results in the file being re-processed.
62
62
  */
63
- export class Project {
63
+ class Project {
64
64
  static RootSuffix = '/pack.mcmeta';
65
65
  /** Prevent circular binding. */
66
66
  #bindingInProgressUris = new Set();
@@ -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 ?? new Downloader(cacheRoot, externals, logger);
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}”`);
@@ -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.cacheService.validate();
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.getLinter(ruleName);
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;
@@ -717,4 +721,5 @@ __decorate([
717
721
  __decorate([
718
722
  SingletonPromise()
719
723
  ], Project.prototype, "ensureClientManagedChecked", null);
724
+ export { Project };
720
725
  //# sourceMappingURL=Project.js.map
@@ -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) ? node.color : node.color.value,
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({ node: file, needle: range.start });
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, { doc, tabSize, insertSpaces }));
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 declare type SymbolRegistrar = (this: void, symbols: SymbolUtil, ctx: SymbolRegistrarContext) => void;
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 declare type UriBinder = (uris: readonly string[], ctx: UriBinderContext) => void;
3
- export declare type UriSorterRegistration = (this: void, a: string, b: string, next: UriSorter) => number;
4
- export declare type UriSorter = (this: void, a: string, b: string) => number;
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 declare type RootUriString = `${string}/`;
3
- export declare type FileExtension = `.${string}`;
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 (`/`).
@@ -2,7 +2,7 @@ import { Range } from './Range.js';
2
2
  /**
3
3
  * The pairs should be in ascending order.
4
4
  */
5
- export declare type IndexMap = {
5
+ export type IndexMap = {
6
6
  outer: Range;
7
7
  inner: Range;
8
8
  }[];
@@ -7,7 +7,7 @@ export interface Location {
7
7
  range: Range;
8
8
  posRange: PositionRange;
9
9
  }
10
- export declare type LocationLike = Partial<{
10
+ export type LocationLike = Partial<{
11
11
  uri: string;
12
12
  range: RangeLike;
13
13
  posRange: PositionRange;
@@ -1,5 +1,5 @@
1
1
  import { ReadonlySource } from './Source.js';
2
- export declare type OffsetLike = number | ReadonlySource | ((this: void) => number | ReadonlySource);
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`.
@@ -1,5 +1,5 @@
1
1
  import type { OffsetLike } from './Offset.js';
2
- export declare type RangeLike = Range | RangeContainer | OffsetLike | ((this: void) => Range | RangeContainer | OffsetLike);
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;
@@ -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
- declare type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
5
- declare type Space = ' ' | '\t';
6
- declare type Newline = '\r\n' | '\r' | '\n';
7
- declare type Whitespace = Space | Newline;
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";