@spyglassmc/core 0.4.40 → 0.4.41

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/README.md CHANGED
@@ -12,6 +12,4 @@ This package is the core of the Spyglass Project. It defines the structure of a
12
12
  ## Exports
13
13
 
14
14
  * `@spyglassmc/core`: Contains all core functionalities.
15
- * `@spyglassmc/core/lib/browser.js`: Contains browser-specific features.
16
- * `@spyglassmc/core/lib/nodejs.js`: Contains Node.js-specific features.
17
- * `@spyglassmc/core/test-out/utils.js`: For internal development use only. Does not exist in the package published to npm.
15
+ * `@spyglassmc/core/test/utils.ts`: For internal development use only. Does not exist in the package published to npm.
@@ -1,8 +1,8 @@
1
1
  import { localize } from '@spyglassmc/locales';
2
- import { Range, Source } from '../source/index.js';
2
+ import { ErrorSeverity, Range, Source } from '../source/index.js';
3
3
  import { Failure } from './Parser.js';
4
4
  const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
5
- ctx.err.report(localize('expected', localize('float.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
5
+ ctx.err.report(localize('expected', localize('float.between', options.min ?? '-∞', options.max ?? '+∞')), ans, ErrorSeverity.Error);
6
6
  };
7
7
  export function float(options) {
8
8
  return (src, ctx) => {
@@ -1,8 +1,8 @@
1
1
  import { localize } from '@spyglassmc/locales';
2
- import { Range, Source } from '../source/index.js';
2
+ import { ErrorSeverity, Range, Source } from '../source/index.js';
3
3
  import { Failure } from './Parser.js';
4
4
  const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
5
- ctx.err.report(localize('expected', localize('integer.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
5
+ ctx.err.report(localize('expected', localize('integer.between', options.min ?? '-∞', options.max ?? '+∞')), ans, ErrorSeverity.Error);
6
6
  };
7
7
  export function integer(options) {
8
8
  return (src, ctx) => {
@@ -1,5 +1,5 @@
1
1
  import { localeQuote, localize } from '@spyglassmc/locales';
2
- import { Range } from '../source/index.js';
2
+ import { ErrorSeverity, Range } from '../source/index.js';
3
3
  import { Failure } from './Parser.js';
4
4
  import { attempt } from './util.js';
5
5
  export function list({ start, value, sep, trailingSep, end }) {
@@ -46,7 +46,7 @@ export function list({ start, value, sep, trailingSep, end }) {
46
46
  // Trailing item sep.
47
47
  if (hasValueSep && !trailingSep) {
48
48
  const trailingRange = ans.children[ans.children.length - 1].sep;
49
- ctx.err.report(localize('parser.list.trailing-sep'), trailingRange, 3 /* ErrorSeverity.Error */, {
49
+ ctx.err.report(localize('parser.list.trailing-sep'), trailingRange, ErrorSeverity.Error, {
50
50
  codeAction: {
51
51
  title: localize('code-action.remove-trailing-separation'),
52
52
  isPreferred: true,
@@ -1,8 +1,8 @@
1
1
  import { localize } from '@spyglassmc/locales';
2
- import { Range, Source } from '../source/index.js';
2
+ import { ErrorSeverity, Range, Source } from '../source/index.js';
3
3
  import { Failure } from './Parser.js';
4
4
  const fallbackOnOutOfRange = (ans, _src, ctx, options) => {
5
- ctx.err.report(localize('expected', localize('long.between', options.min ?? '-∞', options.max ?? '+∞')), ans, 3 /* ErrorSeverity.Error */);
5
+ ctx.err.report(localize('expected', localize('long.between', options.min ?? '-∞', options.max ?? '+∞')), ans, ErrorSeverity.Error);
6
6
  };
7
7
  export function long(options) {
8
8
  return (src, ctx) => {
@@ -1,5 +1,5 @@
1
1
  import { localeQuote, localize } from '@spyglassmc/locales';
2
- import { Range } from '../source/index.js';
2
+ import { ErrorSeverity, Range } from '../source/index.js';
3
3
  import { Failure } from './Parser.js';
4
4
  import { attempt } from './util.js';
5
5
  /**
@@ -82,7 +82,7 @@ export function record({ start, pair, end }) {
82
82
  // Trailing pair end.
83
83
  if (hasPairEnd && !pair.trailingEnd) {
84
84
  const trailingRange = ans.children[ans.children.length - 1].end;
85
- ctx.err.report(localize('parser.record.trailing-end'), trailingRange, 3 /* ErrorSeverity.Error */, {
85
+ ctx.err.report(localize('parser.record.trailing-end'), trailingRange, ErrorSeverity.Error, {
86
86
  codeAction: {
87
87
  title: localize('code-action.remove-trailing-separation'),
88
88
  isPreferred: true,
@@ -1,6 +1,6 @@
1
1
  import { arrayToMessage, localize } from '@spyglassmc/locales';
2
2
  import { ResourceLocation } from '../common/index.js';
3
- import { Range } from '../source/index.js';
3
+ import { ErrorSeverity, Range } from '../source/index.js';
4
4
  const Terminators = new Set([
5
5
  ' ',
6
6
  '\r',
@@ -104,7 +104,7 @@ export function resourceLocation(options) {
104
104
  ctx.err.report(localize('parser.resource-location.tag-required'), ans);
105
105
  }
106
106
  if (!ans.namespace && options.requireCanonical) {
107
- ctx.err.report(localize('parser.resource-location.namespace-expected'), ans, 3 /* ErrorSeverity.Error */, {
107
+ ctx.err.report(localize('parser.resource-location.namespace-expected'), ans, ErrorSeverity.Error, {
108
108
  codeAction: {
109
109
  title: localize('code-action.add-default-namespace'),
110
110
  isPreferred: true,
@@ -2,6 +2,7 @@ import { localize } from '@spyglassmc/locales';
2
2
  import { ResourceLocation, StateProxy } from '../../common/index.js';
3
3
  import { ResourceLocationNode } from '../../node/index.js';
4
4
  import { ErrorReporter } from '../../service/index.js';
5
+ import { ErrorSeverity } from '../../source/index.js';
5
6
  import { traversePreOrder } from '../util.js';
6
7
  import { AsyncBinder, SyncBinder } from './Binder.js';
7
8
  export function attempt(binder, node, ctx) {
@@ -107,7 +108,7 @@ export const resourceLocation = SyncBinder.create((node, ctx) => {
107
108
  }
108
109
  if (node.options.pool && !node.options.allowUnknown) {
109
110
  if (!node.options.pool.includes(sanitizedRaw)) {
110
- ctx.err.report(localize('expected', node.options.pool), node, 3 /* ErrorSeverity.Error */);
111
+ ctx.err.report(localize('expected', node.options.pool), node, ErrorSeverity.Error);
111
112
  }
112
113
  return;
113
114
  }
@@ -54,7 +54,7 @@ export class CacheService {
54
54
  }
55
55
  catch (e) {
56
56
  if (!this.project.externals.error.isKind(e, 'EISDIR')) {
57
- this.project.logger.error(`[CacheService#hash-root] ${root}`);
57
+ this.project.logger.error(`[CacheService#hash-root] ${root}`, e);
58
58
  }
59
59
  }
60
60
  }
@@ -264,7 +264,7 @@ export declare class ConfigService implements ExternalEventEmitter {
264
264
  emit(event: 'changed', data: ConfigEvent): boolean;
265
265
  emit(event: 'error', data: ErrorEvent): boolean;
266
266
  load(): Promise<Config>;
267
- private static isConfigFile;
267
+ static isConfigFile(this: void, uri: string): boolean;
268
268
  static merge(base: Config, ...overrides: any[]): Config;
269
269
  }
270
270
  export {};
@@ -1,5 +1,6 @@
1
1
  import rfdc from 'rfdc';
2
2
  import { Arrayable, bufferToString, merge, TypePredicates } from '../common/index.js';
3
+ import { ErrorSeverity } from '../source/index.js';
3
4
  import { DataFileCategories, RegistryCategories } from '../symbol/index.js';
4
5
  export var LinterSeverity;
5
6
  (function (LinterSeverity) {
@@ -13,13 +14,13 @@ export var LinterSeverity;
13
14
  function toErrorSeverity(value) {
14
15
  switch (value) {
15
16
  case 'error':
16
- return 3 /* ErrorSeverity.Error */;
17
+ return ErrorSeverity.Error;
17
18
  case 'hint':
18
- return 0 /* ErrorSeverity.Hint */;
19
+ return ErrorSeverity.Hint;
19
20
  case 'information':
20
- return 1 /* ErrorSeverity.Information */;
21
+ return ErrorSeverity.Information;
21
22
  case 'warning':
22
- return 2 /* ErrorSeverity.Warning */;
23
+ return ErrorSeverity.Warning;
23
24
  }
24
25
  }
25
26
  LinterSeverity.toErrorSeverity = toErrorSeverity;
@@ -36,7 +37,7 @@ export var LinterConfigValue;
36
37
  if (Array.isArray(value) && LinterSeverity.is(value[0])) {
37
38
  return { ruleSeverity: LinterSeverity.toErrorSeverity(value[0]), ruleValue: value[1] };
38
39
  }
39
- return { ruleSeverity: 2 /* ErrorSeverity.Warning */, ruleValue: value };
40
+ return { ruleSeverity: ErrorSeverity.Warning, ruleValue: value };
40
41
  }
41
42
  LinterConfigValue.destruct = destruct;
42
43
  })(LinterConfigValue || (LinterConfigValue = {}));
@@ -1,5 +1,5 @@
1
1
  import { localize } from '@spyglassmc/locales';
2
- import { LanguageError, Range } from '../source/index.js';
2
+ import { ErrorSeverity, LanguageError, Range } from '../source/index.js';
3
3
  export class ErrorReporter {
4
4
  source;
5
5
  errors = [];
@@ -9,7 +9,7 @@ export class ErrorReporter {
9
9
  /**
10
10
  * Reports a new error.
11
11
  */
12
- report(message, range, severity = 3 /* ErrorSeverity.Error */, info) {
12
+ report(message, range, severity = ErrorSeverity.Error, info) {
13
13
  if (message.trim() === '') {
14
14
  throw new Error('Tried to report an error with no message');
15
15
  }
@@ -132,6 +132,7 @@ export declare class Project implements ExternalEventEmitter {
132
132
  on(event: 'ready', callbackFn: (data: EmptyEvent) => void): this;
133
133
  on(event: 'rootsUpdated', callbackFn: (data: RootsEvent) => void): this;
134
134
  on(event: 'symbolRegistrarExecuted', callbackFn: (data: SymbolRegistrarEvent) => void): this;
135
+ on(event: 'configChanged', callbackFn: (data: Config) => void): this;
135
136
  once(event: 'documentErrored', callbackFn: (data: DocumentErrorEvent) => void): this;
136
137
  once(event: 'documentUpdated', callbackFn: (data: DocumentEvent) => void): this;
137
138
  once(event: 'documentRemoved', callbackFn: (data: FileEvent) => void): this;
@@ -139,6 +140,7 @@ export declare class Project implements ExternalEventEmitter {
139
140
  once(event: 'ready', callbackFn: (data: EmptyEvent) => void): this;
140
141
  once(event: 'rootsUpdated', callbackFn: (data: RootsEvent) => void): this;
141
142
  once(event: 'symbolRegistrarExecuted', callbackFn: (data: SymbolRegistrarEvent) => void): this;
143
+ once(event: 'configChanged', callbackFn: (data: Config) => void): this;
142
144
  emit(event: 'documentErrored', data: DocumentErrorEvent): boolean;
143
145
  emit(event: 'documentUpdated', data: DocumentEvent): boolean;
144
146
  emit(event: 'documentRemoved', data: FileEvent): boolean;
@@ -146,6 +148,7 @@ export declare class Project implements ExternalEventEmitter {
146
148
  emit(event: 'ready', data: EmptyEvent): boolean;
147
149
  emit(event: 'rootsUpdated', data: RootsEvent): boolean;
148
150
  emit(event: 'symbolRegistrarExecuted', data: SymbolRegistrarEvent): boolean;
151
+ emit(event: 'configChanged', data: Config): boolean;
149
152
  /**
150
153
  * Get all files that are tracked and supported.
151
154
  *
@@ -173,6 +173,7 @@ export class Project {
173
173
  this.#configService.on('changed', ({ config }) => {
174
174
  this.config = config;
175
175
  this.logger.info('[Project] [Config] Changed');
176
+ this.emit('configChanged', config);
176
177
  }).on('error', ({ error, uri }) => this.logger.error(`[Project] [Config] Failed loading ${uri}`, error));
177
178
  this.setInitPromise();
178
179
  this.setReadyPromise();
@@ -729,7 +730,8 @@ export class Project {
729
730
  * its file extension.
730
731
  */
731
732
  shouldExclude(uri, language) {
732
- return !this.isSupportedLanguage(uri, language) || this.isUserExcluded(uri);
733
+ return (!this.isSupportedLanguage(uri, language) && !ConfigService.isConfigFile(uri))
734
+ || this.isUserExcluded(uri);
733
735
  }
734
736
  isSupportedLanguage(uri, language) {
735
737
  language ??= this.guessLanguageID(uri);
@@ -24,7 +24,7 @@ export declare namespace LanguageError {
24
24
  */
25
25
  function withPosRange(error: LanguageError, doc: TextDocument): PosRangeLanguageError;
26
26
  }
27
- export declare const enum ErrorSeverity {
27
+ export declare enum ErrorSeverity {
28
28
  Hint = 0,
29
29
  Information = 1,
30
30
  Warning = 2,
@@ -1,7 +1,7 @@
1
1
  import { PositionRange } from './PositionRange.js';
2
2
  export var LanguageError;
3
3
  (function (LanguageError) {
4
- function create(message, range, severity = 3 /* ErrorSeverity.Error */, info, source) {
4
+ function create(message, range, severity = ErrorSeverity.Error, info, source) {
5
5
  const ans = { range, message, severity };
6
6
  if (info) {
7
7
  ans.info = info;
@@ -26,4 +26,11 @@ export var LanguageError;
26
26
  }
27
27
  LanguageError.withPosRange = withPosRange;
28
28
  })(LanguageError || (LanguageError = {}));
29
+ export var ErrorSeverity;
30
+ (function (ErrorSeverity) {
31
+ ErrorSeverity[ErrorSeverity["Hint"] = 0] = "Hint";
32
+ ErrorSeverity[ErrorSeverity["Information"] = 1] = "Information";
33
+ ErrorSeverity[ErrorSeverity["Warning"] = 2] = "Warning";
34
+ ErrorSeverity[ErrorSeverity["Error"] = 3] = "Error";
35
+ })(ErrorSeverity || (ErrorSeverity = {}));
29
36
  //# sourceMappingURL=LanguageError.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/core",
3
- "version": "0.4.40",
3
+ "version": "0.4.41",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -24,7 +24,7 @@
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.20"
27
+ "@spyglassmc/locales": "0.3.21"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/decompress": "^4.2.3",