Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

- Find `@rescript/runtime` for Rewatch compiler-args call. https://github.com/rescript-lang/rescript-vscode/pull/1125
- Use `prepareRename` command (when a new enough ReScript version is used) to speed up the `rename` command. https://github.com/rescript-lang/rescript-vscode/pull/1124
- Use `compiler-info.json` to find the `@rescript/runtime` and `bsc.exe` if available.
- Use `compiler-info.json` to find the `@rescript/runtime` and `bsc.exe` if available. https://github.com/rescript-lang/rescript-vscode/pull/1129
- Add `Dump LSP Server State` command to client. https://github.com/rescript-lang/rescript-vscode/pull/1130

## 1.64.0

Expand Down
1 change: 1 addition & 0 deletions client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export { createInterface } from "./commands/create_interface";
export { openCompiled } from "./commands/open_compiled";
export { switchImplIntf } from "./commands/switch_impl_intf";
export { dumpDebug, dumpDebugRetrigger } from "./commands/dump_debug";
export { dumpServerState } from "./commands/dump_server_state";

export const codeAnalysisWithReanalyze = (
targetDir: string | null,
Expand Down
38 changes: 38 additions & 0 deletions client/src/commands/dump_server_state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)}`);
}
}
4 changes: 4 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ export function activate(context: ExtensionContext) {
customCommands.dumpDebug(context, debugDumpStatusBarItem);
});

commands.registerCommand("rescript-vscode.dump-server-state", () => {
customCommands.dumpServerState(client, context, debugDumpStatusBarItem);
});

commands.registerCommand("rescript-vscode.showProblems", async () => {
try {
await commands.executeCommand("workbench.actions.view.problems");
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
{
"command": "rescript-vscode.debug-dump-start",
"title": "DEBUG ReScript: Dump analysis info"
},
{
"command": "rescript-vscode.dump-server-state",
"title": "DEBUG ReScript: Dump LSP Server State"
}
],
"keybindings": [
Expand Down
44 changes: 44 additions & 0 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,50 @@ async function onMessage(msg: p.Message) {
if (extName === c.resExt) {
send(await signatureHelp(msg));
}
} else if (msg.method === "rescript/dumpServerState") {
// Custom debug endpoint: dump current server state (config + projectsFiles)
try {
const projects = Array.from(projectsFiles.entries()).map(
([projectRootPath, pf]) => ({
projectRootPath,
openFiles: Array.from(pf.openFiles),
filesWithDiagnostics: Array.from(pf.filesWithDiagnostics),
filesDiagnostics: pf.filesDiagnostics,
rescriptVersion: pf.rescriptVersion,
bscBinaryLocation: pf.bscBinaryLocation,
editorAnalysisLocation: pf.editorAnalysisLocation,
namespaceName: pf.namespaceName,
hasPromptedToStartBuild: pf.hasPromptedToStartBuild,
bsbWatcherByEditor:
pf.bsbWatcherByEditor != null
? { pid: pf.bsbWatcherByEditor.pid ?? null }
: null,
}),
);

const result = {
config: config.extensionConfiguration,
projects,
workspaceFolders: Array.from(workspaceFolders),
};

let response: p.ResponseMessage = {
jsonrpc: c.jsonrpcVersion,
id: msg.id,
result,
};
send(response);
} catch (e) {
let response: p.ResponseMessage = {
jsonrpc: c.jsonrpcVersion,
id: msg.id,
error: {
code: p.ErrorCodes.InternalError,
message: `Failed to dump server state: ${String(e)}`,
},
};
send(response);
}
} else {
let response: p.ResponseMessage = {
jsonrpc: c.jsonrpcVersion,
Expand Down
Loading