Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to show LSP's internal state for diagnosing issues #3195

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
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 @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Loading