@spyglassmc/core 0.1.0 → 0.2.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 (196) 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/TwoWayMap.d.ts +21 -0
  5. package/lib/common/TwoWayMap.js +69 -0
  6. package/lib/common/externals/BrowserExternals.d.ts +3 -0
  7. package/lib/common/externals/BrowserExternals.js +191 -0
  8. package/lib/common/externals/NodeJsExternals.d.ts +3 -0
  9. package/lib/common/externals/NodeJsExternals.js +151 -0
  10. package/lib/common/externals/downloader.d.ts +31 -0
  11. package/lib/common/externals/downloader.js +32 -0
  12. package/lib/common/externals/index.d.ts +96 -0
  13. package/lib/common/externals/index.js +2 -0
  14. package/lib/common/index.d.ts +2 -1
  15. package/lib/common/index.js +2 -13
  16. package/lib/common/util.d.ts +17 -34
  17. package/lib/common/util.js +32 -113
  18. package/lib/index.d.ts +7 -7
  19. package/lib/index.js +7 -19
  20. package/lib/node/AstNode.d.ts +3 -3
  21. package/lib/node/AstNode.js +10 -16
  22. package/lib/node/BooleanNode.d.ts +2 -2
  23. package/lib/node/BooleanNode.js +4 -7
  24. package/lib/node/CommentNode.d.ts +1 -1
  25. package/lib/node/CommentNode.js +2 -5
  26. package/lib/node/ErrorNode.d.ts +1 -1
  27. package/lib/node/ErrorNode.js +2 -5
  28. package/lib/node/FileNode.d.ts +3 -3
  29. package/lib/node/FileNode.js +2 -5
  30. package/lib/node/FloatNode.d.ts +2 -2
  31. package/lib/node/FloatNode.js +4 -7
  32. package/lib/node/IntegerNode.d.ts +2 -2
  33. package/lib/node/IntegerNode.js +4 -7
  34. package/lib/node/ListNode.d.ts +2 -2
  35. package/lib/node/ListNode.js +2 -5
  36. package/lib/node/LiteralNode.d.ts +4 -4
  37. package/lib/node/LiteralNode.js +5 -8
  38. package/lib/node/LongNode.d.ts +2 -2
  39. package/lib/node/LongNode.js +4 -7
  40. package/lib/node/RecordNode.d.ts +2 -2
  41. package/lib/node/RecordNode.js +2 -5
  42. package/lib/node/ResourceLocationNode.d.ts +6 -8
  43. package/lib/node/ResourceLocationNode.js +9 -12
  44. package/lib/node/Sequence.d.ts +4 -3
  45. package/lib/node/Sequence.js +4 -6
  46. package/lib/node/StringNode.d.ts +5 -5
  47. package/lib/node/StringNode.js +9 -12
  48. package/lib/node/SymbolNode.d.ts +4 -4
  49. package/lib/node/SymbolNode.js +5 -8
  50. package/lib/node/index.d.ts +15 -15
  51. package/lib/node/index.js +15 -27
  52. package/lib/nodejs.d.ts +2 -0
  53. package/lib/nodejs.js +2 -0
  54. package/lib/parser/Parser.d.ts +3 -3
  55. package/lib/parser/Parser.js +1 -4
  56. package/lib/parser/boolean.d.ts +2 -2
  57. package/lib/parser/boolean.js +3 -6
  58. package/lib/parser/comment.d.ts +2 -2
  59. package/lib/parser/comment.js +5 -9
  60. package/lib/parser/empty.d.ts +1 -1
  61. package/lib/parser/empty.js +1 -5
  62. package/lib/parser/error.d.ts +2 -2
  63. package/lib/parser/error.js +5 -9
  64. package/lib/parser/file.d.ts +3 -3
  65. package/lib/parser/file.js +9 -13
  66. package/lib/parser/float.d.ts +4 -4
  67. package/lib/parser/float.js +12 -16
  68. package/lib/parser/index.d.ts +16 -16
  69. package/lib/parser/index.js +16 -34
  70. package/lib/parser/integer.d.ts +4 -4
  71. package/lib/parser/integer.js +10 -14
  72. package/lib/parser/list.d.ts +2 -2
  73. package/lib/parser/list.js +15 -19
  74. package/lib/parser/literal.d.ts +2 -2
  75. package/lib/parser/literal.js +5 -9
  76. package/lib/parser/long.d.ts +4 -4
  77. package/lib/parser/long.js +10 -14
  78. package/lib/parser/record.d.ts +3 -3
  79. package/lib/parser/record.js +20 -24
  80. package/lib/parser/resourceLocation.d.ts +2 -2
  81. package/lib/parser/resourceLocation.js +14 -18
  82. package/lib/parser/string.d.ts +7 -7
  83. package/lib/parser/string.js +40 -44
  84. package/lib/parser/symbol.d.ts +3 -3
  85. package/lib/parser/symbol.js +3 -7
  86. package/lib/parser/util.d.ts +30 -12
  87. package/lib/parser/util.js +78 -63
  88. package/lib/processor/ColorInfoProvider.d.ts +1 -1
  89. package/lib/processor/ColorInfoProvider.js +6 -9
  90. package/lib/processor/InlayHintProvider.d.ts +2 -2
  91. package/lib/processor/InlayHintProvider.js +1 -2
  92. package/lib/processor/SignatureHelpProvider.d.ts +2 -2
  93. package/lib/processor/SignatureHelpProvider.js +1 -2
  94. package/lib/processor/checker/Checker.d.ts +2 -2
  95. package/lib/processor/checker/Checker.js +1 -5
  96. package/lib/processor/checker/builtin.d.ts +5 -4
  97. package/lib/processor/checker/builtin.js +26 -28
  98. package/lib/processor/checker/index.d.ts +2 -2
  99. package/lib/processor/checker/index.js +2 -27
  100. package/lib/processor/colorizer/Colorizer.d.ts +4 -4
  101. package/lib/processor/colorizer/Colorizer.js +8 -11
  102. package/lib/processor/colorizer/builtin.d.ts +3 -3
  103. package/lib/processor/colorizer/builtin.js +33 -46
  104. package/lib/processor/colorizer/index.d.ts +2 -2
  105. package/lib/processor/colorizer/index.js +2 -27
  106. package/lib/processor/completer/Completer.d.ts +4 -4
  107. package/lib/processor/completer/Completer.js +14 -33
  108. package/lib/processor/completer/builtin.d.ts +7 -7
  109. package/lib/processor/completer/builtin.js +58 -74
  110. package/lib/processor/completer/index.d.ts +2 -2
  111. package/lib/processor/completer/index.js +2 -27
  112. package/lib/processor/formatter/Formatter.d.ts +2 -2
  113. package/lib/processor/formatter/Formatter.js +2 -7
  114. package/lib/processor/formatter/builtin.d.ts +3 -3
  115. package/lib/processor/formatter/builtin.js +22 -36
  116. package/lib/processor/formatter/index.d.ts +2 -2
  117. package/lib/processor/formatter/index.js +2 -27
  118. package/lib/processor/index.d.ts +9 -9
  119. package/lib/processor/index.js +9 -21
  120. package/lib/processor/linter/Linter.d.ts +2 -2
  121. package/lib/processor/linter/Linter.js +1 -2
  122. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
  123. package/lib/processor/linter/builtin/undeclaredSymbol.js +23 -27
  124. package/lib/processor/linter/builtin.d.ts +3 -3
  125. package/lib/processor/linter/builtin.js +19 -31
  126. package/lib/processor/linter/index.d.ts +2 -2
  127. package/lib/processor/linter/index.js +2 -27
  128. package/lib/processor/util.d.ts +2 -2
  129. package/lib/processor/util.js +4 -9
  130. package/lib/service/CacheService.d.ts +6 -6
  131. package/lib/service/CacheService.js +38 -48
  132. package/lib/service/Config.d.ts +17 -16
  133. package/lib/service/Config.js +56 -51
  134. package/lib/service/Context.d.ts +14 -14
  135. package/lib/service/Context.js +30 -32
  136. package/lib/service/Dependency.js +2 -5
  137. package/lib/service/Downloader.d.ts +10 -39
  138. package/lib/service/Downloader.js +37 -106
  139. package/lib/service/ErrorReporter.d.ts +2 -2
  140. package/lib/service/ErrorReporter.js +11 -15
  141. package/lib/service/FileService.d.ts +41 -14
  142. package/lib/service/FileService.js +107 -81
  143. package/lib/service/Hover.d.ts +2 -2
  144. package/lib/service/Hover.js +4 -7
  145. package/lib/service/Logger.js +2 -5
  146. package/lib/service/MetaRegistry.d.ts +12 -12
  147. package/lib/service/MetaRegistry.js +62 -73
  148. package/lib/service/Operations.js +3 -9
  149. package/lib/service/Profiler.d.ts +1 -1
  150. package/lib/service/Profiler.js +25 -41
  151. package/lib/service/Project.d.ts +50 -51
  152. package/lib/service/Project.js +240 -238
  153. package/lib/service/Service.d.ts +19 -29
  154. package/lib/service/Service.js +57 -53
  155. package/lib/service/SymbolLocations.d.ts +3 -3
  156. package/lib/service/SymbolLocations.js +4 -7
  157. package/lib/service/SymbolRegistrar.d.ts +1 -1
  158. package/lib/service/SymbolRegistrar.js +1 -2
  159. package/lib/service/fileUtil.d.ts +21 -41
  160. package/lib/service/fileUtil.js +59 -129
  161. package/lib/service/index.d.ts +17 -17
  162. package/lib/service/index.js +17 -31
  163. package/lib/source/IndexMap.d.ts +1 -1
  164. package/lib/source/IndexMap.js +7 -10
  165. package/lib/source/LanguageError.d.ts +2 -2
  166. package/lib/source/LanguageError.js +3 -6
  167. package/lib/source/Location.d.ts +3 -3
  168. package/lib/source/Location.js +6 -9
  169. package/lib/source/Offset.d.ts +1 -1
  170. package/lib/source/Offset.js +4 -7
  171. package/lib/source/Position.js +2 -5
  172. package/lib/source/PositionRange.d.ts +2 -2
  173. package/lib/source/PositionRange.js +14 -17
  174. package/lib/source/Range.d.ts +1 -1
  175. package/lib/source/Range.js +7 -10
  176. package/lib/source/Source.d.ts +12 -4
  177. package/lib/source/Source.js +84 -29
  178. package/lib/source/index.d.ts +8 -8
  179. package/lib/source/index.js +8 -20
  180. package/lib/symbol/Symbol.d.ts +15 -15
  181. package/lib/symbol/Symbol.js +53 -68
  182. package/lib/symbol/SymbolUtil.d.ts +23 -33
  183. package/lib/symbol/SymbolUtil.js +162 -163
  184. package/lib/symbol/UriBinder.d.ts +1 -1
  185. package/lib/symbol/UriBinder.js +1 -2
  186. package/lib/symbol/index.d.ts +3 -3
  187. package/lib/symbol/index.js +3 -15
  188. package/package.json +7 -4
  189. package/lib/common/Heap.d.ts +0 -1
  190. package/lib/common/Heap.js +0 -2
  191. package/lib/node/TableNode.d.ts +0 -17
  192. package/lib/node/TableNode.js +0 -11
  193. package/lib/parser/table.d.ts +0 -22
  194. package/lib/parser/table.js +0 -97
  195. package/lib/service/CommandExecutor.d.ts +0 -3
  196. package/lib/service/CommandExecutor.js +0 -7
