@spyglassmc/core 0.1.1 → 0.3.0

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 (206) hide show
  1. package/README.md +7 -0
  2. package/lib/browser.d.ts +2 -0
  3. package/lib/browser.js +2 -0
  4. package/lib/common/Dev.d.ts +11 -0
  5. package/lib/common/Dev.js +90 -0
  6. package/lib/{service → common}/Logger.d.ts +0 -0
  7. package/lib/{service → common}/Logger.js +2 -5
  8. package/lib/common/Operations.d.ts +12 -0
  9. package/lib/common/Operations.js +33 -0
  10. package/lib/common/ReadonlyProxy.d.ts +9 -0
  11. package/lib/common/ReadonlyProxy.js +23 -0
  12. package/lib/common/StateProxy.d.ts +35 -0
  13. package/lib/common/StateProxy.js +69 -0
  14. package/lib/common/TwoWayMap.d.ts +21 -0
  15. package/lib/common/TwoWayMap.js +69 -0
  16. package/lib/common/externals/BrowserExternals.d.ts +3 -0
  17. package/lib/common/externals/BrowserExternals.js +191 -0
  18. package/lib/common/externals/NodeJsExternals.d.ts +3 -0
  19. package/lib/common/externals/NodeJsExternals.js +152 -0
  20. package/lib/common/externals/downloader.d.ts +31 -0
  21. package/lib/common/externals/downloader.js +32 -0
  22. package/lib/common/externals/index.d.ts +96 -0
  23. package/lib/common/externals/index.js +2 -0
  24. package/lib/common/index.d.ts +8 -1
  25. package/lib/common/index.js +8 -13
  26. package/lib/common/util.d.ts +50 -39
  27. package/lib/common/util.js +73 -122
  28. package/lib/index.d.ts +7 -7
  29. package/lib/index.js +7 -19
  30. package/lib/node/AstNode.d.ts +12 -11
  31. package/lib/node/AstNode.js +10 -16
  32. package/lib/node/BooleanNode.d.ts +2 -2
  33. package/lib/node/BooleanNode.js +4 -7
  34. package/lib/node/CommentNode.d.ts +6 -5
  35. package/lib/node/CommentNode.js +4 -9
  36. package/lib/node/ErrorNode.d.ts +1 -1
  37. package/lib/node/ErrorNode.js +2 -5
  38. package/lib/node/FileNode.d.ts +8 -4
  39. package/lib/node/FileNode.js +3 -6
  40. package/lib/node/FloatNode.d.ts +3 -3
  41. package/lib/node/FloatNode.js +4 -7
  42. package/lib/node/IntegerNode.d.ts +3 -3
  43. package/lib/node/IntegerNode.js +4 -7
  44. package/lib/node/ListNode.d.ts +2 -2
  45. package/lib/node/ListNode.js +2 -5
  46. package/lib/node/LiteralNode.d.ts +5 -5
  47. package/lib/node/LiteralNode.js +5 -8
  48. package/lib/node/LongNode.d.ts +3 -3
  49. package/lib/node/LongNode.js +4 -7
  50. package/lib/node/RecordNode.d.ts +2 -2
  51. package/lib/node/RecordNode.js +2 -5
  52. package/lib/node/ResourceLocationNode.d.ts +8 -10
  53. package/lib/node/ResourceLocationNode.js +9 -12
  54. package/lib/node/Sequence.d.ts +4 -3
  55. package/lib/node/Sequence.js +4 -6
  56. package/lib/node/StringNode.d.ts +5 -5
  57. package/lib/node/StringNode.js +9 -12
  58. package/lib/node/SymbolNode.d.ts +5 -5
  59. package/lib/node/SymbolNode.js +5 -8
  60. package/lib/node/index.d.ts +15 -15
  61. package/lib/node/index.js +15 -27
  62. package/lib/nodejs.d.ts +2 -0
  63. package/lib/nodejs.js +2 -0
  64. package/lib/parser/Parser.d.ts +3 -3
  65. package/lib/parser/Parser.js +1 -4
  66. package/lib/parser/boolean.d.ts +2 -2
  67. package/lib/parser/boolean.js +3 -6
  68. package/lib/parser/comment.d.ts +2 -2
  69. package/lib/parser/comment.js +5 -9
  70. package/lib/parser/empty.d.ts +1 -1
  71. package/lib/parser/empty.js +1 -5
  72. package/lib/parser/error.d.ts +2 -2
  73. package/lib/parser/error.js +5 -9
  74. package/lib/parser/file.d.ts +3 -3
  75. package/lib/parser/file.js +9 -13
  76. package/lib/parser/float.d.ts +4 -4
  77. package/lib/parser/float.js +12 -16
  78. package/lib/parser/index.d.ts +16 -16
  79. package/lib/parser/index.js +16 -34
  80. package/lib/parser/integer.d.ts +4 -4
  81. package/lib/parser/integer.js +10 -14
  82. package/lib/parser/list.d.ts +2 -2
  83. package/lib/parser/list.js +15 -19
  84. package/lib/parser/literal.d.ts +2 -2
  85. package/lib/parser/literal.js +5 -9
  86. package/lib/parser/long.d.ts +4 -4
  87. package/lib/parser/long.js +10 -14
  88. package/lib/parser/record.d.ts +3 -3
  89. package/lib/parser/record.js +20 -24
  90. package/lib/parser/resourceLocation.d.ts +2 -2
  91. package/lib/parser/resourceLocation.js +12 -24
  92. package/lib/parser/string.d.ts +7 -7
  93. package/lib/parser/string.js +40 -44
  94. package/lib/parser/symbol.d.ts +3 -3
  95. package/lib/parser/symbol.js +4 -14
  96. package/lib/parser/util.d.ts +30 -12
  97. package/lib/parser/util.js +78 -65
  98. package/lib/processor/ColorInfoProvider.d.ts +1 -1
  99. package/lib/processor/ColorInfoProvider.js +6 -9
  100. package/lib/processor/InlayHintProvider.d.ts +4 -3
  101. package/lib/processor/InlayHintProvider.js +1 -2
  102. package/lib/processor/SignatureHelpProvider.d.ts +4 -3
  103. package/lib/processor/SignatureHelpProvider.js +1 -2
  104. package/lib/processor/binder/Binder.d.ts +26 -0
  105. package/lib/processor/binder/Binder.js +18 -0
  106. package/lib/processor/binder/builtin.d.ts +27 -0
  107. package/lib/processor/binder/builtin.js +116 -0
  108. package/lib/processor/binder/index.d.ts +3 -0
  109. package/lib/processor/binder/index.js +3 -0
  110. package/lib/processor/checker/Checker.d.ts +2 -2
  111. package/lib/processor/checker/Checker.js +1 -5
  112. package/lib/processor/checker/builtin.d.ts +4 -4
  113. package/lib/processor/checker/builtin.js +22 -33
  114. package/lib/processor/checker/index.d.ts +2 -2
  115. package/lib/processor/checker/index.js +2 -27
  116. package/lib/processor/colorizer/Colorizer.d.ts +6 -5
  117. package/lib/processor/colorizer/Colorizer.js +8 -11
  118. package/lib/processor/colorizer/builtin.d.ts +3 -3
  119. package/lib/processor/colorizer/builtin.js +33 -46
  120. package/lib/processor/colorizer/index.d.ts +2 -2
  121. package/lib/processor/colorizer/index.js +2 -27
  122. package/lib/processor/completer/Completer.d.ts +6 -5
  123. package/lib/processor/completer/Completer.js +14 -33
  124. package/lib/processor/completer/builtin.d.ts +10 -9
  125. package/lib/processor/completer/builtin.js +59 -75
  126. package/lib/processor/completer/index.d.ts +2 -2
  127. package/lib/processor/completer/index.js +2 -27
  128. package/lib/processor/formatter/Formatter.d.ts +4 -3
  129. package/lib/processor/formatter/Formatter.js +2 -7
  130. package/lib/processor/formatter/builtin.d.ts +3 -3
  131. package/lib/processor/formatter/builtin.js +22 -36
  132. package/lib/processor/formatter/index.d.ts +2 -2
  133. package/lib/processor/formatter/index.js +2 -27
  134. package/lib/processor/index.d.ts +10 -9
  135. package/lib/processor/index.js +10 -21
  136. package/lib/processor/linter/Linter.d.ts +4 -3
  137. package/lib/processor/linter/Linter.js +1 -2
  138. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
  139. package/lib/processor/linter/builtin/undeclaredSymbol.js +23 -27
  140. package/lib/processor/linter/builtin.d.ts +4 -3
  141. package/lib/processor/linter/builtin.js +19 -26
  142. package/lib/processor/linter/index.d.ts +2 -2
  143. package/lib/processor/linter/index.js +2 -27
  144. package/lib/processor/util.d.ts +4 -14
  145. package/lib/processor/util.js +1 -16
  146. package/lib/service/CacheService.d.ts +8 -6
  147. package/lib/service/CacheService.js +35 -56
  148. package/lib/service/Config.d.ts +17 -16
  149. package/lib/service/Config.js +56 -51
  150. package/lib/service/Context.d.ts +24 -21
  151. package/lib/service/Context.js +40 -36
  152. package/lib/service/Dependency.js +2 -5
  153. package/lib/service/Downloader.d.ts +9 -39
  154. package/lib/service/Downloader.js +37 -106
  155. package/lib/service/ErrorReporter.d.ts +2 -2
  156. package/lib/service/ErrorReporter.js +11 -15
  157. package/lib/service/FileService.d.ts +40 -14
  158. package/lib/service/FileService.js +107 -81
  159. package/lib/service/Hover.d.ts +2 -2
  160. package/lib/service/Hover.js +4 -7
  161. package/lib/service/MetaRegistry.d.ts +17 -12
  162. package/lib/service/MetaRegistry.js +81 -73
  163. package/lib/service/Profiler.d.ts +3 -2
  164. package/lib/service/Profiler.js +81 -45
  165. package/lib/service/Project.d.ts +101 -73
  166. package/lib/service/Project.js +438 -367
  167. package/lib/service/Service.d.ts +19 -29
  168. package/lib/service/Service.js +57 -53
  169. package/lib/service/SymbolLocations.d.ts +3 -3
  170. package/lib/service/SymbolLocations.js +4 -7
  171. package/lib/service/SymbolRegistrar.d.ts +1 -1
  172. package/lib/service/SymbolRegistrar.js +1 -2
  173. package/lib/service/UriProcessor.d.ts +5 -0
  174. package/lib/service/UriProcessor.js +2 -0
  175. package/lib/service/fileUtil.d.ts +21 -41
  176. package/lib/service/fileUtil.js +59 -129
  177. package/lib/service/index.d.ts +16 -17
  178. package/lib/service/index.js +16 -31
  179. package/lib/source/IndexMap.d.ts +1 -1
  180. package/lib/source/IndexMap.js +7 -10
  181. package/lib/source/LanguageError.d.ts +2 -2
  182. package/lib/source/LanguageError.js +3 -6
  183. package/lib/source/Location.d.ts +3 -3
  184. package/lib/source/Location.js +6 -9
  185. package/lib/source/Offset.d.ts +1 -1
  186. package/lib/source/Offset.js +4 -7
  187. package/lib/source/Position.js +2 -5
  188. package/lib/source/PositionRange.d.ts +2 -2
  189. package/lib/source/PositionRange.js +14 -17
  190. package/lib/source/Range.d.ts +1 -1
  191. package/lib/source/Range.js +7 -10
  192. package/lib/source/Source.d.ts +9 -4
  193. package/lib/source/Source.js +58 -31
  194. package/lib/source/index.d.ts +8 -8
  195. package/lib/source/index.js +8 -20
  196. package/lib/symbol/Symbol.d.ts +15 -14
  197. package/lib/symbol/Symbol.js +53 -68
  198. package/lib/symbol/SymbolUtil.d.ts +30 -39
  199. package/lib/symbol/SymbolUtil.js +189 -168
  200. package/lib/symbol/index.d.ts +2 -3
  201. package/lib/symbol/index.js +2 -15
  202. package/package.json +7 -4
  203. package/lib/service/Operations.d.ts +0 -8
  204. package/lib/service/Operations.js +0 -26
  205. package/lib/symbol/UriBinder.d.ts +0 -3
  206. package/lib/symbol/UriBinder.js +0 -3
