diff --git a/vscode/package.json b/vscode/package.json index bdac55e77..53b7fed20 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -138,6 +138,11 @@ "title": "Show syntax tree", "category": "Ruby LSP" }, + { + "command": "rubyLsp.diagnoseState", + "title": "Diagnose language server state", + "category": "Ruby LSP" + }, { "command": "rubyLsp.railsGenerate", "title": "Rails generate", diff --git a/vscode/src/common.ts b/vscode/src/common.ts index 32ef885e2..805db65f1 100644 --- a/vscode/src/common.ts +++ b/vscode/src/common.ts @@ -20,6 +20,7 @@ export enum Command { RunTestInTerminal = "rubyLsp.runTestInTerminal", DebugTest = "rubyLsp.debugTest", ShowSyntaxTree = "rubyLsp.showSyntaxTree", + DiagnoseState = "rubyLsp.diagnoseState", DisplayAddons = "rubyLsp.displayAddons", RunTask = "rubyLsp.runTask", BundleInstall = "rubyLsp.bundleInstall", diff --git a/vscode/src/documentProvider.ts b/vscode/src/documentProvider.ts index 4d413a43a..ca9df743b 100644 --- a/vscode/src/documentProvider.ts +++ b/vscode/src/documentProvider.ts @@ -12,6 +12,9 @@ export default class DocumentProvider case "show-syntax-tree": response = uri.query; break; + case "show-diagnose-state": + response = uri.query; + break; } return response; diff --git a/vscode/src/rubyLsp.ts b/vscode/src/rubyLsp.ts index 88266bc2c..c4a373aa7 100644 --- a/vscode/src/rubyLsp.ts +++ b/vscode/src/rubyLsp.ts @@ -264,6 +264,10 @@ export class RubyLsp { Command.ShowSyntaxTree, this.showSyntaxTree.bind(this), ), + vscode.commands.registerCommand( + Command.DiagnoseState, + this.diagnoseState.bind(this), + ), vscode.commands.registerCommand(Command.ShowServerChangelog, () => { const version = this.currentActiveWorkspace()?.lspClient?.serverVersion; @@ -779,6 +783,48 @@ export class RubyLsp { return this.getWorkspace(workspaceFolder.uri); } + private async diagnoseState() { + const workspace = await this.showWorkspacePick(); + + const response: + | { + workerAlive: boolean; + backtrace: string[]; + documents: { uri: string; source: string }; + incomingQueueSize: number; + } + | null + | undefined = await workspace?.lspClient?.sendRequest( + "rubyLsp/diagnoseState", + ); + + if (response) { + const documentData = Object.entries(response.documents); + const information = [ + `Worker alive: ${response.workerAlive}`, + `Incoming queue size: ${response.incomingQueueSize}`, + `Backtrace:\n${response.backtrace.join("\n")}\n`, + `=========== Documents (${documentData.length}) ===========`, + ...documentData.map( + ([uri, source]) => `URI: ${uri}\n\n${source}\n===========`, + ), + ].join("\n"); + + const document = await vscode.workspace.openTextDocument( + vscode.Uri.from({ + scheme: "ruby-lsp", + path: "show-diagnose-state", + query: information, + }), + ); + + await vscode.window.showTextDocument(document, { + viewColumn: vscode.ViewColumn.Beside, + preserveFocus: true, + }); + } + } + // Show syntax tree command private async showSyntaxTree() { const activeEditor = vscode.window.activeTextEditor;