@@ -1,44 +1,35 @@
1
- /// <reference types="node" />
2
- import EventEmitter from 'events';
3
1
  import type { TextDocument } from 'vscode-languageserver-textdocument';
4
- import type { FileNode } from '../node';
5
- import { AstNode } from '../node';
6
- import type { Color, ColorInfo, ColorToken, InlayHint, SignatureHelp } from '../processor';
7
- import { ColorPresentation } from '../processor';
8
- import { Range } from '../source';
9
- import type { SymbolUsageType } from '../symbol';
10
- import { Downloader } from './Downloader';
11
- import { FileService } from './FileService';
12
- import { Hover } from './Hover';
13
- import { Logger } from './Logger';
14
- import { ProfilerFactory } from './Profiler';
15
- import type { ProjectInitializer } from './Project';
16
- import { Project } from './Project';
17
- import { SymbolLocations } from './SymbolLocations';
2
+ import type { FileNode } from '../node/index.js';
3
+ import { AstNode } from '../node/index.js';
4
+ import type { Color, ColorInfo, ColorToken, InlayHint, SignatureHelp } from '../processor/index.js';
5
+ import { ColorPresentation } from '../processor/index.js';
6
+ import { Range } from '../source/index.js';
7
+ import type { SymbolUsageType } from '../symbol/index.js';
8
+ import { Hover } from './Hover.js';
9
+ import type { Logger } from './Logger.js';
10
+ import { ProfilerFactory } from './Profiler.js';
11
+ import type { ProjectOptions } from './Project.js';
12
+ import { Project } from './Project.js';
13
+ import { SymbolLocations } from './SymbolLocations.js';
18
14
  interface Options {
19
- cacheRoot: string;
20
- downloader?: Downloader;
21
- fs?: FileService;
22
- initializers?: readonly ProjectInitializer[];
23
15
  isDebugging?: boolean;
24
- logger?: Logger;
16
+ logger: Logger;
25
17
  profilers?: ProfilerFactory;
26
- projectPath: string;
18
+ project: ProjectOptions;
27
19
  }
