-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathdump_server_state.ts
More file actions
38 lines (34 loc) · 1.09 KB
/
dump_server_state.ts
File metadata and controls
38 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {
ExtensionContext,
StatusBarItem,
Uri,
ViewColumn,
window,
} from "vscode";
import { LanguageClient } from "vscode-languageclient/node";
import * as fs from "fs";
import { createFileInTempDir } from "../utils";
export async function dumpServerState(
client: LanguageClient,
_context?: ExtensionContext,
_statusBarItem?: StatusBarItem,
) {
try {
const result = await client.sendRequest("rescript/dumpServerState");
const outputFile = createFileInTempDir("server_state", ".json");
// Pretty-print JSON with stable ordering where possible
const replacer = (_key: string, value: any) => {
if (value instanceof Map) return Object.fromEntries(value);
if (value instanceof Set) return Array.from(value);
return value;
};
const json = JSON.stringify(result, replacer, 2);
fs.writeFileSync(outputFile, json, { encoding: "utf-8" });
await window.showTextDocument(Uri.parse(outputFile), {
viewColumn: ViewColumn.Beside,
preview: false,
});
} catch (e) {
window.showErrorMessage(`Failed to dump server state: ${String(e)}`);
}
}