@volar/test-utils 2.4.0-alpha.9 → 2.4.1
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 +1 -1
- package/index.d.ts +4 -2
- package/index.js +20 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ The returned server handle provides several methods to interact with the languag
|
|
|
18
18
|
|
|
19
19
|
- `initialize(rootUri: string, initializationOptions: InitializationOptions)`: Initializes the language server.
|
|
20
20
|
- `openTextDocument(fileName: string, languageId: string)`: Opens a text document.
|
|
21
|
-
- `openUntitledDocument(
|
|
21
|
+
- `openUntitledDocument(languageId: string, content: string)`: Opens an untitled text document.
|
|
22
22
|
- `closeTextDocument(uri: string)`: Closes a text document.
|
|
23
23
|
- Various `send*Request` methods: Send language-related requests to the server.
|
|
24
24
|
|
package/index.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ export type LanguageServerHandle = ReturnType<typeof startLanguageServer>;
|
|
|
6
6
|
export declare function startLanguageServer(serverModule: string, cwd?: string | URL): {
|
|
7
7
|
process: cp.ChildProcess;
|
|
8
8
|
connection: _.ProtocolConnection;
|
|
9
|
-
initialize(rootUri: string, initializationOptions: _._InitializeParams["initializationOptions"], capabilities?: _.ClientCapabilities, locale?: string): Promise<_.InitializeResult<any>>;
|
|
9
|
+
initialize(rootUri: string | _.WorkspaceFolder[], initializationOptions: _._InitializeParams["initializationOptions"], capabilities?: _.ClientCapabilities, locale?: string): Promise<_.InitializeResult<any>>;
|
|
10
10
|
shutdown(): Promise<void>;
|
|
11
11
|
openTextDocument(fileName: string, languageId: string): Promise<TextDocument>;
|
|
12
|
-
openUntitledDocument(
|
|
12
|
+
openUntitledDocument(languageId: string, content: string): Promise<TextDocument>;
|
|
13
13
|
openInMemoryDocument(uri: string, languageId: string, content: string): Promise<TextDocument>;
|
|
14
14
|
closeTextDocument(uri: string): Promise<void>;
|
|
15
15
|
updateTextDocument(uri: string, edits: _.TextEdit[]): Promise<TextDocument>;
|
|
@@ -39,6 +39,8 @@ export declare function startLanguageServer(serverModule: string, cwd?: string |
|
|
|
39
39
|
sendColorPresentationRequest(uri: string, color: _.Color, range: _.Range): Promise<_.ColorPresentation[]>;
|
|
40
40
|
sendDocumentLinkRequest(uri: string): Promise<_.DocumentLink[] | null>;
|
|
41
41
|
sendDocumentLinkResolveRequest(link: _.DocumentLink): Promise<_.DocumentLink>;
|
|
42
|
+
sendInlayHintRequest(uri: string, range: _.Range): Promise<_.InlayHint[] | null>;
|
|
43
|
+
sendInlayHintResolveRequest(hint: _.InlayHint): Promise<_.InlayHint>;
|
|
42
44
|
};
|
|
43
45
|
export declare function printSnapshots(sourceScript: _.SourceScript<URI>): Generator<string, void, unknown>;
|
|
44
46
|
export declare function printSnapshot(sourceScript: {
|
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ function startLanguageServer(serverModule, cwd) {
|
|
|
18
18
|
stdio: 'pipe',
|
|
19
19
|
});
|
|
20
20
|
const connection = _.createProtocolConnection(childProcess.stdout, childProcess.stdin);
|
|
21
|
+
const documentVersions = new Map();
|
|
21
22
|
const openedDocuments = new Map();
|
|
22
23
|
const settings = {};
|
|
23
24
|
let untitledCounter = 0;
|
|
@@ -50,7 +51,8 @@ function startLanguageServer(serverModule, cwd) {
|
|
|
50
51
|
async initialize(rootUri, initializationOptions, capabilities = {}, locale) {
|
|
51
52
|
const result = await connection.sendRequest(_.InitializeRequest.type, {
|
|
52
53
|
processId: childProcess.pid ?? null,
|
|
53
|
-
rootUri,
|
|
54
|
+
rootUri: typeof rootUri === 'string' ? rootUri : null,
|
|
55
|
+
workspaceFolders: Array.isArray(rootUri) ? rootUri : null,
|
|
54
56
|
initializationOptions,
|
|
55
57
|
capabilities,
|
|
56
58
|
locale,
|
|
@@ -67,7 +69,8 @@ function startLanguageServer(serverModule, cwd) {
|
|
|
67
69
|
async openTextDocument(fileName, languageId) {
|
|
68
70
|
const uri = vscode_uri_1.URI.file(fileName).toString();
|
|
69
71
|
if (!openedDocuments.has(uri)) {
|
|
70
|
-
const document = vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, 0, fs.readFileSync(fileName, 'utf-8'));
|
|
72
|
+
const document = vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, (documentVersions.get(uri) ?? 0) + 1, fs.readFileSync(fileName, 'utf-8'));
|
|
73
|
+
documentVersions.set(uri, document.version);
|
|
71
74
|
openedDocuments.set(uri, document);
|
|
72
75
|
await connection.sendNotification(_.DidOpenTextDocumentNotification.type, {
|
|
73
76
|
textDocument: {
|
|
@@ -80,9 +83,10 @@ function startLanguageServer(serverModule, cwd) {
|
|
|
80
83
|
}
|
|
81
84
|
return openedDocuments.get(uri);
|
|
82
85
|
},
|
|
83
|
-
async openUntitledDocument(
|
|
86
|
+
async openUntitledDocument(languageId, content) {
|
|
84
87
|
const uri = vscode_uri_1.URI.from({ scheme: 'untitled', path: `Untitled-${untitledCounter++}` }).toString();
|
|
85
|
-
const document = vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, 0, content);
|
|
88
|
+
const document = vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, (documentVersions.get(uri) ?? 0) + 1, content);
|
|
89
|
+
documentVersions.set(uri, document.version);
|
|
86
90
|
openedDocuments.set(uri, document);
|
|
87
91
|
await connection.sendNotification(_.DidOpenTextDocumentNotification.type, {
|
|
88
92
|
textDocument: {
|
|
@@ -99,7 +103,8 @@ function startLanguageServer(serverModule, cwd) {
|
|
|
99
103
|
if (oldDocument) {
|
|
100
104
|
await this.closeTextDocument(uri);
|
|
101
105
|
}
|
|
102
|
-
const document = vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, (
|
|
106
|
+
const document = vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, (documentVersions.get(uri) ?? 0) + 1, content);
|
|
107
|
+
documentVersions.set(uri, document.version);
|
|
103
108
|
openedDocuments.set(uri, document);
|
|
104
109
|
await connection.sendNotification(_.DidOpenTextDocumentNotification.type, {
|
|
105
110
|
textDocument: {
|
|
@@ -123,6 +128,7 @@ function startLanguageServer(serverModule, cwd) {
|
|
|
123
128
|
assert(document);
|
|
124
129
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
125
130
|
document = vscode_languageserver_textdocument_1.TextDocument.create(uri, document.languageId, document.version + 1, newText);
|
|
131
|
+
documentVersions.set(uri, document.version);
|
|
126
132
|
openedDocuments.set(uri, document);
|
|
127
133
|
await connection.sendNotification(_.DidChangeTextDocumentNotification.type, {
|
|
128
134
|
textDocument: {
|
|
@@ -279,6 +285,15 @@ function startLanguageServer(serverModule, cwd) {
|
|
|
279
285
|
sendDocumentLinkResolveRequest(link) {
|
|
280
286
|
return connection.sendRequest(_.DocumentLinkResolveRequest.type, link);
|
|
281
287
|
},
|
|
288
|
+
sendInlayHintRequest(uri, range) {
|
|
289
|
+
return connection.sendRequest(_.InlayHintRequest.type, {
|
|
290
|
+
textDocument: { uri },
|
|
291
|
+
range,
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
sendInlayHintResolveRequest(hint) {
|
|
295
|
+
return connection.sendRequest(_.InlayHintResolveRequest.type, hint);
|
|
296
|
+
},
|
|
282
297
|
};
|
|
283
298
|
function getConfiguration(section) {
|
|
284
299
|
if (section in settings) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/test-utils",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"@types/node": "latest"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@volar/language-core": "2.4.
|
|
19
|
-
"@volar/language-server": "2.4.
|
|
18
|
+
"@volar/language-core": "2.4.1",
|
|
19
|
+
"@volar/language-server": "2.4.1",
|
|
20
20
|
"vscode-languageserver-textdocument": "^1.0.11",
|
|
21
21
|
"vscode-uri": "^3.0.8"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "b920b6c4a3e4b2d8f46c676ea414e94c437cb5b7"
|
|
24
24
|
}
|