28
- export declare class Service extends EventEmitter {
29
- readonly downloader: Downloader;
30
- readonly fs: FileService;
20
+ export declare class Service {
31
21
  readonly isDebugging: boolean;
32
22
  readonly logger: Logger;
33
23
  readonly profilers: ProfilerFactory;
34
24
  readonly project: Project;
35
- constructor({ cacheRoot, downloader, fs, initializers, isDebugging, logger, profilers, projectPath, }: Options);
25
+ constructor({ isDebugging, logger, profilers, project, }: Options);
36
26
  private debug;
37
27
  colorize(node: FileNode<AstNode>, doc: TextDocument, range?: Range): readonly ColorToken[];
38
28
  getColorInfo(node: FileNode<AstNode>, doc: TextDocument): ColorInfo[];
39
29
  getColorPresentation(file: FileNode<AstNode>, doc: TextDocument, range: Range, color: Color): ColorPresentation[];
40
- complete(node: FileNode<AstNode>, doc: TextDocument, offset: number, triggerCharacter?: string): import("../processor").CompletionItem[];
30
+ complete(node: FileNode<AstNode>, doc: TextDocument, offset: number, triggerCharacter?: string): import("../processor/index.js").CompletionItem[];
41
31
  dataHackPubify(initialism: string): string;
32
+ format(node: FileNode<AstNode>, doc: TextDocument, tabSize: number, insertSpaces: boolean): string;
42
33
  getHover(file: FileNode<AstNode>, doc: TextDocument, offset: number): Hover | undefined;
43
34
  getInlayHints(node: FileNode<AstNode>, doc: TextDocument, range?: Range): InlayHint[];
44
35
  getSignatureHelp(node: FileNode<AstNode>, doc: TextDocument, offset: number): SignatureHelp | undefined;
@@ -48,8 +39,7 @@ export declare class Service extends EventEmitter {
48
39
  *
49
40
  * @returns Symbol locations of the selected symbol at `offset`, or `undefined` if there's no symbol at `offset`.
50
41
  */
51
- getSymbolLocations(file: FileNode<AstNode>, doc: TextDocument, offset: number, searchedUsages?: readonly SymbolUsageType[], currentFileOnly?: boolean): SymbolLocations | undefined;
52
- format(node: FileNode<AstNode>, doc: TextDocument, tabSize: number, insertSpaces: boolean): string;
42
+ getSymbolLocations(file: FileNode<AstNode>, doc: TextDocument, offset: number, searchedUsages?: readonly SymbolUsageType[], currentFileOnly?: boolean): Promise<SymbolLocations | undefined>;
53
43
  }
54
44
  export {};
55
45
  //# sourceMappingURL=Service.d.ts.map
@@ -1,32 +1,28 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Service = void 0;
7
- const events_1 = __importDefault(require("events"));
8
- const node_1 = require("../node");
9
- const processor_1 = require("../processor");
10
- const source_1 = require("../source");
11
- const symbol_1 = require("../symbol");
12
- const Context_1 = require("./Context");
13
- const Downloader_1 = require("./Downloader");
14
- const FileService_1 = require("./FileService");
15
- const Hover_1 = require("./Hover");
16
- const Logger_1 = require("./Logger");
17
- const Profiler_1 = require("./Profiler");
18
- const Project_1 = require("./Project");
19
- const SymbolLocations_1 = require("./SymbolLocations");
1
+ import { AstNode } from '../node/index.js';
2
+ import { ColorPresentation, completer, traversePreOrder } from '../processor/index.js';
3
+ import { Range } from '../source/index.js';
4
+ import { SymbolUsageTypes } from '../symbol/index.js';
5
+ import { ColorizerContext, CompleterContext, FormatterContext, ProcessorContext, SignatureHelpProviderContext } from './Context.js';
6
+ import { fileUtil } from './fileUtil.js';
7
+ import { Hover } from './Hover.js';
8
+ import { ProfilerFactory } from './Profiler.js';
9
+ import { Project } from './Project.js';
10
+ import { SymbolLocations } from './SymbolLocations.js';
20
11
  /* istanbul ignore next */
21
- class Service extends events_1.default {
22
- constructor({ cacheRoot, downloader, fs = FileService_1.FileService.create(), initializers = [], isDebugging = false, logger = Logger_1.Logger.create(), profilers = Profiler_1.ProfilerFactory.noop(), projectPath, }) {
23
- super();
24
- this.downloader = (downloader ?? (downloader = new Downloader_1.Downloader(cacheRoot, logger)));
25
- this.fs = fs;
12
+ export class Service {
13
+ isDebugging;
14
+ logger;
15
+ profilers;
16
+ project;
17
+ constructor({ isDebugging = false, logger, profilers = ProfilerFactory.noop(), project, }) {
26
18
  this.isDebugging = isDebugging;
27
19
  this.logger = logger;
28
20
  this.profilers = profilers;
29
- this.project = new Project_1.Project({ cacheRoot, downloader, fs, initializers, logger, profilers, projectPath });
21
+ this.project = new Project({
22
+ logger,
23
+ profilers,
24
+ ...project,
25
+ });
30
26
  }
31
27
  debug(message) {
32
28
  if (this.isDebugging) {
@@ -37,7 +33,7 @@ class Service extends events_1.default {
37
33
  try {
38
34
  this.debug(`Colorizing '${doc.uri}' # ${doc.version}`);
39
35
  const colorizer = this.project.meta.getColorizer(node.type);
40
- return colorizer(node, Context_1.ColorizerContext.create(this.project, { doc, range }));
36
+ return colorizer(node, ColorizerContext.create(this.project, { doc, range }));
41
37
  }
42
38
  catch (e) {
43
39
  this.logger.error(`[Service] [colorize] Failed for “${doc.uri}” #${doc.version}`, e);
@@ -48,7 +44,7 @@ class Service extends events_1.default {
48
44
  try {
49
45
  this.debug(`Getting color info for '${doc.uri}' # ${doc.version}`);
50
46
  const ans = [];
51
- (0, processor_1.traversePreOrder)(node, _ => true, node => node.color, node => ans.push({
47
+ traversePreOrder(node, _ => true, node => node.color, node => ans.push({
52
48
  color: Array.isArray(node.color) ? node.color : node.color.value,
53
49
  range: Array.isArray(node.color) ? node.range : (node.color.range ?? node.range),
54
50
  }));
@@ -61,13 +57,13 @@ class Service extends events_1.default {
61
57
  }
62
58
  getColorPresentation(file, doc, range, color) {
63
59
  try {
64
- this.debug(`Getting color presentation for '${doc.uri}' # ${doc.version} @ ${source_1.Range.toString(range)}`);
65
- let node = node_1.AstNode.findDeepestChild({ node: file, needle: range.start });
60
+ this.debug(`Getting color presentation for '${doc.uri}' # ${doc.version} @ ${Range.toString(range)}`);
61
+ let node = AstNode.findDeepestChild({ node: file, needle: range.start });
66
62
  while (node) {
67
63
  const nodeColor = node.color;
68
64
  if (nodeColor && !Array.isArray(nodeColor)) {
69
65
  const colorRange = nodeColor.range ?? node.range;
70
- return nodeColor.format.map(format => processor_1.ColorPresentation.fromColorFormat(format, color, colorRange));
66
+ return nodeColor.format.map(format => ColorPresentation.fromColorFormat(format, color, colorRange));
71
67
  }
72
68
  node = node.parent;
73
69
  }
@@ -82,7 +78,7 @@ class Service extends events_1.default {
82
78
  this.debug(`Getting completion for '${doc.uri}' # ${doc.version} @ ${offset}`);
83
79
  const shouldComplete = this.project.meta.shouldComplete(doc.languageId, triggerCharacter);
84
80
  if (shouldComplete) {
85
- return processor_1.completer.file(node, Context_1.CompleterContext.create(this.project, { doc, offset, triggerCharacter }));
81
+ return completer.file(node, CompleterContext.create(this.project, { doc, offset, triggerCharacter }));
86
82
  }
87
83
  }
88
84
  catch (e) {
@@ -107,18 +103,29 @@ class Service extends events_1.default {
107
103
  .map((c, i) => `${c.toUpperCase()}${secrets[i % secrets.length]}`)
108
104
  .join(' ');
109
105
  }
106
+ format(node, doc, tabSize, insertSpaces) {
107
+ try {
108
+ this.debug(`Formatting '${doc.uri}' # ${doc.version}`);
109
+ const formatter = this.project.meta.getFormatter(node.type);
110
+ return formatter(node, FormatterContext.create(this.project, { doc, tabSize, insertSpaces }));
111
+ }
112
+ catch (e) {
113
+ this.logger.error(`[Service] [format] Failed for “${doc.uri}” #${doc.version}`, e);
114
+ throw e;
115
+ }
116
+ }
110
117
  getHover(file, doc, offset) {
111
118
  try {
112
119
  this.debug(`Getting hover for '${doc.uri}' # ${doc.version} @ ${offset}`);
113
- let node = node_1.AstNode.findDeepestChild({ node: file, needle: offset });
120
+ let node = AstNode.findDeepestChild({ node: file, needle: offset });
114
121
  while (node) {
115
122
  const symbol = this.project.symbols.resolveAlias(node.symbol);
116
123
  if (symbol) {
117
124
  const hover = `\`\`\`typescript\n(${symbol.category}${symbol.subcategory ? `/${symbol.subcategory}` : ''}) ${symbol.identifier}\n\`\`\`` + (symbol.desc ? `\n******\n${symbol.desc}` : '');
118
- return Hover_1.Hover.create(node.range, hover);
125
+ return Hover.create(node.range, hover);
119
126
  }
120
127
  if (node.hover) {
121
- return Hover_1.Hover.create(node.range, node.hover);
128
+ return Hover.create(node.range, node.hover);
122
129
  }
123
130
  node = node.parent;
124
131
  }
@@ -133,7 +140,7 @@ class Service extends events_1.default {
133
140
  // TODO: `range` argument is not used.
134
141
  this.debug(`Getting inlay hints for '${doc.uri}' # ${doc.version}`);
135
142
  const ans = [];
136
- const ctx = Context_1.ProcessorContext.create(this.project, { doc });
143
+ const ctx = ProcessorContext.create(this.project, { doc });
137
144
  for (const provider of this.project.meta.inlayHintProviders) {
138
145
  ans.push(...provider(node, ctx));
139
146
  }
@@ -147,7 +154,7 @@ class Service extends events_1.default {
147
154
  getSignatureHelp(node, doc, offset) {
148
155
  try {
149
156
  this.debug(`Getting signature help for '${doc.uri}' # ${doc.version} @ ${offset}`);
150
- const ctx = Context_1.SignatureHelpProviderContext.create(this.project, { doc, offset });
157
+ const ctx = SignatureHelpProviderContext.create(this.project, { doc, offset });
151
158
  for (const provider of this.project.meta.signatureHelpProviders) {
152
159
  const result = provider(node, ctx);
153
160
  if (result) {
@@ -166,22 +173,31 @@ class Service extends events_1.default {
166
173
  *
167
174
  * @returns Symbol locations of the selected symbol at `offset`, or `undefined` if there's no symbol at `offset`.
168
175
  */
169
- getSymbolLocations(file, doc, offset, searchedUsages = symbol_1.SymbolUsageTypes, currentFileOnly = false) {
176
+ async getSymbolLocations(file, doc, offset, searchedUsages = SymbolUsageTypes, currentFileOnly = false) {
170
177
  try {
171
178
  this.debug(`Getting symbol locations of usage '${searchedUsages.join(',')}' for '${doc.uri}' # ${doc.version} @ ${offset} with currentFileOnly=${currentFileOnly}`);
172
- let node = node_1.AstNode.findDeepestChild({ node: file, needle: offset });
179
+ let node = AstNode.findDeepestChild({ node: file, needle: offset });
173
180
  while (node) {
174
181
  const symbol = this.project.symbols.resolveAlias(node.symbol);
175
182
  if (symbol) {
176
- const locations = [];
183
+ const rawLocations = [];
177
184
  for (const usage of searchedUsages) {
178
185
  let locs = symbol[usage] ?? [];
179
186
  if (currentFileOnly) {
180
187
  locs = locs.filter(l => l.uri === doc.uri);
181
188
  }
182
- locations.push(...locs);
189
+ rawLocations.push(...locs);
190
+ }
191
+ const locations = [];
192
+ for (const loc of rawLocations) {
193
+ const mappedUri = fileUtil.isFileUri(loc.uri)
194
+ ? loc.uri
195
+ : await this.project.fs.mapToDisk(loc.uri);
196
+ if (mappedUri) {
197
+ locations.push({ ...loc, uri: mappedUri });
198
+ }
183
199
  }
184
- return SymbolLocations_1.SymbolLocations.create(node.range, locations.length ? locations : undefined);
200
+ return SymbolLocations.create(node.range, locations.length ? locations : undefined);
185
201
  }
186
202
  node = node.parent;
187
203
  }
@@ -191,17 +207,5 @@ class Service extends events_1.default {
191
207
  }
192
208
  return undefined;
193
209
  }
194
- format(node, doc, tabSize, insertSpaces) {
195
- try {
196
- this.debug(`Formatting '${doc.uri}' # ${doc.version}`);
197
- const formatter = this.project.meta.getFormatter(node.type);
198
- return formatter(node, Context_1.FormatterContext.create(this.project, { doc, tabSize, insertSpaces }));
199
- }
200
- catch (e) {
201
- this.logger.error(`[Service] [format] Failed for “${doc.uri}” #${doc.version}`, e);
202
- throw e;
203
- }
204
- }
205
210
  }
206
- exports.Service = Service;
207
211
  //# sourceMappingURL=Service.js.map
@@ -1,6 +1,6 @@
1
- import type { RangeLike } from '../source';
2
- import { Range } from '../source';
3
- import type { SymbolLocation } from '../symbol';
1
+ import type { RangeLike } from '../source/index.js';
2
+ import { Range } from '../source/index.js';
3
+ import type { SymbolLocation } from '../symbol/index.js';
4
4
  export interface SymbolLocations {
5
5
  /**
6
6
  * The range of the currently selected symbol.
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SymbolLocations = void 0;
4
- const source_1 = require("../source");
5
- var SymbolLocations;
1
+ import { Range } from '../source/index.js';
2
+ export var SymbolLocations;
6
3
  (function (SymbolLocations) {
7
4
  /* istanbul ignore next */
8
5
  function create(range, locations) {
9
6
  return {
10
- range: source_1.Range.get(range),
7
+ range: Range.get(range),
11
8
  locations,
12
9
  };
13
10
  }
14
11
  SymbolLocations.create = create;
15
- })(SymbolLocations = exports.SymbolLocations || (exports.SymbolLocations = {}));
12
+ })(SymbolLocations || (SymbolLocations = {}));
16
13
  //# sourceMappingURL=SymbolLocations.js.map
@@ -1,4 +1,4 @@
1
- import type { SymbolUtil } from '../symbol';
1
+ import type { SymbolUtil } from '../symbol/index.js';
2
2
  export declare type SymbolRegistrar = (this: void, symbols: SymbolUtil, ctx: SymbolRegistrarContext) => void;
3
3
  export interface SymbolRegistrarContext {
4
4
  }
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=SymbolRegistrar.js.map
@@ -1,12 +1,6 @@
1
- /// <reference types="node" />
2
- import type fs from 'fs';
3
- import { URL as Uri } from 'url';
1
+ import type { Externals, FsLocation } from '../common/index.js';
4
2
  export declare type RootUriString = `${string}/`;
5
3
  export declare type FileExtension = `.${string}`;
6
- /**
7
- * A string file path, string file URI, or a file URI object.
8
- */
9
- export declare type PathLike = string | Uri;
10
4
  export declare namespace fileUtil {
11
5
  /**
12
6
  * @param rootUris The root URIs. Each URI in this array must end with a slash (`/`).
@@ -42,24 +36,16 @@ export declare namespace fileUtil {
42
36
  */
43
37
  function extname(value: string): FileExtension | undefined;
44
38
  /**
45
- * @param fileUri A file URI.
46
- * @returns The corresponding file path of the `fileUri` in platform-specific format.
47
- * @throws If the URI is not a file schema URI.
39
+ * @returns The part from the last `/` to the end of the URI.
48
40
  */
49
- function fileUriToPath(fileUri: string): string;
50
- /**
51
- * @param path A file path.
52
- * @returns The corresponding file URI of the `path`.
53
- */
54
- function pathToFileUri(path: string): string;
55
- function normalize(uri: string): string;
56
- function getParentOfFile(path: PathLike): PathLike;
41
+ function basename(uri: string): string;
42
+ function getParentOfFile(externals: Externals, path: FsLocation): FsLocation;
57
43
  /**
58
44
  * @throws
59
45
  *
60
46
  * @param mode Default to `0o777` (`rwxrwxrwx`)
61
47
  */
62
- function ensureDir(path: PathLike, mode?: fs.Mode): Promise<void>;
48
+ function ensureDir(externals: Externals, path: FsLocation, mode?: number): Promise<void>;
63
49
  /**
64
50
  * @throws
65
51
  *
@@ -67,55 +53,49 @@ export declare namespace fileUtil {
67
53
  *
68
54
  * @param mode Default to `0o777` (`rwxrwxrwx`)
69
55
  */
70
- function ensureParentOfFile(path: PathLike, mode?: fs.Mode): Promise<void>;
71
- function readFile(path: PathLike): Promise<Buffer>;
56
+ function ensureParentOfFile(externals: Externals, path: FsLocation, mode?: number): Promise<void>;
57
+ function chmod(externals: Externals, path: FsLocation, mode: number): Promise<void>;
58
+ function ensureWritable(externals: Externals, path: FsLocation): Promise<void>;
59
+ function markReadOnly(externals: Externals, path: FsLocation): Promise<void>;
60
+ function readFile(externals: Externals, path: FsLocation): Promise<Uint8Array>;
72
61
  /**
73
62
  * @throws
74
63
  *
75
- * The directory of the file will be created recursively if it doesn'texist.
64
+ * The directory of the file will be created recursively if it doesn't exist.
65
+ *
66
+ * The target file will be given permission `0o666` (`rw-rw-rw-`) before being written into, and changed back to the
67
+ * specified `mode`.
76
68
  *
77
69
  * * Encoding: `utf-8`
78
70
  * * Mode: `0o666` (`rw-rw-rw-`)
79
71
  * * Flag: `w`
80
72
  */
81
- function writeFile(path: PathLike, data: Buffer | string): Promise<void>;
73
+ function writeFile(externals: Externals, path: FsLocation, data: Uint8Array | string, mode?: number): Promise<void>;
82
74
  /**
83
75
  * @throws
84
76
  */
85
- function readJson<T = any>(path: PathLike): Promise<T>;
77
+ function readJson(externals: Externals, path: FsLocation): Promise<unknown>;
86
78
  /**
87
79
  * @throws
88
80
  *
89
81
  * @see {@link writeFile}
90
82
  */
91
- function writeJson(path: PathLike, data: any): Promise<void>;
83
+ function writeJson(externals: Externals, path: FsLocation, data: any): Promise<void>;
92
84
  /**
93
85
  * @throws
94
86
  */
95
- function readGzippedFile(path: PathLike): Promise<Buffer>;
87
+ function readGzippedFile(externals: Externals, path: FsLocation): Promise<Uint8Array>;
96
88
  /**
97
89
  * @throws
98
90
  */
99
- function writeGzippedFile(path: PathLike, buffer: Buffer | string): Promise<void>;
91
+ function writeGzippedFile(externals: Externals, path: FsLocation, buffer: Uint8Array | string): Promise<void>;
100
92
  /**
101
93
  * @throws
102
94
  */
103
- function readGzippedJson<T = any>(path: PathLike): Promise<T>;
95
+ function readGzippedJson(externals: Externals, path: FsLocation): Promise<unknown>;
104
96
  /**
105
97
  * @throws
106
98
  */
107
- function writeGzippedJson(path: PathLike, data: any): Promise<void>;
108
- /**
109
- * Show the file/directory in the platform-specific explorer program.
110
- *
111
- * Should not be called with unsanitized user-input path due to the possibility of
112
- * arbitrary code execution.
113
- *
114
- * @returns The `stdout` from the spawned child process.
115
- */
116
- function showFile(path: string): Promise<{
117
- stdout: string;
118
- stderr: string;
119
- }>;
99
+ function writeGzippedJson(externals: Externals, path: FsLocation, data: any): Promise<void>;
120
100
  }
121
101
  //# sourceMappingURL=fileUtil.d.ts.map