@volar/test-utils 2.1.3 → 2.1.5

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 (3) hide show
  1. package/index.d.ts +3 -0
  2. package/index.js +58 -0
  3. package/package.json +4 -4
package/index.d.ts CHANGED
@@ -12,6 +12,9 @@ export declare function startLanguageServer(serverModule: string, cwd?: string |
12
12
  openUntitledDocument(content: string, languageId: string): Promise<TextDocument>;
13
13
  openInMemoryDocument(uri: string, languageId: string, content: string): Promise<TextDocument>;
14
14
  closeTextDocument(uri: string): Promise<void>;
15
+ updateTextDocument(uri: string, edits: _.TextEdit[]): Promise<TextDocument>;
16
+ updateConfiguration(newSettings: any): Promise<void>;
17
+ didChangeWatchedFiles(changes: _.FileEvent[]): Promise<void>;
15
18
  sendCompletionRequest(uri: string, position: _.Position): Promise<_.CompletionList | null>;
16
19
  sendCompletionResolveRequest(item: _.CompletionItem): Promise<_.CompletionItem>;
17
20
  sendDocumentDiagnosticRequest(uri: string): Promise<_.DocumentDiagnosticReport>;
package/index.js CHANGED
@@ -16,7 +16,9 @@ function startLanguageServer(serverModule, cwd) {
16
16
  });
17
17
  const connection = _.createProtocolConnection(new _.IPCMessageReader(childProcess), new _.IPCMessageWriter(childProcess));
18
18
  const openedDocuments = new Map();
19
+ const settings = {};
19
20
  let untitledCounter = 0;
21
+ let running = false;
20
22
  connection.listen();
21
23
  connection.onClose(e => console.log(e));
22
24
  connection.onUnhandledNotification(e => console.log(e));
@@ -24,6 +26,13 @@ function startLanguageServer(serverModule, cwd) {
24
26
  connection.onDispose(() => {
25
27
  childProcess.kill();
26
28
  });
29
+ connection.onRequest(_.ConfigurationRequest.type, ({ items }) => {
30
+ return items.map(item => {
31
+ if (item.section) {
32
+ return getConfiguration(item.section);
33
+ }
34
+ });
35
+ });
27
36
  return {
28
37
  process: childProcess,
29
38
  connection,
@@ -36,9 +45,11 @@ function startLanguageServer(serverModule, cwd) {
36
45
  locale,
37
46
  });
38
47
  await connection.sendNotification(_.InitializedNotification.type, {});
48
+ running = true;
39
49
  return result;
40
50
  },
41
51
  async shutdown() {
52
+ running = false;
42
53
  await connection.sendRequest(_.ShutdownRequest.type);
43
54
  openedDocuments.clear();
44
55
  },
@@ -96,6 +107,30 @@ function startLanguageServer(serverModule, cwd) {
96
107
  textDocument: { uri },
97
108
  });
98
109
  },
110
+ async updateTextDocument(uri, edits) {
111
+ let document = openedDocuments.get(uri);
112
+ assert(document);
113
+ const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
114
+ document = vscode_languageserver_textdocument_1.TextDocument.create(uri, document.languageId, document.version + 1, newText);
115
+ openedDocuments.set(uri, document);
116
+ await connection.sendNotification(_.DidChangeTextDocumentNotification.type, {
117
+ textDocument: {
118
+ uri: document.uri,
119
+ version: document.version,
120
+ },
121
+ contentChanges: [{ text: document.getText() }],
122
+ });
123
+ return document;
124
+ },
125
+ async updateConfiguration(newSettings) {
126
+ Object.assign(settings, newSettings);
127
+ if (running) {
128
+ await connection.sendNotification(_.DidChangeConfigurationNotification.type, { settings });
129
+ }
130
+ },
131
+ didChangeWatchedFiles(changes) {
132
+ return connection.sendNotification(_.DidChangeWatchedFilesNotification.type, { changes });
133
+ },
99
134
  async sendCompletionRequest(uri, position) {
100
135
  const result = await connection.sendRequest(_.CompletionRequest.type, {
101
136
  textDocument: { uri },
@@ -234,6 +269,29 @@ function startLanguageServer(serverModule, cwd) {
234
269
  return connection.sendRequest(_.DocumentLinkResolveRequest.type, link);
235
270
  },
236
271
  };
272
+ function getConfiguration(section) {
273
+ if (section in settings) {
274
+ return settings[section];
275
+ }
276
+ let result;
277
+ for (const settingKey in settings) {
278
+ if (settingKey.startsWith(`${section}.`)) {
279
+ const value = settings[settingKey];
280
+ const props = settingKey.substring(section.length + 1).split('.');
281
+ result ??= {};
282
+ let current = result;
283
+ while (props.length > 1) {
284
+ const prop = props.shift();
285
+ if (typeof current[prop] !== 'object') {
286
+ current[prop] = {};
287
+ }
288
+ current = current[prop];
289
+ }
290
+ current[props.shift()] = value;
291
+ }
292
+ }
293
+ return result;
294
+ }
237
295
  }
238
296
  exports.startLanguageServer = startLanguageServer;
239
297
  function* printSnapshots(sourceFile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/test-utils",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
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.1.3",
19
- "@volar/language-server": "2.1.3",
18
+ "@volar/language-core": "2.1.5",
19
+ "@volar/language-server": "2.1.5",
20
20
  "vscode-languageserver-textdocument": "^1.0.11",
21
21
  "vscode-uri": "^3.0.8"
22
22
  },
23
- "gitHead": "0f861d59faa19cbeadef182ee079be88f9629fc7"
23
+ "gitHead": "1b7f456660134891d91608f36cfc6dd2eaea6f70"
24
24
  }