@@ -1,6 +1,6 @@
1
- import { IndexMap } from '.';
2
- import type { RangeContainer } from './Range';
3
- import { Range } from './Range';
1
+ import { IndexMap } from './IndexMap.js';
2
+ import type { RangeContainer } from './Range.js';
3
+ import { Range } from './Range.js';
4
4
  declare type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
5
5
  declare type Space = ' ' | '\t';
6
6
  declare type Newline = '\r\n' | '\r' | '\n';
@@ -35,9 +35,12 @@ export declare class ReadonlySource {
35
35
  /**
36
36
  * If the `expectedValue` is right after the cursor, returns `true`. Otherwise returns `false`.
37
37
  *
38
+ * @param offset Defaults to 0.
39
+ *
38
40
  * @see {@link Source.trySkip}
39
41
  */
40
- tryPeek(expectedValue: string): boolean;
42
+ tryPeek(expectedValue: string, offset?: number): boolean;
43
+ tryPeekAfterWhitespace(expectedValue: string): boolean;
41
44
  peekUntil(...terminators: string[]): string;
42
45
  peekLine(): string;
43
46
  hasNonSpaceAheadInLine(): boolean;
@@ -91,6 +94,8 @@ export declare class Source extends ReadonlySource {
91
94
  skipSpace(): this;
92
95
  readWhitespace(): string;
93
96
  skipWhitespace(): this;
97
+ readIf(predicate: (this: void, char: string) => boolean): string;
98
+ skipIf(predicate: (this: void, char: string) => boolean): this;
94
99
  /**
95
100
  * @param terminators Ending character. Will not be skipped or included in the result.
96
101
  */
@@ -1,20 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Source = exports.ReadonlySource = exports.Whitespaces = exports.LF = exports.CR = exports.CRLF = void 0;
4
- const _1 = require(".");
5
- const Range_1 = require("./Range");
6
- exports.CRLF = '\r\n';
7
- exports.CR = '\r';
8
- exports.LF = '\n';
9
- exports.Whitespaces = Object.freeze([' ', '\n', '\r', '\t']);
10
- class ReadonlySource {
1
+ import { IndexMap } from './IndexMap.js';
2
+ import { Range } from './Range.js';
3
+ export const CRLF = '\r\n';
4
+ export const CR = '\r';
5
+ export const LF = '\n';
6
+ export const Whitespaces = Object.freeze([' ', '\n', '\r', '\t']);
7
+ export class ReadonlySource {
8
+ string;
9
+ indexMap;
10
+ innerCursor = 0;
11
11
  constructor(string, indexMap = []) {
12
12
  this.string = string;
13
13
  this.indexMap = indexMap;
14
- this.innerCursor = 0;
15
14
  }
16
15
  get cursor() {
17
- return _1.IndexMap.toOuterOffset(this.indexMap, this.innerCursor);
16
+ return IndexMap.toOuterOffset(this.indexMap, this.innerCursor);
18
17
  }
19
18
  /**
20
19
  * @param offset The index to offset from cursor. Defaults to 0.
@@ -27,7 +26,7 @@ class ReadonlySource {
27
26
  * getCharRange(1) // Returns the range of the character after cursor.
28
27
  */
29
28
  getCharRange(offset = 0) {
30
- return _1.IndexMap.toOuterRange(this.indexMap, Range_1.Range.create(this.innerCursor + offset, this.innerCursor + offset + 1));
29
+ return IndexMap.toOuterRange(this.indexMap, Range.create(this.innerCursor + offset, this.innerCursor + offset + 1));
31
30
  }
32
31
  /**
33
32
  * Peeks a substring from the current cursor.
@@ -40,10 +39,20 @@ class ReadonlySource {
40
39
  /**
41
40
  * If the `expectedValue` is right after the cursor, returns `true`. Otherwise returns `false`.
42
41
  *
42
+ * @param offset Defaults to 0.
43
+ *
43
44
  * @see {@link Source.trySkip}
44
45
  */
45
- tryPeek(expectedValue) {
46
- return this.peek(expectedValue.length) === expectedValue;
46
+ tryPeek(expectedValue, offset = 0) {
47
+ return this.peek(expectedValue.length, offset) === expectedValue;
48
+ }
49
+ tryPeekAfterWhitespace(expectedValue) {
50
+ const maxOffset = this.string.length - this.innerCursor;
51
+ let offset = 0;
52
+ while (offset < maxOffset && Source.isWhitespace(this.peek(1, offset))) {
53
+ offset++;
54
+ }
55
+ return this.tryPeek(expectedValue, offset);
47
56
  }
48
57
  peekUntil(...terminators) {
49
58
  let ans = '';
@@ -59,12 +68,12 @@ class ReadonlySource {
59
68
  return ans;
60
69
  }
61
70
  peekLine() {
62
- return this.peekUntil(exports.CR, exports.LF);
71
+ return this.peekUntil(CR, LF);
63
72
  }
64
73
  hasNonSpaceAheadInLine() {
65
74
  for (let cursor = this.innerCursor; cursor < this.string.length; cursor++) {
66
75
  const c = this.string.charAt(cursor);
67
- if (c === exports.CR || c === exports.LF) {
76
+ if (c === CR || c === LF) {
68
77
  break;
69
78
  }
70
79
  if (!(c === ' ' || c === '\t')) {
@@ -75,20 +84,21 @@ class ReadonlySource {
75
84
  }
76
85
  slice(param0, end) {
77
86
  if (typeof param0 === 'number') {
78
- const innerStart = _1.IndexMap.toInnerOffset(this.indexMap, param0);
79
- const innerEnd = end !== undefined ? _1.IndexMap.toInnerOffset(this.indexMap, end) : undefined;
87
+ const innerStart = IndexMap.toInnerOffset(this.indexMap, param0);
88
+ const innerEnd = end !== undefined ? IndexMap.toInnerOffset(this.indexMap, end) : undefined;
80
89
  return this.string.slice(innerStart, innerEnd);
81
90
  }
82
- const range = _1.IndexMap.toInnerRange(this.indexMap, Range_1.Range.get(param0));
91
+ const range = IndexMap.toInnerRange(this.indexMap, Range.get(param0));
83
92
  return this.string.slice(range.start, range.end);
84
93
  }
85
94
  sliceToCursor(start) {
86
- const innerStart = _1.IndexMap.toInnerOffset(this.indexMap, start);
95
+ const innerStart = IndexMap.toInnerOffset(this.indexMap, start);
87
96
  return this.string.slice(innerStart, this.innerCursor);
88
97
  }
89
98
  }
90
- exports.ReadonlySource = ReadonlySource;
91
- class Source extends ReadonlySource {
99
+ export class Source extends ReadonlySource {
100
+ string;
101
+ indexMap;
92
102
  constructor(string, indexMap = []) {
93
103
  super(string, indexMap);
94
104
  this.string = string;
@@ -98,7 +108,7 @@ class Source extends ReadonlySource {
98
108
  return super.cursor;
99
109
  }
100
110
  set cursor(cursor) {
101
- this.innerCursor = _1.IndexMap.toInnerOffset(this.indexMap, cursor);
111
+ this.innerCursor = IndexMap.toInnerOffset(this.indexMap, cursor);
102
112
  }
103
113
  clone() {
104
114
  const ans = new Source(this.string, this.indexMap);
@@ -109,7 +119,7 @@ class Source extends ReadonlySource {
109
119
  return this.innerCursor + length <= this.string.length;
110
120
  }
111
121
  canReadInLine() {
112
- return this.canRead() && this.peek() !== exports.CR && this.peek() !== exports.LF;
122
+ return this.canRead() && this.peek() !== CR && this.peek() !== LF;
113
123
  }
114
124
  read() {
115
125
  return this.string.charAt(this.innerCursor++);
@@ -147,7 +157,7 @@ class Source extends ReadonlySource {
147
157
  * Reads until the end of this line.
148
158
  */
149
159
  readLine() {
150
- return this.readUntil(exports.CR, exports.LF);
160
+ return this.readUntil(CR, LF);
151
161
  }
152
162
  /**
153
163
  * Skips until the end of this line.
@@ -161,10 +171,10 @@ class Source extends ReadonlySource {
161
171
  */
162
172
  nextLine() {
163
173
  this.skipLine();
164
- if (this.peek(2) === exports.CRLF) {
174
+ if (this.peek(2) === CRLF) {
165
175
  this.skip(2);
166
176
  }
167
- else if (this.peek() === exports.CR || this.peek() === exports.LF) {
177
+ else if (this.peek() === CR || this.peek() === LF) {
168
178
  this.skip();
169
179
  }
170
180
  return this;
@@ -191,6 +201,24 @@ class Source extends ReadonlySource {
191
201
  }
192
202
  return this;
193
203
  }
204
+ readIf(predicate) {
205
+ let ans = '';
206
+ while (this.canRead()) {
207
+ const c = this.peek();
208
+ if (predicate(c)) {
209
+ this.skip();
210
+ ans += c;
211
+ }
212
+ else {
213
+ break;
214
+ }
215
+ }
216
+ return ans;
217
+ }
218
+ skipIf(predicate) {
219
+ this.readIf(predicate);
220
+ return this;
221
+ }
194
222
  /**
195
223
  * @param terminators Ending character. Will not be skipped or included in the result.
196
224
  */
@@ -216,10 +244,10 @@ class Source extends ReadonlySource {
216
244
  return this;
217
245
  }
218
246
  readUntilLineEnd() {
219
- return this.readUntil(exports.CR, exports.LF);
247
+ return this.readUntil(CR, LF);
220
248
  }
221
249
  skipUntilLineEnd() {
222
- return this.skipUntilOrEnd(exports.CR, exports.LF);
250
+ return this.skipUntilOrEnd(CR, LF);
223
251
  }
224
252
  readRemaining() {
225
253
  const start = this.innerCursor;
@@ -246,5 +274,4 @@ class Source extends ReadonlySource {
246
274
  return Source.isSpace(c) || Source.isNewline(c);
247
275
  }
248
276
  }
249
- exports.Source = Source;
250
277
  //# sourceMappingURL=Source.js.map
@@ -1,9 +1,9 @@
1
- export * from './IndexMap';
2
- export * from './LanguageError';
3
- export * from './Location';
4
- export * from './Offset';
5
- export * from './Position';
6
- export * from './PositionRange';
7
- export * from './Range';
8
- export * from './Source';
1
+ export * from './IndexMap.js';
2
+ export * from './LanguageError.js';
3
+ export * from './Location.js';
4
+ export * from './Offset.js';
5
+ export * from './Position.js';
6
+ export * from './PositionRange.js';
7
+ export * from './Range.js';
8
+ export * from './Source.js';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1,21 +1,9 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./IndexMap"), exports);
14
- __exportStar(require("./LanguageError"), exports);
15
- __exportStar(require("./Location"), exports);
16
- __exportStar(require("./Offset"), exports);
17
- __exportStar(require("./Position"), exports);
18
- __exportStar(require("./PositionRange"), exports);
19
- __exportStar(require("./Range"), exports);
20
- __exportStar(require("./Source"), exports);
1
+ export * from './IndexMap.js';
2
+ export * from './LanguageError.js';
3
+ export * from './Location.js';
4
+ export * from './Offset.js';
5
+ export * from './Position.js';
6
+ export * from './PositionRange.js';
7
+ export * from './Range.js';
8
+ export * from './Source.js';
21
9
  //# sourceMappingURL=index.js.map