Skip to content

Commit 3e9c3ed

Browse files
authored
Add command to show LSP's internal state for diagnosing issues (#3195)
Add command to show LSP's internal state for diagnosing issues (#3195) ### Motivation Add a command to trigger the new custom diagnose request, so that it's easy to see the information at a glance. ### Implementation It's the same implementation as show syntax tree, we use a custom resource to show a read-only document containing the relevant information. ### Manual Tests 1. Launch the extension on this branch 2. On the second VS Code window, open the Ruby LSP code itself (you need the server changes to verify all pieces together) 3. Invoke the new command 4. Verify you see the internal state of the server Co-authored-by: vinistock <[email protected]>
1 parent 0cf2dba commit 3e9c3ed

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

vscode/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@
138138
"title": "Show syntax tree",
139139
"category": "Ruby LSP"
140140
},
141+
{
142+
"command": "rubyLsp.diagnoseState",
143+
"title": "Diagnose language server state",
144+
"category": "Ruby LSP"
145+
},
141146
{
142147
"command": "rubyLsp.railsGenerate",
143148
"title": "Rails generate",

vscode/src/common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export enum Command {
2020
RunTestInTerminal = "rubyLsp.runTestInTerminal",
2121
DebugTest = "rubyLsp.debugTest",
2222
ShowSyntaxTree = "rubyLsp.showSyntaxTree",
23+
DiagnoseState = "rubyLsp.diagnoseState",
2324
DisplayAddons = "rubyLsp.displayAddons",
2425
RunTask = "rubyLsp.runTask",
2526
BundleInstall = "rubyLsp.bundleInstall",

vscode/src/documentProvider.ts

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export default class DocumentProvider
1212
case "show-syntax-tree":
1313
response = uri.query;
1414
break;
15+
case "show-diagnose-state":
16+
response = uri.query;
17+
break;
1518
}
1619

1720
return response;

vscode/src/rubyLsp.ts

+46
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ export class RubyLsp {
264264
Command.ShowSyntaxTree,
265265
this.showSyntaxTree.bind(this),
266266
),
267+
vscode.commands.registerCommand(
268+
Command.DiagnoseState,
269+
this.diagnoseState.bind(this),
270+
),
267271
vscode.commands.registerCommand(Command.ShowServerChangelog, () => {
268272
const version = this.currentActiveWorkspace()?.lspClient?.serverVersion;
269273

@@ -779,6 +783,48 @@ export class RubyLsp {
779783
return this.getWorkspace(workspaceFolder.uri);
780784
}
781785

786+
private async diagnoseState() {
787+
const workspace = await this.showWorkspacePick();
788+
789+
const response:
790+
| {
791+
workerAlive: boolean;
792+
backtrace: string[];
793+
documents: { uri: string; source: string };
794+
incomingQueueSize: number;
795+
}
796+
| null
797+
| undefined = await workspace?.lspClient?.sendRequest(
798+
"rubyLsp/diagnoseState",
799+
);
800+
801+
if (response) {
802+
const documentData = Object.entries(response.documents);
803+
const information = [
804+
`Worker alive: ${response.workerAlive}`,
805+
`Incoming queue size: ${response.incomingQueueSize}`,
806+
`Backtrace:\n${response.backtrace.join("\n")}\n`,
807+
`=========== Documents (${documentData.length}) ===========`,
808+
...documentData.map(
809+
([uri, source]) => `URI: ${uri}\n\n${source}\n===========`,
810+
),
811+
].join("\n");
812+
813+
const document = await vscode.workspace.openTextDocument(
814+
vscode.Uri.from({
815+
scheme: "ruby-lsp",
816+
path: "show-diagnose-state",
817+
query: information,
818+
}),
819+
);
820+
821+
await vscode.window.showTextDocument(document, {
822+
viewColumn: vscode.ViewColumn.Beside,
823+
preserveFocus: true,
824+
});
825+
}
826+
}
827+
782828
// Show syntax tree command
783829
private async showSyntaxTree() {
784830
const activeEditor = vscode.window.activeTextEditor;

0 commit comments

Comments
 (0)