@spyglassmc/core 0.1.2 → 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.
- package/README.md +7 -0
- package/lib/browser.d.ts +2 -0
- package/lib/browser.js +2 -0
- package/lib/common/TwoWayMap.js +4 -10
- package/lib/common/externals/BrowserExternals.d.ts +3 -0
- package/lib/common/externals/BrowserExternals.js +191 -0
- package/lib/common/externals/NodeJsExternals.d.ts +3 -0
- package/lib/common/externals/NodeJsExternals.js +151 -0
- package/lib/common/externals/downloader.d.ts +31 -0
- package/lib/common/externals/downloader.js +32 -0
- package/lib/common/externals/index.d.ts +96 -0
- package/lib/common/externals/index.js +2 -0
- package/lib/common/index.d.ts +2 -1
- package/lib/common/index.js +2 -17
- package/lib/common/util.d.ts +15 -15
- package/lib/common/util.js +30 -77
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -23
- package/lib/node/AstNode.d.ts +3 -3
- package/lib/node/AstNode.js +10 -16
- package/lib/node/BooleanNode.d.ts +2 -2
- package/lib/node/BooleanNode.js +4 -7
- package/lib/node/CommentNode.d.ts +1 -1
- package/lib/node/CommentNode.js +2 -5
- package/lib/node/ErrorNode.d.ts +1 -1
- package/lib/node/ErrorNode.js +2 -5
- package/lib/node/FileNode.d.ts +3 -3
- package/lib/node/FileNode.js +2 -5
- package/lib/node/FloatNode.d.ts +2 -2
- package/lib/node/FloatNode.js +4 -7
- package/lib/node/IntegerNode.d.ts +2 -2
- package/lib/node/IntegerNode.js +4 -7
- package/lib/node/ListNode.d.ts +2 -2
- package/lib/node/ListNode.js +2 -5
- package/lib/node/LiteralNode.d.ts +3 -3
- package/lib/node/LiteralNode.js +4 -7
- package/lib/node/LongNode.d.ts +2 -2
- package/lib/node/LongNode.js +4 -7
- package/lib/node/RecordNode.d.ts +2 -2
- package/lib/node/RecordNode.js +2 -5
- package/lib/node/ResourceLocationNode.d.ts +5 -5
- package/lib/node/ResourceLocationNode.js +9 -12
- package/lib/node/Sequence.d.ts +2 -2
- package/lib/node/Sequence.js +4 -7
- package/lib/node/StringNode.d.ts +4 -4
- package/lib/node/StringNode.js +9 -12
- package/lib/node/SymbolNode.d.ts +3 -3
- package/lib/node/SymbolNode.js +4 -7
- package/lib/node/index.d.ts +15 -15
- package/lib/node/index.js +15 -31
- package/lib/nodejs.d.ts +2 -0
- package/lib/nodejs.js +2 -0
- package/lib/parser/Parser.d.ts +3 -3
- package/lib/parser/Parser.js +1 -4
- package/lib/parser/boolean.d.ts +2 -2
- package/lib/parser/boolean.js +3 -6
- package/lib/parser/comment.d.ts +2 -2
- package/lib/parser/comment.js +5 -9
- package/lib/parser/empty.d.ts +1 -1
- package/lib/parser/empty.js +1 -5
- package/lib/parser/error.d.ts +2 -2
- package/lib/parser/error.js +5 -9
- package/lib/parser/file.d.ts +3 -3
- package/lib/parser/file.js +9 -13
- package/lib/parser/float.d.ts +4 -4
- package/lib/parser/float.js +12 -16
- package/lib/parser/index.d.ts +16 -16
- package/lib/parser/index.js +16 -38
- package/lib/parser/integer.d.ts +4 -4
- package/lib/parser/integer.js +10 -14
- package/lib/parser/list.d.ts +2 -2
- package/lib/parser/list.js +15 -19
- package/lib/parser/literal.d.ts +2 -2
- package/lib/parser/literal.js +5 -9
- package/lib/parser/long.d.ts +4 -4
- package/lib/parser/long.js +10 -14
- package/lib/parser/record.d.ts +3 -3
- package/lib/parser/record.js +20 -24
- package/lib/parser/resourceLocation.d.ts +2 -2
- package/lib/parser/resourceLocation.js +14 -18
- package/lib/parser/string.d.ts +5 -5
- package/lib/parser/string.js +36 -42
- package/lib/parser/symbol.d.ts +3 -3
- package/lib/parser/symbol.js +3 -7
- package/lib/parser/util.d.ts +5 -5
- package/lib/parser/util.js +38 -56
- package/lib/processor/ColorInfoProvider.d.ts +1 -1
- package/lib/processor/ColorInfoProvider.js +6 -9
- package/lib/processor/InlayHintProvider.d.ts +2 -2
- package/lib/processor/InlayHintProvider.js +1 -2
- package/lib/processor/SignatureHelpProvider.d.ts +2 -2
- package/lib/processor/SignatureHelpProvider.js +1 -2
- package/lib/processor/checker/Checker.d.ts +2 -2
- package/lib/processor/checker/Checker.js +1 -5
- package/lib/processor/checker/builtin.d.ts +4 -4
- package/lib/processor/checker/builtin.js +19 -30
- package/lib/processor/checker/index.d.ts +2 -2
- package/lib/processor/checker/index.js +2 -31
- package/lib/processor/colorizer/Colorizer.d.ts +4 -4
- package/lib/processor/colorizer/Colorizer.js +8 -11
- package/lib/processor/colorizer/builtin.d.ts +3 -3
- package/lib/processor/colorizer/builtin.js +33 -46
- package/lib/processor/colorizer/index.d.ts +2 -2
- package/lib/processor/colorizer/index.js +2 -31
- package/lib/processor/completer/Completer.d.ts +4 -4
- package/lib/processor/completer/Completer.js +14 -33
- package/lib/processor/completer/builtin.d.ts +7 -7
- package/lib/processor/completer/builtin.js +46 -62
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -31
- package/lib/processor/formatter/Formatter.d.ts +2 -2
- package/lib/processor/formatter/Formatter.js +2 -7
- package/lib/processor/formatter/builtin.d.ts +3 -3
- package/lib/processor/formatter/builtin.js +22 -36
- package/lib/processor/formatter/index.d.ts +2 -2
- package/lib/processor/formatter/index.js +2 -31
- package/lib/processor/index.d.ts +9 -9
- package/lib/processor/index.js +9 -25
- package/lib/processor/linter/Linter.d.ts +2 -2
- package/lib/processor/linter/Linter.js +1 -2
- package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
- package/lib/processor/linter/builtin/undeclaredSymbol.js +20 -24
- package/lib/processor/linter/builtin.d.ts +3 -3
- package/lib/processor/linter/builtin.js +19 -26
- package/lib/processor/linter/index.d.ts +2 -2
- package/lib/processor/linter/index.js +2 -31
- package/lib/processor/util.d.ts +2 -2
- package/lib/processor/util.js +4 -9
- package/lib/service/CacheService.d.ts +6 -6
- package/lib/service/CacheService.js +32 -56
- package/lib/service/Config.d.ts +11 -12
- package/lib/service/Config.js +50 -45
- package/lib/service/Context.d.ts +13 -13
- package/lib/service/Context.js +29 -32
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +10 -40
- package/lib/service/Downloader.js +37 -110
- package/lib/service/ErrorReporter.d.ts +2 -2
- package/lib/service/ErrorReporter.js +10 -14
- package/lib/service/FileService.d.ts +16 -14
- package/lib/service/FileService.js +55 -92
- package/lib/service/Hover.d.ts +2 -2
- package/lib/service/Hover.js +4 -7
- package/lib/service/Logger.js +2 -5
- package/lib/service/MetaRegistry.d.ts +12 -12
- package/lib/service/MetaRegistry.js +62 -73
- package/lib/service/Operations.js +3 -9
- package/lib/service/Profiler.d.ts +1 -1
- package/lib/service/Profiler.js +25 -41
- package/lib/service/Project.d.ts +47 -51
- package/lib/service/Project.js +199 -239
- package/lib/service/Service.d.ts +17 -27
- package/lib/service/Service.js +37 -43
- package/lib/service/SymbolLocations.d.ts +3 -3
- package/lib/service/SymbolLocations.js +4 -7
- package/lib/service/SymbolRegistrar.d.ts +1 -1
- package/lib/service/SymbolRegistrar.js +1 -2
- package/lib/service/fileUtil.d.ts +15 -45
- package/lib/service/fileUtil.js +38 -143
- package/lib/service/index.d.ts +17 -17
- package/lib/service/index.js +17 -35
- package/lib/source/IndexMap.d.ts +1 -1
- package/lib/source/IndexMap.js +7 -10
- package/lib/source/LanguageError.d.ts +2 -2
- package/lib/source/LanguageError.js +2 -5
- package/lib/source/Location.d.ts +3 -3
- package/lib/source/Location.js +6 -9
- package/lib/source/Offset.d.ts +1 -1
- package/lib/source/Offset.js +4 -7
- package/lib/source/Position.js +2 -5
- package/lib/source/PositionRange.d.ts +2 -2
- package/lib/source/PositionRange.js +14 -17
- package/lib/source/Range.d.ts +1 -1
- package/lib/source/Range.js +7 -10
- package/lib/source/Source.d.ts +3 -3
- package/lib/source/Source.js +28 -29
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -24
- package/lib/symbol/Symbol.d.ts +2 -2
- package/lib/symbol/Symbol.js +49 -65
- package/lib/symbol/SymbolUtil.d.ts +22 -25
- package/lib/symbol/SymbolUtil.js +150 -151
- package/lib/symbol/UriBinder.d.ts +1 -1
- package/lib/symbol/UriBinder.js +1 -2
- package/lib/symbol/index.d.ts +3 -3
- package/lib/symbol/index.js +3 -19
- package/package.json +7 -4
package/lib/service/Service.d.ts
CHANGED
|
@@ -1,43 +1,33 @@
|
|
|
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 {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
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
|
|
16
|
+
logger: Logger;
|
|
25
17
|
profilers?: ProfilerFactory;
|
|
26
|
-
|
|
18
|
+
project: ProjectOptions;
|
|
27
19
|
}
|
|
28
|
-
export declare class Service
|
|
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({
|
|
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;
|
|
42
32
|
format(node: FileNode<AstNode>, doc: TextDocument, tabSize: number, insertSpaces: boolean): string;
|
|
43
33
|
getHover(file: FileNode<AstNode>, doc: TextDocument, offset: number): Hover | undefined;
|
package/lib/service/Service.js
CHANGED
|
@@ -1,33 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 fileUtil_1 = require("./fileUtil");
|
|
16
|
-
const Hover_1 = require("./Hover");
|
|
17
|
-
const Logger_1 = require("./Logger");
|
|
18
|
-
const Profiler_1 = require("./Profiler");
|
|
19
|
-
const Project_1 = require("./Project");
|
|
20
|
-
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';
|
|
21
11
|
/* istanbul ignore next */
|
|
22
|
-
class Service
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
export class Service {
|
|
13
|
+
isDebugging;
|
|
14
|
+
logger;
|
|
15
|
+
profilers;
|
|
16
|
+
project;
|
|
17
|
+
constructor({ isDebugging = false, logger, profilers = ProfilerFactory.noop(), project, }) {
|
|
27
18
|
this.isDebugging = isDebugging;
|
|
28
19
|
this.logger = logger;
|
|
29
20
|
this.profilers = profilers;
|
|
30
|
-
this.project = new
|
|
21
|
+
this.project = new Project({
|
|
22
|
+
logger,
|
|
23
|
+
profilers,
|
|
24
|
+
...project,
|
|
25
|
+
});
|
|
31
26
|
}
|
|
32
27
|
debug(message) {
|
|
33
28
|
if (this.isDebugging) {
|
|
@@ -38,7 +33,7 @@ class Service extends events_1.default {
|
|
|
38
33
|
try {
|
|
39
34
|
this.debug(`Colorizing '${doc.uri}' # ${doc.version}`);
|
|
40
35
|
const colorizer = this.project.meta.getColorizer(node.type);
|
|
41
|
-
return colorizer(node,
|
|
36
|
+
return colorizer(node, ColorizerContext.create(this.project, { doc, range }));
|
|
42
37
|
}
|
|
43
38
|
catch (e) {
|
|
44
39
|
this.logger.error(`[Service] [colorize] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
@@ -49,7 +44,7 @@ class Service extends events_1.default {
|
|
|
49
44
|
try {
|
|
50
45
|
this.debug(`Getting color info for '${doc.uri}' # ${doc.version}`);
|
|
51
46
|
const ans = [];
|
|
52
|
-
|
|
47
|
+
traversePreOrder(node, _ => true, node => node.color, node => ans.push({
|
|
53
48
|
color: Array.isArray(node.color) ? node.color : node.color.value,
|
|
54
49
|
range: Array.isArray(node.color) ? node.range : (node.color.range ?? node.range),
|
|
55
50
|
}));
|
|
@@ -62,13 +57,13 @@ class Service extends events_1.default {
|
|
|
62
57
|
}
|
|
63
58
|
getColorPresentation(file, doc, range, color) {
|
|
64
59
|
try {
|
|
65
|
-
this.debug(`Getting color presentation for '${doc.uri}' # ${doc.version} @ ${
|
|
66
|
-
let node =
|
|
60
|
+
this.debug(`Getting color presentation for '${doc.uri}' # ${doc.version} @ ${Range.toString(range)}`);
|
|
61
|
+
let node = AstNode.findDeepestChild({ node: file, needle: range.start });
|
|
67
62
|
while (node) {
|
|
68
63
|
const nodeColor = node.color;
|
|
69
64
|
if (nodeColor && !Array.isArray(nodeColor)) {
|
|
70
65
|
const colorRange = nodeColor.range ?? node.range;
|
|
71
|
-
return nodeColor.format.map(format =>
|
|
66
|
+
return nodeColor.format.map(format => ColorPresentation.fromColorFormat(format, color, colorRange));
|
|
72
67
|
}
|
|
73
68
|
node = node.parent;
|
|
74
69
|
}
|
|
@@ -83,7 +78,7 @@ class Service extends events_1.default {
|
|
|
83
78
|
this.debug(`Getting completion for '${doc.uri}' # ${doc.version} @ ${offset}`);
|
|
84
79
|
const shouldComplete = this.project.meta.shouldComplete(doc.languageId, triggerCharacter);
|
|
85
80
|
if (shouldComplete) {
|
|
86
|
-
return
|
|
81
|
+
return completer.file(node, CompleterContext.create(this.project, { doc, offset, triggerCharacter }));
|
|
87
82
|
}
|
|
88
83
|
}
|
|
89
84
|
catch (e) {
|
|
@@ -112,7 +107,7 @@ class Service extends events_1.default {
|
|
|
112
107
|
try {
|
|
113
108
|
this.debug(`Formatting '${doc.uri}' # ${doc.version}`);
|
|
114
109
|
const formatter = this.project.meta.getFormatter(node.type);
|
|
115
|
-
return formatter(node,
|
|
110
|
+
return formatter(node, FormatterContext.create(this.project, { doc, tabSize, insertSpaces }));
|
|
116
111
|
}
|
|
117
112
|
catch (e) {
|
|
118
113
|
this.logger.error(`[Service] [format] Failed for “${doc.uri}” #${doc.version}`, e);
|
|
@@ -122,15 +117,15 @@ class Service extends events_1.default {
|
|
|
122
117
|
getHover(file, doc, offset) {
|
|
123
118
|
try {
|
|
124
119
|
this.debug(`Getting hover for '${doc.uri}' # ${doc.version} @ ${offset}`);
|
|
125
|
-
let node =
|
|
120
|
+
let node = AstNode.findDeepestChild({ node: file, needle: offset });
|
|
126
121
|
while (node) {
|
|
127
122
|
const symbol = this.project.symbols.resolveAlias(node.symbol);
|
|
128
123
|
if (symbol) {
|
|
129
124
|
const hover = `\`\`\`typescript\n(${symbol.category}${symbol.subcategory ? `/${symbol.subcategory}` : ''}) ${symbol.identifier}\n\`\`\`` + (symbol.desc ? `\n******\n${symbol.desc}` : '');
|
|
130
|
-
return
|
|
125
|
+
return Hover.create(node.range, hover);
|
|
131
126
|
}
|
|
132
127
|
if (node.hover) {
|
|
133
|
-
return
|
|
128
|
+
return Hover.create(node.range, node.hover);
|
|
134
129
|
}
|
|
135
130
|
node = node.parent;
|
|
136
131
|
}
|
|
@@ -145,7 +140,7 @@ class Service extends events_1.default {
|
|
|
145
140
|
// TODO: `range` argument is not used.
|
|
146
141
|
this.debug(`Getting inlay hints for '${doc.uri}' # ${doc.version}`);
|
|
147
142
|
const ans = [];
|
|
148
|
-
const ctx =
|
|
143
|
+
const ctx = ProcessorContext.create(this.project, { doc });
|
|
149
144
|
for (const provider of this.project.meta.inlayHintProviders) {
|
|
150
145
|
ans.push(...provider(node, ctx));
|
|
151
146
|
}
|
|
@@ -159,7 +154,7 @@ class Service extends events_1.default {
|
|
|
159
154
|
getSignatureHelp(node, doc, offset) {
|
|
160
155
|
try {
|
|
161
156
|
this.debug(`Getting signature help for '${doc.uri}' # ${doc.version} @ ${offset}`);
|
|
162
|
-
const ctx =
|
|
157
|
+
const ctx = SignatureHelpProviderContext.create(this.project, { doc, offset });
|
|
163
158
|
for (const provider of this.project.meta.signatureHelpProviders) {
|
|
164
159
|
const result = provider(node, ctx);
|
|
165
160
|
if (result) {
|
|
@@ -178,10 +173,10 @@ class Service extends events_1.default {
|
|
|
178
173
|
*
|
|
179
174
|
* @returns Symbol locations of the selected symbol at `offset`, or `undefined` if there's no symbol at `offset`.
|
|
180
175
|
*/
|
|
181
|
-
async getSymbolLocations(file, doc, offset, searchedUsages =
|
|
176
|
+
async getSymbolLocations(file, doc, offset, searchedUsages = SymbolUsageTypes, currentFileOnly = false) {
|
|
182
177
|
try {
|
|
183
178
|
this.debug(`Getting symbol locations of usage '${searchedUsages.join(',')}' for '${doc.uri}' # ${doc.version} @ ${offset} with currentFileOnly=${currentFileOnly}`);
|
|
184
|
-
let node =
|
|
179
|
+
let node = AstNode.findDeepestChild({ node: file, needle: offset });
|
|
185
180
|
while (node) {
|
|
186
181
|
const symbol = this.project.symbols.resolveAlias(node.symbol);
|
|
187
182
|
if (symbol) {
|
|
@@ -195,14 +190,14 @@ class Service extends events_1.default {
|
|
|
195
190
|
}
|
|
196
191
|
const locations = [];
|
|
197
192
|
for (const loc of rawLocations) {
|
|
198
|
-
const mappedUri =
|
|
193
|
+
const mappedUri = fileUtil.isFileUri(loc.uri)
|
|
199
194
|
? loc.uri
|
|
200
195
|
: await this.project.fs.mapToDisk(loc.uri);
|
|
201
196
|
if (mappedUri) {
|
|
202
197
|
locations.push({ ...loc, uri: mappedUri });
|
|
203
198
|
}
|
|
204
199
|
}
|
|
205
|
-
return
|
|
200
|
+
return SymbolLocations.create(node.range, locations.length ? locations : undefined);
|
|
206
201
|
}
|
|
207
202
|
node = node.parent;
|
|
208
203
|
}
|
|
@@ -213,5 +208,4 @@ class Service extends events_1.default {
|
|
|
213
208
|
return undefined;
|
|
214
209
|
}
|
|
215
210
|
}
|
|
216
|
-
exports.Service = Service;
|
|
217
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
|
-
|
|
2
|
-
|
|
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:
|
|
7
|
+
range: Range.get(range),
|
|
11
8
|
locations,
|
|
12
9
|
};
|
|
13
10
|
}
|
|
14
11
|
SymbolLocations.create = create;
|
|
15
|
-
})(SymbolLocations
|
|
12
|
+
})(SymbolLocations || (SymbolLocations = {}));
|
|
16
13
|
//# sourceMappingURL=SymbolLocations.js.map
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" />
|
|
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 (`/`).
|
|
@@ -45,25 +39,13 @@ export declare namespace fileUtil {
|
|
|
45
39
|
* @returns The part from the last `/` to the end of the URI.
|
|
46
40
|
*/
|
|
47
41
|
function basename(uri: string): string;
|
|
48
|
-
|
|
49
|
-
* @param fileUri A file URI.
|
|
50
|
-
* @returns The corresponding file path of the `fileUri` in platform-specific format.
|
|
51
|
-
* @throws If the URI is not a file schema URI.
|
|
52
|
-
*/
|
|
53
|
-
function fileUriToPath(fileUri: string): string;
|
|
54
|
-
/**
|
|
55
|
-
* @param path A file path.
|
|
56
|
-
* @returns The corresponding file URI of the `path`.
|
|
57
|
-
*/
|
|
58
|
-
function pathToFileUri(path: string): string;
|
|
59
|
-
function normalize(uri: string): string;
|
|
60
|
-
function getParentOfFile(path: PathLike): PathLike;
|
|
42
|
+
function getParentOfFile(externals: Externals, path: FsLocation): FsLocation;
|
|
61
43
|
/**
|
|
62
44
|
* @throws
|
|
63
45
|
*
|
|
64
46
|
* @param mode Default to `0o777` (`rwxrwxrwx`)
|
|
65
47
|
*/
|
|
66
|
-
function ensureDir(path:
|
|
48
|
+
function ensureDir(externals: Externals, path: FsLocation, mode?: number): Promise<void>;
|
|
67
49
|
/**
|
|
68
50
|
* @throws
|
|
69
51
|
*
|
|
@@ -71,11 +53,11 @@ export declare namespace fileUtil {
|
|
|
71
53
|
*
|
|
72
54
|
* @param mode Default to `0o777` (`rwxrwxrwx`)
|
|
73
55
|
*/
|
|
74
|
-
function ensureParentOfFile(path:
|
|
75
|
-
function chmod(path:
|
|
76
|
-
function ensureWritable(path:
|
|
77
|
-
function markReadOnly(path:
|
|
78
|
-
function readFile(path:
|
|
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>;
|
|
79
61
|
/**
|
|
80
62
|
* @throws
|
|
81
63
|
*
|
|
@@ -88,44 +70,32 @@ export declare namespace fileUtil {
|
|
|
88
70
|
* * Mode: `0o666` (`rw-rw-rw-`)
|
|
89
71
|
* * Flag: `w`
|
|
90
72
|
*/
|
|
91
|
-
function writeFile(path:
|
|
73
|
+
function writeFile(externals: Externals, path: FsLocation, data: Uint8Array | string, mode?: number): Promise<void>;
|
|
92
74
|
/**
|
|
93
75
|
* @throws
|
|
94
76
|
*/
|
|
95
|
-
function readJson
|
|
77
|
+
function readJson(externals: Externals, path: FsLocation): Promise<unknown>;
|
|
96
78
|
/**
|
|
97
79
|
* @throws
|
|
98
80
|
*
|
|
99
81
|
* @see {@link writeFile}
|
|
100
82
|
*/
|
|
101
|
-
function writeJson(path:
|
|
83
|
+
function writeJson(externals: Externals, path: FsLocation, data: any): Promise<void>;
|
|
102
84
|
/**
|
|
103
85
|
* @throws
|
|
104
86
|
*/
|
|
105
|
-
function readGzippedFile(path:
|
|
87
|
+
function readGzippedFile(externals: Externals, path: FsLocation): Promise<Uint8Array>;
|
|
106
88
|
/**
|
|
107
89
|
* @throws
|
|
108
90
|
*/
|
|
109
|
-
function writeGzippedFile(path:
|
|
91
|
+
function writeGzippedFile(externals: Externals, path: FsLocation, buffer: Uint8Array | string): Promise<void>;
|
|
110
92
|
/**
|
|
111
93
|
* @throws
|
|
112
94
|
*/
|
|
113
|
-
function readGzippedJson
|
|
95
|
+
function readGzippedJson(externals: Externals, path: FsLocation): Promise<unknown>;
|
|
114
96
|
/**
|
|
115
97
|
* @throws
|
|
116
98
|
*/
|
|
117
|
-
function writeGzippedJson(path:
|
|
118
|
-
/**
|
|
119
|
-
* Show the file/directory in the platform-specific explorer program.
|
|
120
|
-
*
|
|
121
|
-
* Should not be called with unsanitized user-input path due to the possibility of
|
|
122
|
-
* arbitrary code execution.
|
|
123
|
-
*
|
|
124
|
-
* @returns The `stdout` from the spawned child process.
|
|
125
|
-
*/
|
|
126
|
-
function showFile(path: string): Promise<{
|
|
127
|
-
stdout: string;
|
|
128
|
-
stderr: string;
|
|
129
|
-
}>;
|
|
99
|
+
function writeGzippedJson(externals: Externals, path: FsLocation, data: any): Promise<void>;
|
|
130
100
|
}
|
|
131
101
|
//# sourceMappingURL=fileUtil.d.ts.map
|
package/lib/service/fileUtil.js
CHANGED
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.fileUtil = void 0;
|
|
30
|
-
const child_process_1 = __importDefault(require("child_process"));
|
|
31
|
-
const fs_1 = require("fs");
|
|
32
|
-
const path_1 = require("path");
|
|
33
|
-
const process_1 = __importDefault(require("process"));
|
|
34
|
-
const url_1 = __importStar(require("url"));
|
|
35
|
-
const util_1 = require("util");
|
|
36
|
-
const zlib_1 = __importDefault(require("zlib"));
|
|
37
|
-
const common_1 = require("../common");
|
|
38
|
-
var fileUtil;
|
|
1
|
+
import { bufferToString, Uri } from '../common/index.js';
|
|
2
|
+
export var fileUtil;
|
|
39
3
|
(function (fileUtil) {
|
|
40
4
|
/**
|
|
41
5
|
* @param rootUris The root URIs. Each URI in this array must end with a slash (`/`).
|
|
@@ -106,53 +70,8 @@ var fileUtil;
|
|
|
106
70
|
}
|
|
107
71
|
fileUtil.basename = basename;
|
|
108
72
|
/* istanbul ignore next */
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
* @returns The corresponding file path of the `fileUri` in platform-specific format.
|
|
112
|
-
* @throws If the URI is not a file schema URI.
|
|
113
|
-
*/
|
|
114
|
-
function fileUriToPath(fileUri) {
|
|
115
|
-
return url_1.default.fileURLToPath(new url_1.URL(fileUri));
|
|
116
|
-
}
|
|
117
|
-
fileUtil.fileUriToPath = fileUriToPath;
|
|
118
|
-
/* istanbul ignore next */
|
|
119
|
-
/**
|
|
120
|
-
* @param path A file path.
|
|
121
|
-
* @returns The corresponding file URI of the `path`.
|
|
122
|
-
*/
|
|
123
|
-
function pathToFileUri(path) {
|
|
124
|
-
return url_1.default.pathToFileURL(path).toString();
|
|
125
|
-
}
|
|
126
|
-
fileUtil.pathToFileUri = pathToFileUri;
|
|
127
|
-
/* istanbul ignore next */
|
|
128
|
-
function normalize(uri) {
|
|
129
|
-
try {
|
|
130
|
-
return isFileUri(uri) ? pathToFileUri(fileUriToPath(uri)) : new url_1.URL(uri).toString();
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
return uri;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
fileUtil.normalize = normalize;
|
|
137
|
-
/**
|
|
138
|
-
* @param path A string file path, string file URI, or a file URI object.
|
|
139
|
-
*
|
|
140
|
-
* @returns A {@link fs.PathLike}.
|
|
141
|
-
*/
|
|
142
|
-
function toFsPathLike(path) {
|
|
143
|
-
if (typeof path === 'string' && isFileUri(path)) {
|
|
144
|
-
return new url_1.URL(path);
|
|
145
|
-
}
|
|
146
|
-
return path;
|
|
147
|
-
}
|
|
148
|
-
/* istanbul ignore next */
|
|
149
|
-
function getParentOfFile(path) {
|
|
150
|
-
if (path instanceof url_1.URL || isFileUri(path)) {
|
|
151
|
-
return new url_1.URL('.', path);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
return (0, path_1.resolve)(path, '..');
|
|
155
|
-
}
|
|
73
|
+
function getParentOfFile(externals, path) {
|
|
74
|
+
return new Uri('.', path);
|
|
156
75
|
}
|
|
157
76
|
fileUtil.getParentOfFile = getParentOfFile;
|
|
158
77
|
/* istanbul ignore next */
|
|
@@ -161,12 +80,12 @@ var fileUtil;
|
|
|
161
80
|
*
|
|
162
81
|
* @param mode Default to `0o777` (`rwxrwxrwx`)
|
|
163
82
|
*/
|
|
164
|
-
async function ensureDir(path, mode = 0o777) {
|
|
83
|
+
async function ensureDir(externals, path, mode = 0o777) {
|
|
165
84
|
try {
|
|
166
|
-
await
|
|
85
|
+
await externals.fs.mkdir(path, { mode, recursive: true });
|
|
167
86
|
}
|
|
168
87
|
catch (e) {
|
|
169
|
-
if (!
|
|
88
|
+
if (!externals.error.isKind(e, 'EEXIST')) {
|
|
170
89
|
throw e;
|
|
171
90
|
}
|
|
172
91
|
}
|
|
@@ -180,31 +99,31 @@ var fileUtil;
|
|
|
180
99
|
*
|
|
181
100
|
* @param mode Default to `0o777` (`rwxrwxrwx`)
|
|
182
101
|
*/
|
|
183
|
-
async function ensureParentOfFile(path, mode = 0o777) {
|
|
184
|
-
return ensureDir(getParentOfFile(path), mode);
|
|
102
|
+
async function ensureParentOfFile(externals, path, mode = 0o777) {
|
|
103
|
+
return ensureDir(externals, getParentOfFile(externals, path), mode);
|
|
185
104
|
}
|
|
186
105
|
fileUtil.ensureParentOfFile = ensureParentOfFile;
|
|
187
|
-
async function chmod(path, mode) {
|
|
188
|
-
return
|
|
106
|
+
async function chmod(externals, path, mode) {
|
|
107
|
+
return externals.fs.chmod(path, mode);
|
|
189
108
|
}
|
|
190
109
|
fileUtil.chmod = chmod;
|
|
191
|
-
async function ensureWritable(path) {
|
|
110
|
+
async function ensureWritable(externals, path) {
|
|
192
111
|
try {
|
|
193
|
-
await chmod(path, 0o666);
|
|
112
|
+
await chmod(externals, path, 0o666);
|
|
194
113
|
}
|
|
195
114
|
catch (e) {
|
|
196
|
-
if (!(
|
|
115
|
+
if (!externals.error.isKind(e, 'ENOENT')) {
|
|
197
116
|
throw e;
|
|
198
117
|
}
|
|
199
118
|
}
|
|
200
119
|
}
|
|
201
120
|
fileUtil.ensureWritable = ensureWritable;
|
|
202
|
-
async function markReadOnly(path) {
|
|
203
|
-
return chmod(path, 0o444);
|
|
121
|
+
async function markReadOnly(externals, path) {
|
|
122
|
+
return chmod(externals, path, 0o444);
|
|
204
123
|
}
|
|
205
124
|
fileUtil.markReadOnly = markReadOnly;
|
|
206
|
-
async function readFile(path) {
|
|
207
|
-
return
|
|
125
|
+
async function readFile(externals, path) {
|
|
126
|
+
return externals.fs.readFile(path);
|
|
208
127
|
}
|
|
209
128
|
fileUtil.readFile = readFile;
|
|
210
129
|
/* istanbul ignore next */
|
|
@@ -220,18 +139,18 @@ var fileUtil;
|
|
|
220
139
|
* * Mode: `0o666` (`rw-rw-rw-`)
|
|
221
140
|
* * Flag: `w`
|
|
222
141
|
*/
|
|
223
|
-
async function writeFile(path, data, mode = 0o666) {
|
|
224
|
-
await ensureParentOfFile(path);
|
|
225
|
-
await ensureWritable(path);
|
|
226
|
-
return
|
|
142
|
+
async function writeFile(externals, path, data, mode = 0o666) {
|
|
143
|
+
await ensureParentOfFile(externals, path);
|
|
144
|
+
await ensureWritable(externals, path);
|
|
145
|
+
return externals.fs.writeFile(path, data, { mode });
|
|
227
146
|
}
|
|
228
147
|
fileUtil.writeFile = writeFile;
|
|
229
148
|
/* istanbul ignore next */
|
|
230
149
|
/**
|
|
231
150
|
* @throws
|
|
232
151
|
*/
|
|
233
|
-
async function readJson(path) {
|
|
234
|
-
return JSON.parse(
|
|
152
|
+
async function readJson(externals, path) {
|
|
153
|
+
return JSON.parse(bufferToString(await readFile(externals, path)));
|
|
235
154
|
}
|
|
236
155
|
fileUtil.readJson = readJson;
|
|
237
156
|
/* istanbul ignore next */
|
|
@@ -240,64 +159,40 @@ var fileUtil;
|
|
|
240
159
|
*
|
|
241
160
|
* @see {@link writeFile}
|
|
242
161
|
*/
|
|
243
|
-
async function writeJson(path, data) {
|
|
244
|
-
return writeFile(path, JSON.stringify(data));
|
|
162
|
+
async function writeJson(externals, path, data) {
|
|
163
|
+
return writeFile(externals, path, JSON.stringify(data));
|
|
245
164
|
}
|
|
246
165
|
fileUtil.writeJson = writeJson;
|
|
247
166
|
/**
|
|
248
167
|
* @throws
|
|
249
168
|
*/
|
|
250
|
-
async function readGzippedFile(path) {
|
|
251
|
-
|
|
252
|
-
return unzip(await readFile(path));
|
|
169
|
+
async function readGzippedFile(externals, path) {
|
|
170
|
+
return externals.archive.gunzip(await readFile(externals, path));
|
|
253
171
|
}
|
|
254
172
|
fileUtil.readGzippedFile = readGzippedFile;
|
|
255
173
|
/**
|
|
256
174
|
* @throws
|
|
257
175
|
*/
|
|
258
|
-
async function writeGzippedFile(path, buffer) {
|
|
259
|
-
|
|
260
|
-
|
|
176
|
+
async function writeGzippedFile(externals, path, buffer) {
|
|
177
|
+
if (typeof buffer === 'string') {
|
|
178
|
+
buffer = new TextEncoder().encode(buffer);
|
|
179
|
+
}
|
|
180
|
+
return writeFile(externals, path, await externals.archive.gzip(buffer));
|
|
261
181
|
}
|
|
262
182
|
fileUtil.writeGzippedFile = writeGzippedFile;
|
|
263
183
|
/**
|
|
264
184
|
* @throws
|
|
265
185
|
*/
|
|
266
|
-
async function readGzippedJson(path) {
|
|
267
|
-
return JSON.parse(
|
|
186
|
+
async function readGzippedJson(externals, path) {
|
|
187
|
+
return JSON.parse(bufferToString(await readGzippedFile(externals, path)));
|
|
268
188
|
}
|
|
269
189
|
fileUtil.readGzippedJson = readGzippedJson;
|
|
270
190
|
/**
|
|
271
191
|
* @throws
|
|
272
192
|
*/
|
|
273
|
-
async function writeGzippedJson(path, data) {
|
|
274
|
-
return writeGzippedFile(path, JSON.stringify(data));
|
|
193
|
+
async function writeGzippedJson(externals, path, data) {
|
|
194
|
+
return writeGzippedFile(externals, path, JSON.stringify(data));
|
|
275
195
|
}
|
|
276
196
|
fileUtil.writeGzippedJson = writeGzippedJson;
|
|
277
|
-
|
|
278
|
-
* Show the file/directory in the platform-specific explorer program.
|
|
279
|
-
*
|
|
280
|
-
* Should not be called with unsanitized user-input path due to the possibility of
|
|
281
|
-
* arbitrary code execution.
|
|
282
|
-
*
|
|
283
|
-
* @returns The `stdout` from the spawned child process.
|
|
284
|
-
*/
|
|
285
|
-
async function showFile(path) {
|
|
286
|
-
const execFile = (0, util_1.promisify)(child_process_1.default.execFile);
|
|
287
|
-
let command;
|
|
288
|
-
switch (process_1.default.platform) {
|
|
289
|
-
case 'darwin':
|
|
290
|
-
command = 'open';
|
|
291
|
-
break;
|
|
292
|
-
case 'win32':
|
|
293
|
-
command = 'explorer';
|
|
294
|
-
break;
|
|
295
|
-
default:
|
|
296
|
-
command = 'xdg-open';
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
return execFile(command, [path]);
|
|
300
|
-
}
|
|
301
|
-
fileUtil.showFile = showFile;
|
|
302
|
-
})(fileUtil = exports.fileUtil || (exports.fileUtil = {}));
|
|
197
|
+
})(fileUtil || (fileUtil = {}));
|
|
303
198
|
//# sourceMappingURL=fileUtil.js.map
|