Skip to content

Commit

Permalink
Add command to show LSP's internal state for diagnosing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Feb 13, 2025
1 parent 139c44a commit 651a9de
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions vscode/src/documentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 46 additions & 0 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,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;

Expand Down Expand Up @@ -744,6 +748,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;
Expand Down

0 comments on commit 651a9de

Please sign in to comment.