@volar/test-utils 2.0.0-alpha.8 → 2.0.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/index.d.ts +4 -1
- package/index.js +103 -4
- package/package.json +4 -3
package/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import * as _ from '@volar/language-server/node';
|
|
4
3
|
import * as cp from 'child_process';
|
|
5
4
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
@@ -36,3 +35,7 @@ export declare function startLanguageServer(serverModule: string, cwd?: string |
|
|
|
36
35
|
sendDocumentLinkRequest(uri: string): Promise<_.DocumentLink[] | null>;
|
|
37
36
|
sendDocumentLinkResolveRequest(link: _.DocumentLink): Promise<_.DocumentLink>;
|
|
38
37
|
};
|
|
38
|
+
export declare function printSnapshots(sourceFile: _.SourceFile): Generator<string, void, unknown>;
|
|
39
|
+
export declare function printSnapshot(sourceFile: {
|
|
40
|
+
snapshot: _.SourceFile['snapshot'];
|
|
41
|
+
}, file: _.VirtualCode): Generator<string, void, unknown>;
|
package/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.startLanguageServer = void 0;
|
|
3
|
+
exports.printSnapshot = exports.printSnapshots = exports.startLanguageServer = void 0;
|
|
4
4
|
const _ = require("@volar/language-server/node");
|
|
5
5
|
const assert = require("assert");
|
|
6
6
|
const cp = require("child_process");
|
|
7
7
|
const fs = require("fs");
|
|
8
8
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
9
9
|
const vscode_uri_1 = require("vscode-uri");
|
|
10
|
+
const language_core_1 = require("@volar/language-core");
|
|
10
11
|
function startLanguageServer(serverModule, cwd) {
|
|
11
12
|
const childProcess = cp.fork(serverModule, ['--node-ipc', `--clientProcessId=${process.pid.toString()}`], {
|
|
12
13
|
execArgv: ['--nolazy'],
|
|
@@ -17,9 +18,9 @@ function startLanguageServer(serverModule, cwd) {
|
|
|
17
18
|
const openedDocuments = new Map();
|
|
18
19
|
let untitledCounter = 0;
|
|
19
20
|
connection.listen();
|
|
20
|
-
connection.onClose(
|
|
21
|
-
connection.onUnhandledNotification(
|
|
22
|
-
connection.onError(
|
|
21
|
+
connection.onClose(e => console.log(e));
|
|
22
|
+
connection.onUnhandledNotification(e => console.log(e));
|
|
23
|
+
connection.onError(e => console.log(e));
|
|
23
24
|
connection.onDispose(() => {
|
|
24
25
|
childProcess.kill();
|
|
25
26
|
});
|
|
@@ -219,4 +220,102 @@ function startLanguageServer(serverModule, cwd) {
|
|
|
219
220
|
};
|
|
220
221
|
}
|
|
221
222
|
exports.startLanguageServer = startLanguageServer;
|
|
223
|
+
function* printSnapshots(sourceFile) {
|
|
224
|
+
if (sourceFile.generated) {
|
|
225
|
+
let lastId = 0;
|
|
226
|
+
for (const file of (0, language_core_1.forEachEmbeddedCode)(sourceFile.generated.code)) {
|
|
227
|
+
const id = lastId++;
|
|
228
|
+
yield `#${id}`;
|
|
229
|
+
for (const line of printSnapshot(sourceFile, file)) {
|
|
230
|
+
yield ' ' + line;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
exports.printSnapshots = printSnapshots;
|
|
236
|
+
function* printSnapshot(sourceFile, file) {
|
|
237
|
+
const sourceCode = sourceFile.snapshot.getText(0, sourceFile.snapshot.getLength());
|
|
238
|
+
const sourceFileDocument = vscode_languageserver_textdocument_1.TextDocument.create('', '', 0, sourceCode);
|
|
239
|
+
const virtualCode = file.snapshot.getText(0, file.snapshot.getLength());
|
|
240
|
+
const virtualCodeLines = virtualCode.split('\n');
|
|
241
|
+
for (let i = 0; i < virtualCodeLines.length - 2; i++) {
|
|
242
|
+
virtualCodeLines[i] += '\n';
|
|
243
|
+
}
|
|
244
|
+
let lineOffset = 0;
|
|
245
|
+
const map = new language_core_1.SourceMap(file.mappings);
|
|
246
|
+
for (let i = 0; i < virtualCodeLines.length; i++) {
|
|
247
|
+
const line = virtualCodeLines[i];
|
|
248
|
+
const lineHead = `[${i + 1}]`;
|
|
249
|
+
yield [lineHead, normalizeLogText(line)].join(' ');
|
|
250
|
+
const logs = [];
|
|
251
|
+
for (let offset = 0; offset < line.length; offset++) {
|
|
252
|
+
for (const [sourceOffset, mapping] of map.getSourceOffsets(lineOffset + offset)) {
|
|
253
|
+
let log = logs.find(log => log.mapping === mapping && log.lineOffset + log.length + 1 === offset);
|
|
254
|
+
if (log) {
|
|
255
|
+
log.length++;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
log = {
|
|
259
|
+
mapping,
|
|
260
|
+
line,
|
|
261
|
+
lineOffset: offset,
|
|
262
|
+
sourceOffset: sourceOffset,
|
|
263
|
+
generatedOffset: offset,
|
|
264
|
+
length: 0,
|
|
265
|
+
};
|
|
266
|
+
logs.push(log);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
for (const log of logs.reverse()) {
|
|
271
|
+
const sourcePosition = sourceFileDocument.positionAt(log.sourceOffset);
|
|
272
|
+
const spanText = log.length === 0 ? '^' : '~'.repeat(log.length);
|
|
273
|
+
const prefix = ' '.repeat(lineHead.length);
|
|
274
|
+
const sourceLineEnd = sourceFileDocument.offsetAt({ line: sourcePosition.line + 1, character: 0 }) - 1;
|
|
275
|
+
const sourceLine = sourceFileDocument.getText().substring(sourceFileDocument.offsetAt({ line: sourcePosition.line, character: 0 }), sourceLineEnd + 1);
|
|
276
|
+
const sourceLineHead = `[${sourcePosition.line + 1}]`;
|
|
277
|
+
yield [
|
|
278
|
+
prefix,
|
|
279
|
+
' '.repeat(log.lineOffset),
|
|
280
|
+
spanText,
|
|
281
|
+
].join(' ');
|
|
282
|
+
if (log.line === sourceLine) {
|
|
283
|
+
yield [
|
|
284
|
+
prefix,
|
|
285
|
+
' '.repeat(log.lineOffset),
|
|
286
|
+
sourceLineHead,
|
|
287
|
+
'(exact match)',
|
|
288
|
+
`(${log.mapping.source
|
|
289
|
+
+ ':' + (sourcePosition.line + 1)
|
|
290
|
+
+ ':' + (sourcePosition.character + 1)})`,
|
|
291
|
+
].join(' ');
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
yield [
|
|
295
|
+
prefix,
|
|
296
|
+
' '.repeat(log.lineOffset),
|
|
297
|
+
sourceLineHead,
|
|
298
|
+
normalizeLogText(sourceLine),
|
|
299
|
+
`(${log.mapping.source
|
|
300
|
+
+ ':' + (sourcePosition.line + 1)
|
|
301
|
+
+ ':' + (sourcePosition.character + 1)})`,
|
|
302
|
+
].join(' ');
|
|
303
|
+
yield [
|
|
304
|
+
prefix,
|
|
305
|
+
' '.repeat(log.lineOffset),
|
|
306
|
+
' '.repeat(sourceLineHead.length),
|
|
307
|
+
' '.repeat(sourcePosition.character) + spanText,
|
|
308
|
+
].join(' ');
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
lineOffset += line.length;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
exports.printSnapshot = printSnapshot;
|
|
315
|
+
function normalizeLogText(text) {
|
|
316
|
+
return text
|
|
317
|
+
.replace(/\t/g, '→')
|
|
318
|
+
.replace(/\n/g, '↵')
|
|
319
|
+
.replace(/ /g, '·');
|
|
320
|
+
}
|
|
222
321
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/test-utils",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
"@types/node": "latest"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@volar/language-
|
|
18
|
+
"@volar/language-core": "2.0.0",
|
|
19
|
+
"@volar/language-server": "2.0.0",
|
|
19
20
|
"vscode-languageserver-textdocument": "^1.0.11",
|
|
20
21
|
"vscode-uri": "^3.0.8"
|
|
21
22
|
},
|
|
22
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "95217136d2727bb7304443d91cfde3dbe711369c"
|
|
23
24
|
}
|