Skip to content

Commit 5f06094

Browse files
committed
Add command to show LSP's internal state for diagnosing issues
1 parent cf32d6a commit 5f06094

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

vscode/package.json

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ export class RubyLsp {
250250
Command.ShowSyntaxTree,
251251
this.showSyntaxTree.bind(this),
252252
),
253+
vscode.commands.registerCommand(
254+
Command.DiagnoseState,
255+
this.diagnoseState.bind(this),
256+
),
253257
vscode.commands.registerCommand(Command.ShowServerChangelog, () => {
254258
const version = this.currentActiveWorkspace()?.lspClient?.serverVersion;
255259

@@ -744,6 +748,48 @@ export class RubyLsp {
744748
return this.getWorkspace(workspaceFolder.uri);
745749
}
746750

751+
private async diagnoseState() {
752+
const workspace = await this.showWorkspacePick();
753+
754+
const response:
755+
| {
756+
workerAlive: boolean;
757+
backtrace: string[];
758+
documents: { uri: string; source: string };
759+
incomingQueueSize: number;
760+
}
761+
| null
762+
| undefined = await workspace?.lspClient?.sendRequest(
763+
"rubyLsp/diagnoseState",
764+
);
765+
766+
if (response) {
767+
const documentData = Object.entries(response.documents);
768+
const information = [
769+
`Worker alive: ${response.workerAlive}`,
770+
`Incoming queue size: ${response.incomingQueueSize}`,
771+
`Backtrace:\n${response.backtrace.join("\n")}\n`,
772+
`=========== Documents (${documentData.length}) ===========`,
773+
...documentData.map(
774+
([uri, source]) => `URI: ${uri}\n\n${source}\n===========`,
775+
),
776+
].join("\n");
777+
778+
const document = await vscode.workspace.openTextDocument(
779+
vscode.Uri.from({
780+
scheme: "ruby-lsp",
781+
path: "show-diagnose-state",
782+
query: information,
783+
}),
784+
);
785+
786+
await vscode.window.showTextDocument(document, {
787+
viewColumn: vscode.ViewColumn.Beside,
788+
preserveFocus: true,
789+
});
790+
}
791+
}
792+
747793
// Show syntax tree command
748794
private async showSyntaxTree() {
749795
const activeEditor = vscode.window.activeTextEditor;

0 commit comments

Comments
 (0)