@spyglassmc/core 0.1.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.
- package/README.md +10 -0
- package/lib/common/Heap.d.ts +1 -0
- package/lib/common/Heap.js +2 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +14 -0
- package/lib/common/util.d.ts +120 -0
- package/lib/common/util.js +292 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +20 -0
- package/lib/node/AstNode.d.ts +64 -0
- package/lib/node/AstNode.js +108 -0
- package/lib/node/BooleanNode.d.ts +13 -0
- package/lib/node/BooleanNode.js +20 -0
- package/lib/node/CommentNode.d.ts +12 -0
- package/lib/node/CommentNode.js +11 -0
- package/lib/node/ErrorNode.d.ts +8 -0
- package/lib/node/ErrorNode.js +12 -0
- package/lib/node/FileNode.d.ts +21 -0
- package/lib/node/FileNode.js +11 -0
- package/lib/node/FloatNode.d.ts +13 -0
- package/lib/node/FloatNode.js +21 -0
- package/lib/node/IntegerNode.d.ts +13 -0
- package/lib/node/IntegerNode.js +20 -0
- package/lib/node/ListNode.d.ts +15 -0
- package/lib/node/ListNode.js +11 -0
- package/lib/node/LiteralNode.d.ts +19 -0
- package/lib/node/LiteralNode.js +22 -0
- package/lib/node/LongNode.d.ts +13 -0
- package/lib/node/LongNode.js +20 -0
- package/lib/node/RecordNode.d.ts +20 -0
- package/lib/node/RecordNode.js +11 -0
- package/lib/node/ResourceLocationNode.d.ts +41 -0
- package/lib/node/ResourceLocationNode.js +65 -0
- package/lib/node/Sequence.d.ts +22 -0
- package/lib/node/Sequence.js +11 -0
- package/lib/node/StringNode.d.ts +63 -0
- package/lib/node/StringNode.js +43 -0
- package/lib/node/SymbolNode.d.ts +21 -0
- package/lib/node/SymbolNode.js +22 -0
- package/lib/node/TableNode.d.ts +17 -0
- package/lib/node/TableNode.js +11 -0
- package/lib/node/index.d.ts +16 -0
- package/lib/node/index.js +28 -0
- package/lib/parser/Parser.d.ts +16 -0
- package/lib/parser/Parser.js +5 -0
- package/lib/parser/boolean.d.ts +4 -0
- package/lib/parser/boolean.js +11 -0
- package/lib/parser/comment.d.ts +12 -0
- package/lib/parser/comment.js +34 -0
- package/lib/parser/empty.d.ts +3 -0
- package/lib/parser/empty.js +7 -0
- package/lib/parser/error.d.ts +8 -0
- package/lib/parser/error.js +22 -0
- package/lib/parser/file.d.ts +9 -0
- package/lib/parser/file.js +37 -0
- package/lib/parser/float.d.ts +33 -0
- package/lib/parser/float.js +57 -0
- package/lib/parser/index.d.ts +17 -0
- package/lib/parser/index.js +36 -0
- package/lib/parser/integer.d.ts +33 -0
- package/lib/parser/integer.js +46 -0
- package/lib/parser/list.d.ts +12 -0
- package/lib/parser/list.js +70 -0
- package/lib/parser/literal.d.ts +5 -0
- package/lib/parser/literal.js +41 -0
- package/lib/parser/long.d.ts +33 -0
- package/lib/parser/long.js +50 -0
- package/lib/parser/record.d.ts +22 -0
- package/lib/parser/record.js +97 -0
- package/lib/parser/resourceLocation.d.ts +4 -0
- package/lib/parser/resourceLocation.js +67 -0
- package/lib/parser/string.d.ts +18 -0
- package/lib/parser/string.js +129 -0
- package/lib/parser/symbol.d.ts +12 -0
- package/lib/parser/symbol.js +33 -0
- package/lib/parser/table.d.ts +22 -0
- package/lib/parser/table.js +97 -0
- package/lib/parser/util.d.ts +134 -0
- package/lib/parser/util.js +224 -0
- package/lib/processor/ColorInfoProvider.d.ts +87 -0
- package/lib/processor/ColorInfoProvider.js +141 -0
- package/lib/processor/InlayHintProvider.d.ts +8 -0
- package/lib/processor/InlayHintProvider.js +3 -0
- package/lib/processor/SignatureHelpProvider.d.ts +18 -0
- package/lib/processor/SignatureHelpProvider.js +3 -0
- package/lib/processor/checker/Checker.d.ts +7 -0
- package/lib/processor/checker/Checker.js +7 -0
- package/lib/processor/checker/builtin.d.ts +23 -0
- package/lib/processor/checker/builtin.js +83 -0
- package/lib/processor/checker/index.d.ts +3 -0
- package/lib/processor/checker/index.js +28 -0
- package/lib/processor/colorizer/Colorizer.d.ts +23 -0
- package/lib/processor/colorizer/Colorizer.js +70 -0
- package/lib/processor/colorizer/builtin.d.ts +17 -0
- package/lib/processor/colorizer/builtin.js +84 -0
- package/lib/processor/colorizer/index.d.ts +3 -0
- package/lib/processor/colorizer/index.js +28 -0
- package/lib/processor/completer/Completer.d.ts +75 -0
- package/lib/processor/completer/Completer.js +92 -0
- package/lib/processor/completer/builtin.d.ts +30 -0
- package/lib/processor/completer/builtin.js +172 -0
- package/lib/processor/completer/index.d.ts +3 -0
- package/lib/processor/completer/index.js +28 -0
- package/lib/processor/formatter/Formatter.d.ts +6 -0
- package/lib/processor/formatter/Formatter.js +19 -0
- package/lib/processor/formatter/builtin.d.ts +15 -0
- package/lib/processor/formatter/builtin.js +60 -0
- package/lib/processor/formatter/index.d.ts +3 -0
- package/lib/processor/formatter/index.js +28 -0
- package/lib/processor/index.d.ts +10 -0
- package/lib/processor/index.js +22 -0
- package/lib/processor/linter/Linter.d.ts +4 -0
- package/lib/processor/linter/Linter.js +3 -0
- package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +4 -0
- package/lib/processor/linter/builtin/undeclaredSymbol.js +73 -0
- package/lib/processor/linter/builtin.d.ts +15 -0
- package/lib/processor/linter/builtin.js +120 -0
- package/lib/processor/linter/index.d.ts +3 -0
- package/lib/processor/linter/index.js +28 -0
- package/lib/processor/util.d.ts +17 -0
- package/lib/processor/util.js +32 -0
- package/lib/service/CacheService.d.ts +54 -0
- package/lib/service/CacheService.js +195 -0
- package/lib/service/CommandExecutor.d.ts +3 -0
- package/lib/service/CommandExecutor.js +7 -0
- package/lib/service/Config.d.ts +218 -0
- package/lib/service/Config.js +264 -0
- package/lib/service/Context.d.ts +143 -0
- package/lib/service/Context.js +143 -0
- package/lib/service/Dependency.d.ts +10 -0
- package/lib/service/Dependency.js +11 -0
- package/lib/service/Downloader.d.ts +67 -0
- package/lib/service/Downloader.js +185 -0
- package/lib/service/ErrorReporter.d.ts +27 -0
- package/lib/service/ErrorReporter.js +49 -0
- package/lib/service/FileService.d.ts +96 -0
- package/lib/service/FileService.js +224 -0
- package/lib/service/Hover.d.ts +10 -0
- package/lib/service/Hover.js +16 -0
- package/lib/service/Logger.d.ts +31 -0
- package/lib/service/Logger.js +30 -0
- package/lib/service/MetaRegistry.d.ts +106 -0
- package/lib/service/MetaRegistry.js +192 -0
- package/lib/service/Operations.d.ts +8 -0
- package/lib/service/Operations.js +26 -0
- package/lib/service/Profiler.d.ts +33 -0
- package/lib/service/Profiler.js +76 -0
- package/lib/service/Project.d.ts +173 -0
- package/lib/service/Project.js +593 -0
- package/lib/service/Service.d.ts +55 -0
- package/lib/service/Service.js +207 -0
- package/lib/service/SymbolLocations.d.ts +17 -0
- package/lib/service/SymbolLocations.js +16 -0
- package/lib/service/SymbolRegistrar.d.ts +5 -0
- package/lib/service/SymbolRegistrar.js +3 -0
- package/lib/service/fileUtil.d.ts +121 -0
- package/lib/service/fileUtil.js +268 -0
- package/lib/service/index.d.ts +18 -0
- package/lib/service/index.js +33 -0
- package/lib/source/IndexMap.d.ts +16 -0
- package/lib/source/IndexMap.js +46 -0
- package/lib/source/LanguageError.d.ts +27 -0
- package/lib/source/LanguageError.js +15 -0
- package/lib/source/Location.d.ts +19 -0
- package/lib/source/Location.js +25 -0
- package/lib/source/Offset.d.ts +13 -0
- package/lib/source/Offset.js +25 -0
- package/lib/source/Position.d.ts +23 -0
- package/lib/source/Position.js +43 -0
- package/lib/source/PositionRange.d.ts +38 -0
- package/lib/source/PositionRange.js +83 -0
- package/lib/source/Range.d.ts +68 -0
- package/lib/source/Range.js +155 -0
- package/lib/source/Source.d.ts +110 -0
- package/lib/source/Source.js +222 -0
- package/lib/source/index.d.ts +9 -0
- package/lib/source/index.js +21 -0
- package/lib/symbol/Symbol.d.ts +219 -0
- package/lib/symbol/Symbol.js +324 -0
- package/lib/symbol/SymbolUtil.d.ts +407 -0
- package/lib/symbol/SymbolUtil.js +880 -0
- package/lib/symbol/UriBinder.d.ts +3 -0
- package/lib/symbol/UriBinder.js +3 -0
- package/lib/symbol/index.d.ts +4 -0
- package/lib/symbol/index.js +16 -0
- package/package.json +41 -0
|
@@ -0,0 +1,207 @@
|
|
|
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");
|
|
20
|
+
/* 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;
|
|
26
|
+
this.isDebugging = isDebugging;
|
|
27
|
+
this.logger = logger;
|
|
28
|
+
this.profilers = profilers;
|
|
29
|
+
this.project = new Project_1.Project({ cacheRoot, downloader, fs, initializers, logger, profilers, projectPath });
|
|
30
|
+
}
|
|
31
|
+
debug(message) {
|
|
32
|
+
if (this.isDebugging) {
|
|
33
|
+
this.logger.info(`[DEBUG] ${message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
colorize(node, doc, range) {
|
|
37
|
+
try {
|
|
38
|
+
this.debug(`Colorizing '${doc.uri}' # ${doc.version}`);
|
|
39
|
+
const colorizer = this.project.meta.getColorizer(node.type);
|
|
40
|
+
return colorizer(node, Context_1.ColorizerContext.create(this.project, { doc, range }));
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
this.logger.error(`[Service] [colorize] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
44
|
+
}
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
getColorInfo(node, doc) {
|
|
48
|
+
try {
|
|
49
|
+
this.debug(`Getting color info for '${doc.uri}' # ${doc.version}`);
|
|
50
|
+
const ans = [];
|
|
51
|
+
(0, processor_1.traversePreOrder)(node, _ => true, node => node.color, node => ans.push({
|
|
52
|
+
color: Array.isArray(node.color) ? node.color : node.color.value,
|
|
53
|
+
range: Array.isArray(node.color) ? node.range : (node.color.range ?? node.range),
|
|
54
|
+
}));
|
|
55
|
+
return ans;
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
this.logger.error(`[Service] [getColorInfo] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
59
|
+
}
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
getColorPresentation(file, doc, range, color) {
|
|
63
|
+
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 });
|
|
66
|
+
while (node) {
|
|
67
|
+
const nodeColor = node.color;
|
|
68
|
+
if (nodeColor && !Array.isArray(nodeColor)) {
|
|
69
|
+
const colorRange = nodeColor.range ?? node.range;
|
|
70
|
+
return nodeColor.format.map(format => processor_1.ColorPresentation.fromColorFormat(format, color, colorRange));
|
|
71
|
+
}
|
|
72
|
+
node = node.parent;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
this.logger.error(`[Service] [getColorPresentation] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
77
|
+
}
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
complete(node, doc, offset, triggerCharacter) {
|
|
81
|
+
try {
|
|
82
|
+
this.debug(`Getting completion for '${doc.uri}' # ${doc.version} @ ${offset}`);
|
|
83
|
+
const shouldComplete = this.project.meta.shouldComplete(doc.languageId, triggerCharacter);
|
|
84
|
+
if (shouldComplete) {
|
|
85
|
+
return processor_1.completer.file(node, Context_1.CompleterContext.create(this.project, { doc, offset, triggerCharacter }));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
this.logger.error(`[Service] [complete] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
90
|
+
}
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
dataHackPubify(initialism) {
|
|
94
|
+
const Secrets = [
|
|
95
|
+
// data hack pub
|
|
96
|
+
// —— Skylinerw, 2020 https://discord.com/channels/154777837382008833/154777837382008833/736313565291741355
|
|
97
|
+
['ata', 'ack', 'ub', 'elper', 'lus'],
|
|
98
|
+
// Dah Huh Pew Helpa Plush
|
|
99
|
+
// —— DoubleFelix, 2021 https://discord.com/channels/154777837382008833/154777837382008833/842070090828087308
|
|
100
|
+
['ah', 'uh', 'ew', 'elpa', 'lush'],
|
|
101
|
+
];
|
|
102
|
+
const secrets = Secrets[Math.floor(Math.random() * Secrets.length)];
|
|
103
|
+
// Punctuation should not be treated differently from any other characters, per example:
|
|
104
|
+
// Hata &ack Sub
|
|
105
|
+
// —— Skylinerw, 2022 https://discord.com/channels/154777837382008833/734106483104415856/955521761351454741
|
|
106
|
+
return [...initialism]
|
|
107
|
+
.map((c, i) => `${c.toUpperCase()}${secrets[i % secrets.length]}`)
|
|
108
|
+
.join(' ');
|
|
109
|
+
}
|
|
110
|
+
getHover(file, doc, offset) {
|
|
111
|
+
try {
|
|
112
|
+
this.debug(`Getting hover for '${doc.uri}' # ${doc.version} @ ${offset}`);
|
|
113
|
+
let node = node_1.AstNode.findDeepestChild({ node: file, needle: offset });
|
|
114
|
+
while (node) {
|
|
115
|
+
const symbol = this.project.symbols.resolveAlias(node.symbol);
|
|
116
|
+
if (symbol) {
|
|
117
|
+
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);
|
|
119
|
+
}
|
|
120
|
+
if (node.hover) {
|
|
121
|
+
return Hover_1.Hover.create(node.range, node.hover);
|
|
122
|
+
}
|
|
123
|
+
node = node.parent;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
this.logger.error(`[Service] [getHover] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
getInlayHints(node, doc, range) {
|
|
132
|
+
try {
|
|
133
|
+
// TODO: `range` argument is not used.
|
|
134
|
+
this.debug(`Getting inlay hints for '${doc.uri}' # ${doc.version}`);
|
|
135
|
+
const ans = [];
|
|
136
|
+
const ctx = Context_1.ProcessorContext.create(this.project, { doc });
|
|
137
|
+
for (const provider of this.project.meta.inlayHintProviders) {
|
|
138
|
+
ans.push(...provider(node, ctx));
|
|
139
|
+
}
|
|
140
|
+
return ans;
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
this.logger.error(`[Service] [getInlayHints] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
144
|
+
}
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
getSignatureHelp(node, doc, offset) {
|
|
148
|
+
try {
|
|
149
|
+
this.debug(`Getting signature help for '${doc.uri}' # ${doc.version} @ ${offset}`);
|
|
150
|
+
const ctx = Context_1.SignatureHelpProviderContext.create(this.project, { doc, offset });
|
|
151
|
+
for (const provider of this.project.meta.signatureHelpProviders) {
|
|
152
|
+
const result = provider(node, ctx);
|
|
153
|
+
if (result) {
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
this.logger.error(`[Service] [getSignatureHelp] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @param searchedUsages Type of symbol usages that should be included in the result. Defaults to all usages.
|
|
165
|
+
* @param currentFileOnly Whether only symbol locations in the current file should be returned.
|
|
166
|
+
*
|
|
167
|
+
* @returns Symbol locations of the selected symbol at `offset`, or `undefined` if there's no symbol at `offset`.
|
|
168
|
+
*/
|
|
169
|
+
getSymbolLocations(file, doc, offset, searchedUsages = symbol_1.SymbolUsageTypes, currentFileOnly = false) {
|
|
170
|
+
try {
|
|
171
|
+
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 });
|
|
173
|
+
while (node) {
|
|
174
|
+
const symbol = this.project.symbols.resolveAlias(node.symbol);
|
|
175
|
+
if (symbol) {
|
|
176
|
+
const locations = [];
|
|
177
|
+
for (const usage of searchedUsages) {
|
|
178
|
+
let locs = symbol[usage] ?? [];
|
|
179
|
+
if (currentFileOnly) {
|
|
180
|
+
locs = locs.filter(l => l.uri === doc.uri);
|
|
181
|
+
}
|
|
182
|
+
locations.push(...locs);
|
|
183
|
+
}
|
|
184
|
+
return SymbolLocations_1.SymbolLocations.create(node.range, locations.length ? locations : undefined);
|
|
185
|
+
}
|
|
186
|
+
node = node.parent;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
this.logger.error(`[Service] [getSymbolLocations] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
191
|
+
}
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
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
|
+
}
|
|
206
|
+
exports.Service = Service;
|
|
207
|
+
//# sourceMappingURL=Service.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RangeLike } from '../source';
|
|
2
|
+
import { Range } from '../source';
|
|
3
|
+
import type { SymbolLocation } from '../symbol';
|
|
4
|
+
export interface SymbolLocations {
|
|
5
|
+
/**
|
|
6
|
+
* The range of the currently selected symbol.
|
|
7
|
+
*/
|
|
8
|
+
range: Range;
|
|
9
|
+
/**
|
|
10
|
+
* All locations of the symbol for the specific usage, or `undefined` if this symbol doesn't have the said usage.
|
|
11
|
+
*/
|
|
12
|
+
locations: SymbolLocation[] | undefined;
|
|
13
|
+
}
|
|
14
|
+
export declare namespace SymbolLocations {
|
|
15
|
+
function create(range: RangeLike, locations: SymbolLocation[] | undefined): SymbolLocations;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=SymbolLocations.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SymbolLocations = void 0;
|
|
4
|
+
const source_1 = require("../source");
|
|
5
|
+
var SymbolLocations;
|
|
6
|
+
(function (SymbolLocations) {
|
|
7
|
+
/* istanbul ignore next */
|
|
8
|
+
function create(range, locations) {
|
|
9
|
+
return {
|
|
10
|
+
range: source_1.Range.get(range),
|
|
11
|
+
locations,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
SymbolLocations.create = create;
|
|
15
|
+
})(SymbolLocations = exports.SymbolLocations || (exports.SymbolLocations = {}));
|
|
16
|
+
//# sourceMappingURL=SymbolLocations.js.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type fs from 'fs';
|
|
3
|
+
import { URL as Uri } from 'url';
|
|
4
|
+
export declare type RootUriString = `${string}/`;
|
|
5
|
+
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
|
+
export declare namespace fileUtil {
|
|
11
|
+
/**
|
|
12
|
+
* @param rootUris The root URIs. Each URI in this array must end with a slash (`/`).
|
|
13
|
+
* @param uri The target file URI.
|
|
14
|
+
* @returns The relative path from one of the `roots` to the `uri`, or `undefined` if the `uri` is not under any roots.
|
|
15
|
+
* The separation used in the relative path is always slash (`/`).
|
|
16
|
+
* @example
|
|
17
|
+
* getRels(['file:///root/foo/', 'file:///root/'], 'file:///root/foo/bar/qux.json')
|
|
18
|
+
* // -> 'bar/qux.json'
|
|
19
|
+
* // -> 'foo/bar/qux.json'
|
|
20
|
+
* // -> undefined
|
|
21
|
+
*
|
|
22
|
+
* getRels(['file:///root/foo/', 'file:///root/'], 'file:///outsider.json')
|
|
23
|
+
* // -> undefined
|
|
24
|
+
*/
|
|
25
|
+
function getRels(uri: string, rootUris: readonly RootUriString[]): Generator<string, undefined, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* @see {@link getRels}
|
|
28
|
+
* @example
|
|
29
|
+
* getRel(['file:///root/foo/', 'file:///root/'], 'file:///root/foo/bar/qux.json') // -> 'bar/qux.json'
|
|
30
|
+
* getRel(['file:///root/foo/', 'file:///root/'], 'file:///outsider.json') // -> undefined
|
|
31
|
+
*/
|
|
32
|
+
function getRel(uri: string, rootUris: readonly RootUriString[]): string | undefined;
|
|
33
|
+
function isRootUri(uri: string): uri is RootUriString;
|
|
34
|
+
function ensureEndingSlash(uri: string): RootUriString;
|
|
35
|
+
function join(fromUri: string, toUri: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* @throws If `uri` is not a valid URI.
|
|
38
|
+
*/
|
|
39
|
+
function isFileUri(uri: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* @returns The part from the last `.` to the end of the URI, or `undefined` if no dots exist. No special treatment for leading dots.
|
|
42
|
+
*/
|
|
43
|
+
function extname(value: string): FileExtension | undefined;
|
|
44
|
+
/**
|
|
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.
|
|
48
|
+
*/
|
|
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;
|
|
57
|
+
/**
|
|
58
|
+
* @throws
|
|
59
|
+
*
|
|
60
|
+
* @param mode Default to `0o777` (`rwxrwxrwx`)
|
|
61
|
+
*/
|
|
62
|
+
function ensureDir(path: PathLike, mode?: fs.Mode): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* @throws
|
|
65
|
+
*
|
|
66
|
+
* Ensures the parent directory of the path exists.
|
|
67
|
+
*
|
|
68
|
+
* @param mode Default to `0o777` (`rwxrwxrwx`)
|
|
69
|
+
*/
|
|
70
|
+
function ensureParentOfFile(path: PathLike, mode?: fs.Mode): Promise<void>;
|
|
71
|
+
function readFile(path: PathLike): Promise<Buffer>;
|
|
72
|
+
/**
|
|
73
|
+
* @throws
|
|
74
|
+
*
|
|
75
|
+
* The directory of the file will be created recursively if it doesn'texist.
|
|
76
|
+
*
|
|
77
|
+
* * Encoding: `utf-8`
|
|
78
|
+
* * Mode: `0o666` (`rw-rw-rw-`)
|
|
79
|
+
* * Flag: `w`
|
|
80
|
+
*/
|
|
81
|
+
function writeFile(path: PathLike, data: Buffer | string): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* @throws
|
|
84
|
+
*/
|
|
85
|
+
function readJson<T = any>(path: PathLike): Promise<T>;
|
|
86
|
+
/**
|
|
87
|
+
* @throws
|
|
88
|
+
*
|
|
89
|
+
* @see {@link writeFile}
|
|
90
|
+
*/
|
|
91
|
+
function writeJson(path: PathLike, data: any): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* @throws
|
|
94
|
+
*/
|
|
95
|
+
function readGzippedFile(path: PathLike): Promise<Buffer>;
|
|
96
|
+
/**
|
|
97
|
+
* @throws
|
|
98
|
+
*/
|
|
99
|
+
function writeGzippedFile(path: PathLike, buffer: Buffer | string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* @throws
|
|
102
|
+
*/
|
|
103
|
+
function readGzippedJson<T = any>(path: PathLike): Promise<T>;
|
|
104
|
+
/**
|
|
105
|
+
* @throws
|
|
106
|
+
*/
|
|
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
|
+
}>;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=fileUtil.d.ts.map
|
|
@@ -0,0 +1,268 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.fileUtil = void 0;
|
|
26
|
+
const child_process_1 = __importDefault(require("child_process"));
|
|
27
|
+
const fs_1 = require("fs");
|
|
28
|
+
const path_1 = require("path");
|
|
29
|
+
const process_1 = __importDefault(require("process"));
|
|
30
|
+
const url_1 = __importStar(require("url"));
|
|
31
|
+
const util_1 = require("util");
|
|
32
|
+
const zlib_1 = __importDefault(require("zlib"));
|
|
33
|
+
const common_1 = require("../common");
|
|
34
|
+
var fileUtil;
|
|
35
|
+
(function (fileUtil) {
|
|
36
|
+
/**
|
|
37
|
+
* @param rootUris The root URIs. Each URI in this array must end with a slash (`/`).
|
|
38
|
+
* @param uri The target file URI.
|
|
39
|
+
* @returns The relative path from one of the `roots` to the `uri`, or `undefined` if the `uri` is not under any roots.
|
|
40
|
+
* The separation used in the relative path is always slash (`/`).
|
|
41
|
+
* @example
|
|
42
|
+
* getRels(['file:///root/foo/', 'file:///root/'], 'file:///root/foo/bar/qux.json')
|
|
43
|
+
* // -> 'bar/qux.json'
|
|
44
|
+
* // -> 'foo/bar/qux.json'
|
|
45
|
+
* // -> undefined
|
|
46
|
+
*
|
|
47
|
+
* getRels(['file:///root/foo/', 'file:///root/'], 'file:///outsider.json')
|
|
48
|
+
* // -> undefined
|
|
49
|
+
*/
|
|
50
|
+
function* getRels(uri, rootUris) {
|
|
51
|
+
for (const root of rootUris) {
|
|
52
|
+
if (uri.startsWith(root)) {
|
|
53
|
+
yield decodeURIComponent(uri.slice(root.length));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
fileUtil.getRels = getRels;
|
|
59
|
+
/**
|
|
60
|
+
* @see {@link getRels}
|
|
61
|
+
* @example
|
|
62
|
+
* getRel(['file:///root/foo/', 'file:///root/'], 'file:///root/foo/bar/qux.json') // -> 'bar/qux.json'
|
|
63
|
+
* getRel(['file:///root/foo/', 'file:///root/'], 'file:///outsider.json') // -> undefined
|
|
64
|
+
*/
|
|
65
|
+
function getRel(uri, rootUris) {
|
|
66
|
+
return getRels(uri, rootUris).next().value;
|
|
67
|
+
}
|
|
68
|
+
fileUtil.getRel = getRel;
|
|
69
|
+
function isRootUri(uri) {
|
|
70
|
+
return uri.endsWith('/');
|
|
71
|
+
}
|
|
72
|
+
fileUtil.isRootUri = isRootUri;
|
|
73
|
+
function ensureEndingSlash(uri) {
|
|
74
|
+
return isRootUri(uri) ? uri : `${uri}/`;
|
|
75
|
+
}
|
|
76
|
+
fileUtil.ensureEndingSlash = ensureEndingSlash;
|
|
77
|
+
function join(fromUri, toUri) {
|
|
78
|
+
return ensureEndingSlash(fromUri) + (toUri.startsWith('/') ? toUri.slice(1) : toUri);
|
|
79
|
+
}
|
|
80
|
+
fileUtil.join = join;
|
|
81
|
+
/**
|
|
82
|
+
* @throws If `uri` is not a valid URI.
|
|
83
|
+
*/
|
|
84
|
+
function isFileUri(uri) {
|
|
85
|
+
return uri.startsWith('file:');
|
|
86
|
+
}
|
|
87
|
+
fileUtil.isFileUri = isFileUri;
|
|
88
|
+
/**
|
|
89
|
+
* @returns The part from the last `.` to the end of the URI, or `undefined` if no dots exist. No special treatment for leading dots.
|
|
90
|
+
*/
|
|
91
|
+
function extname(value) {
|
|
92
|
+
const i = value.lastIndexOf('.');
|
|
93
|
+
return i >= 0 ? value.slice(i) : undefined;
|
|
94
|
+
}
|
|
95
|
+
fileUtil.extname = extname;
|
|
96
|
+
/* istanbul ignore next */
|
|
97
|
+
/**
|
|
98
|
+
* @param fileUri A file URI.
|
|
99
|
+
* @returns The corresponding file path of the `fileUri` in platform-specific format.
|
|
100
|
+
* @throws If the URI is not a file schema URI.
|
|
101
|
+
*/
|
|
102
|
+
function fileUriToPath(fileUri) {
|
|
103
|
+
return url_1.default.fileURLToPath(new url_1.URL(fileUri));
|
|
104
|
+
}
|
|
105
|
+
fileUtil.fileUriToPath = fileUriToPath;
|
|
106
|
+
/* istanbul ignore next */
|
|
107
|
+
/**
|
|
108
|
+
* @param path A file path.
|
|
109
|
+
* @returns The corresponding file URI of the `path`.
|
|
110
|
+
*/
|
|
111
|
+
function pathToFileUri(path) {
|
|
112
|
+
return url_1.default.pathToFileURL(path).toString();
|
|
113
|
+
}
|
|
114
|
+
fileUtil.pathToFileUri = pathToFileUri;
|
|
115
|
+
/* istanbul ignore next */
|
|
116
|
+
function normalize(uri) {
|
|
117
|
+
try {
|
|
118
|
+
return isFileUri(uri) ? pathToFileUri(fileUriToPath(uri)) : new url_1.URL(uri).toString();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return uri;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
fileUtil.normalize = normalize;
|
|
125
|
+
/**
|
|
126
|
+
* @param path A string file path, string file URI, or a file URI object.
|
|
127
|
+
*
|
|
128
|
+
* @returns A {@link fs.PathLike}.
|
|
129
|
+
*/
|
|
130
|
+
function toFsPathLike(path) {
|
|
131
|
+
if (typeof path === 'string' && isFileUri(path)) {
|
|
132
|
+
return new url_1.URL(path);
|
|
133
|
+
}
|
|
134
|
+
return path;
|
|
135
|
+
}
|
|
136
|
+
/* istanbul ignore next */
|
|
137
|
+
function getParentOfFile(path) {
|
|
138
|
+
if (path instanceof url_1.URL || isFileUri(path)) {
|
|
139
|
+
return new url_1.URL('.', path);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
return (0, path_1.resolve)(path, '..');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
fileUtil.getParentOfFile = getParentOfFile;
|
|
146
|
+
/* istanbul ignore next */
|
|
147
|
+
/**
|
|
148
|
+
* @throws
|
|
149
|
+
*
|
|
150
|
+
* @param mode Default to `0o777` (`rwxrwxrwx`)
|
|
151
|
+
*/
|
|
152
|
+
async function ensureDir(path, mode = 0o777) {
|
|
153
|
+
try {
|
|
154
|
+
await fs_1.promises.mkdir(toFsPathLike(path), { mode, recursive: true });
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
if (!(0, common_1.isErrorCode)(e, 'EEXIST')) {
|
|
158
|
+
throw e;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
fileUtil.ensureDir = ensureDir;
|
|
163
|
+
/* istanbul ignore next */
|
|
164
|
+
/**
|
|
165
|
+
* @throws
|
|
166
|
+
*
|
|
167
|
+
* Ensures the parent directory of the path exists.
|
|
168
|
+
*
|
|
169
|
+
* @param mode Default to `0o777` (`rwxrwxrwx`)
|
|
170
|
+
*/
|
|
171
|
+
async function ensureParentOfFile(path, mode = 0o777) {
|
|
172
|
+
return ensureDir(getParentOfFile(path), mode);
|
|
173
|
+
}
|
|
174
|
+
fileUtil.ensureParentOfFile = ensureParentOfFile;
|
|
175
|
+
async function readFile(path) {
|
|
176
|
+
return fs_1.promises.readFile(toFsPathLike(path));
|
|
177
|
+
}
|
|
178
|
+
fileUtil.readFile = readFile;
|
|
179
|
+
/* istanbul ignore next */
|
|
180
|
+
/**
|
|
181
|
+
* @throws
|
|
182
|
+
*
|
|
183
|
+
* The directory of the file will be created recursively if it doesn'texist.
|
|
184
|
+
*
|
|
185
|
+
* * Encoding: `utf-8`
|
|
186
|
+
* * Mode: `0o666` (`rw-rw-rw-`)
|
|
187
|
+
* * Flag: `w`
|
|
188
|
+
*/
|
|
189
|
+
async function writeFile(path, data) {
|
|
190
|
+
await ensureParentOfFile(path);
|
|
191
|
+
return fs_1.promises.writeFile(toFsPathLike(path), data);
|
|
192
|
+
}
|
|
193
|
+
fileUtil.writeFile = writeFile;
|
|
194
|
+
/* istanbul ignore next */
|
|
195
|
+
/**
|
|
196
|
+
* @throws
|
|
197
|
+
*/
|
|
198
|
+
async function readJson(path) {
|
|
199
|
+
return JSON.parse((0, common_1.bufferToString)(await readFile(path)));
|
|
200
|
+
}
|
|
201
|
+
fileUtil.readJson = readJson;
|
|
202
|
+
/* istanbul ignore next */
|
|
203
|
+
/**
|
|
204
|
+
* @throws
|
|
205
|
+
*
|
|
206
|
+
* @see {@link writeFile}
|
|
207
|
+
*/
|
|
208
|
+
async function writeJson(path, data) {
|
|
209
|
+
return writeFile(path, JSON.stringify(data));
|
|
210
|
+
}
|
|
211
|
+
fileUtil.writeJson = writeJson;
|
|
212
|
+
/**
|
|
213
|
+
* @throws
|
|
214
|
+
*/
|
|
215
|
+
async function readGzippedFile(path) {
|
|
216
|
+
const unzip = (0, util_1.promisify)(zlib_1.default.gunzip);
|
|
217
|
+
return unzip(await readFile(path));
|
|
218
|
+
}
|
|
219
|
+
fileUtil.readGzippedFile = readGzippedFile;
|
|
220
|
+
/**
|
|
221
|
+
* @throws
|
|
222
|
+
*/
|
|
223
|
+
async function writeGzippedFile(path, buffer) {
|
|
224
|
+
const zip = (0, util_1.promisify)(zlib_1.default.gzip);
|
|
225
|
+
return writeFile(path, await zip(buffer));
|
|
226
|
+
}
|
|
227
|
+
fileUtil.writeGzippedFile = writeGzippedFile;
|
|
228
|
+
/**
|
|
229
|
+
* @throws
|
|
230
|
+
*/
|
|
231
|
+
async function readGzippedJson(path) {
|
|
232
|
+
return JSON.parse((0, common_1.bufferToString)(await readGzippedFile(path)));
|
|
233
|
+
}
|
|
234
|
+
fileUtil.readGzippedJson = readGzippedJson;
|
|
235
|
+
/**
|
|
236
|
+
* @throws
|
|
237
|
+
*/
|
|
238
|
+
async function writeGzippedJson(path, data) {
|
|
239
|
+
return writeGzippedFile(path, JSON.stringify(data));
|
|
240
|
+
}
|
|
241
|
+
fileUtil.writeGzippedJson = writeGzippedJson;
|
|
242
|
+
/**
|
|
243
|
+
* Show the file/directory in the platform-specific explorer program.
|
|
244
|
+
*
|
|
245
|
+
* Should not be called with unsanitized user-input path due to the possibility of
|
|
246
|
+
* arbitrary code execution.
|
|
247
|
+
*
|
|
248
|
+
* @returns The `stdout` from the spawned child process.
|
|
249
|
+
*/
|
|
250
|
+
async function showFile(path) {
|
|
251
|
+
const execFile = (0, util_1.promisify)(child_process_1.default.execFile);
|
|
252
|
+
let command;
|
|
253
|
+
switch (process_1.default.platform) {
|
|
254
|
+
case 'darwin':
|
|
255
|
+
command = 'open';
|
|
256
|
+
break;
|
|
257
|
+
case 'win32':
|
|
258
|
+
command = 'explorer';
|
|
259
|
+
break;
|
|
260
|
+
default:
|
|
261
|
+
command = 'xdg-open';
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
return execFile(command, [path]);
|
|
265
|
+
}
|
|
266
|
+
fileUtil.showFile = showFile;
|
|
267
|
+
})(fileUtil = exports.fileUtil || (exports.fileUtil = {}));
|
|
268
|
+
//# sourceMappingURL=fileUtil.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './CacheService';
|
|
2
|
+
export * from './Config';
|
|
3
|
+
export * from './Context';
|
|
4
|
+
export * from './Dependency';
|
|
5
|
+
export * from './Downloader';
|
|
6
|
+
export * from './ErrorReporter';
|
|
7
|
+
export { FileService, UriProtocolSupporter } from './FileService';
|
|
8
|
+
export * from './fileUtil';
|
|
9
|
+
export * from './Hover';
|
|
10
|
+
export * from './Logger';
|
|
11
|
+
export * from './MetaRegistry';
|
|
12
|
+
export * from './Operations';
|
|
13
|
+
export * from './Profiler';
|
|
14
|
+
export * from './Project';
|
|
15
|
+
export * from './Service';
|
|
16
|
+
export * from './SymbolLocations';
|
|
17
|
+
export * from './SymbolRegistrar';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|