Skip to content

Commit

Permalink
Add VS Code command to collect issue reporting data (#2456)
Browse files Browse the repository at this point in the history
* Add command to collect Ruby LSP information for issue reporting

- Implement `collectRubyLspInfo` function in new `infoCollector.ts` file
- Add new command `rubyLsp.collectRubyLspInfo` in `package.json`
- Register the new command in `rubyLsp.ts`
- Collect and display information including:
  - VS Code version
  - Ruby LSP extension version
  - Ruby LSP server version
  - Installed Ruby LSP addons
  - Ruby version and version manager
  - Installed public VS Code extensions

This feature will help users and maintainers quickly gather relevant information
for reporting Ruby LSP related issues. The collected information is displayed
in the output channel for easy copying and pasting into GitHub issues.

* Collect rubyLsp settings as well
  • Loading branch information
st0012 authored Aug 21, 2024
1 parent dfdf4db commit 980440b
Show file tree
Hide file tree
Showing 4 changed files with 184 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 @@ -140,6 +140,11 @@
"title": "Ruby file operations",
"category": "Ruby LSP",
"icon": "$(ruby)"
},
{
"command": "rubyLsp.collectRubyLspInfo",
"title": "Collect Ruby LSP Information for Issue Reporting",
"category": "Ruby LSP"
}
],
"configuration": {
Expand Down
1 change: 1 addition & 0 deletions vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export enum Command {
RailsGenerate = "rubyLsp.railsGenerate",
RailsDestroy = "rubyLsp.railsDestroy",
NewMinitestFile = "rubyLsp.newMinitestFile",
CollectRubyLspInfo = "rubyLsp.collectRubyLspInfo",
}

export interface RubyInterface {
Expand Down
173 changes: 173 additions & 0 deletions vscode/src/infoCollector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import * as vscode from "vscode";

import { Workspace } from "./workspace";

export async function collectRubyLspInfo(workspace: Workspace | undefined) {
if (!workspace) {
await vscode.window.showErrorMessage("No active Ruby workspace found.");
return;
}

const lspInfo = await gatherLspInfo(workspace);
const panel = vscode.window.createWebviewPanel(
"rubyLspInfo",
"Ruby LSP Information",
vscode.ViewColumn.One,
{ enableScripts: true },
);

panel.webview.html = generateRubyLspInfoReport(lspInfo);
}

async function gatherLspInfo(
workspace: Workspace,
): Promise<Record<string, string | string[] | Record<string, unknown>>> {
const vscodeVersion = vscode.version;
const rubyLspExtension = vscode.extensions.getExtension("Shopify.ruby-lsp")!;
const rubyLspExtensionVersion = rubyLspExtension.packageJSON.version;
const rubyLspVersion = workspace.lspClient?.serverVersion ?? "Unknown";
const rubyLspAddons =
workspace.lspClient?.addons?.map((addon) => addon.name) ?? [];
const extensions = await getPublicExtensions();

// Fetch rubyLsp settings
const workspaceSettings = vscode.workspace.getConfiguration(
"rubyLsp",
workspace.workspaceFolder,
);
const userSettings = vscode.workspace.getConfiguration("rubyLsp");

// Get only the workspace-specific settings
const workspaceSpecificSettings: Record<string, unknown> = {};
for (const key of Object.keys(workspaceSettings)) {
if (workspaceSettings.inspect(key)?.workspaceValue !== undefined) {
workspaceSpecificSettings[key] = workspaceSettings.get(key);
}
}

return {
/* eslint-disable @typescript-eslint/naming-convention */
"VS Code Version": vscodeVersion,
"Ruby LSP Extension Version": rubyLspExtensionVersion,
"Ruby LSP Server Version": rubyLspVersion,
"Ruby LSP Addons": rubyLspAddons,
"Ruby Version": workspace.ruby.rubyVersion ?? "Unknown",
"Ruby Version Manager": workspace.ruby.versionManager.identifier,
"Installed Extensions": extensions,
"Ruby LSP Settings": {
Workspace: workspaceSpecificSettings,
User: userSettings,
},
/* eslint-enable @typescript-eslint/naming-convention */
};
}

async function getPublicExtensions(): Promise<string[]> {
return vscode.extensions.all
.filter((ext) => {
// Filter out built-in extensions
if (ext.packageJSON.isBuiltin) {
return false;
}

// Assume if an extension doesn't have a license, it's private and should not be listed
if (
ext.packageJSON.license === "UNLICENSED" ||
!ext.packageJSON.license
) {
return false;
}

return true;
})
.map((ext) => `${ext.packageJSON.name} (${ext.packageJSON.version})`);
}

function generateRubyLspInfoReport(
info: Record<string, string | string[] | Record<string, unknown>>,
): string {
let markdown = "\n### Ruby LSP Information\n\n";

for (const [key, value] of Object.entries(info)) {
markdown += `#### ${key}\n\n`;
if (Array.isArray(value)) {
if (key === "Installed Extensions") {
markdown +=
"&lt;details&gt;\n&lt;summary&gt;Click to expand&lt;/summary&gt;\n\n";
markdown += `${value.map((val) => `- ${val}`).join("\n")}\n`;
markdown += "&lt;/details&gt;\n";
} else {
markdown += `${value.map((val) => `- ${val}`).join("\n")}\n`;
}
} else if (typeof value === "object" && value !== null) {
markdown +=
"&lt;details&gt;\n&lt;summary&gt;Click to expand&lt;/summary&gt;\n\n";
for (const [subKey, subValue] of Object.entries(value)) {
markdown += `##### ${subKey}\n\n`;
markdown += `\`\`\`json\n${JSON.stringify(subValue, null, 2)}\n\`\`\`\n\n`;
}
markdown += "&lt;/details&gt;\n";
} else {
markdown += `${value}\n`;
}
markdown += "\n";
}

const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ruby LSP Information</title>
<style>
body { font-family: var(--vscode-font-family); padding: 20px; }
h1, h2, h3, p, li { color: var(--vscode-editor-foreground); }
pre {
background-color: var(--vscode-textBlockQuote-background);
padding: 16px;
overflow-x: auto;
position: relative;
}
code { font-family: var(--vscode-editor-font-family); }
#copyButton {
position: absolute;
top: 5px;
right: 5px;
background-color: var(--vscode-button-background);
color: var(--vscode-button-foreground);
border: none;
padding: 5px 10px;
cursor: pointer;
}
#copyButton:hover { background-color: var(--vscode-button-hoverBackground); }
</style>
</head>
<body>
<h1>Ruby LSP Information</h1>
<p>Please copy the content below and paste it into the issue you're opening:</p>
<pre><button id="copyButton">Copy</button><code id="diagnosticContent">${markdown}</code></pre>
<script>
const copyButton = document.getElementById('copyButton');
const diagnosticContent = document.getElementById('diagnosticContent');
copyButton.addEventListener('click', () => {
const range = document.createRange();
range.selectNode(diagnosticContent);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
copyButton.textContent = 'Copied!';
setTimeout(() => {
copyButton.textContent = 'Copy';
}, 2000);
});
</script>
</body>
</html>
`;

return html;
}
5 changes: 5 additions & 0 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Debugger } from "./debugger";
import { DependenciesTree } from "./dependenciesTree";
import { Rails } from "./rails";
import { ChatAgent } from "./chatAgent";
import { collectRubyLspInfo } from "./infoCollector";

// The RubyLsp class represents an instance of the entire extension. This should only be instantiated once at the
// activation event. One instance of this class controls all of the existing workspaces, telemetry and handles all
Expand Down Expand Up @@ -570,6 +571,10 @@ export class RubyLsp {
await vscode.commands.executeCommand(pick.command, ...pick.args);
}),
vscode.commands.registerCommand(Command.NewMinitestFile, newMinitestFile),
vscode.commands.registerCommand(Command.CollectRubyLspInfo, async () => {
const workspace = await this.showWorkspacePick();
await collectRubyLspInfo(workspace);
}),
);
}

Expand Down

0 comments on commit 980440b

Please sign in to comment.