Skip to content

Commit 980440b

Browse files
authored
Add VS Code command to collect issue reporting data (#2456)
* 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
1 parent dfdf4db commit 980440b

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed

vscode/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@
140140
"title": "Ruby file operations",
141141
"category": "Ruby LSP",
142142
"icon": "$(ruby)"
143+
},
144+
{
145+
"command": "rubyLsp.collectRubyLspInfo",
146+
"title": "Collect Ruby LSP Information for Issue Reporting",
147+
"category": "Ruby LSP"
143148
}
144149
],
145150
"configuration": {

vscode/src/common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export enum Command {
2626
RailsGenerate = "rubyLsp.railsGenerate",
2727
RailsDestroy = "rubyLsp.railsDestroy",
2828
NewMinitestFile = "rubyLsp.newMinitestFile",
29+
CollectRubyLspInfo = "rubyLsp.collectRubyLspInfo",
2930
}
3031

3132
export interface RubyInterface {

vscode/src/infoCollector.ts

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
import * as vscode from "vscode";
2+
3+
import { Workspace } from "./workspace";
4+
5+
export async function collectRubyLspInfo(workspace: Workspace | undefined) {
6+
if (!workspace) {
7+
await vscode.window.showErrorMessage("No active Ruby workspace found.");
8+
return;
9+
}
10+
11+
const lspInfo = await gatherLspInfo(workspace);
12+
const panel = vscode.window.createWebviewPanel(
13+
"rubyLspInfo",
14+
"Ruby LSP Information",
15+
vscode.ViewColumn.One,
16+
{ enableScripts: true },
17+
);
18+
19+
panel.webview.html = generateRubyLspInfoReport(lspInfo);
20+
}
21+
22+
async function gatherLspInfo(
23+
workspace: Workspace,
24+
): Promise<Record<string, string | string[] | Record<string, unknown>>> {
25+
const vscodeVersion = vscode.version;
26+
const rubyLspExtension = vscode.extensions.getExtension("Shopify.ruby-lsp")!;
27+
const rubyLspExtensionVersion = rubyLspExtension.packageJSON.version;
28+
const rubyLspVersion = workspace.lspClient?.serverVersion ?? "Unknown";
29+
const rubyLspAddons =
30+
workspace.lspClient?.addons?.map((addon) => addon.name) ?? [];
31+
const extensions = await getPublicExtensions();
32+
33+
// Fetch rubyLsp settings
34+
const workspaceSettings = vscode.workspace.getConfiguration(
35+
"rubyLsp",
36+
workspace.workspaceFolder,
37+
);
38+
const userSettings = vscode.workspace.getConfiguration("rubyLsp");
39+
40+
// Get only the workspace-specific settings
41+
const workspaceSpecificSettings: Record<string, unknown> = {};
42+
for (const key of Object.keys(workspaceSettings)) {
43+
if (workspaceSettings.inspect(key)?.workspaceValue !== undefined) {
44+
workspaceSpecificSettings[key] = workspaceSettings.get(key);
45+
}
46+
}
47+
48+
return {
49+
/* eslint-disable @typescript-eslint/naming-convention */
50+
"VS Code Version": vscodeVersion,
51+
"Ruby LSP Extension Version": rubyLspExtensionVersion,
52+
"Ruby LSP Server Version": rubyLspVersion,
53+
"Ruby LSP Addons": rubyLspAddons,
54+
"Ruby Version": workspace.ruby.rubyVersion ?? "Unknown",
55+
"Ruby Version Manager": workspace.ruby.versionManager.identifier,
56+
"Installed Extensions": extensions,
57+
"Ruby LSP Settings": {
58+
Workspace: workspaceSpecificSettings,
59+
User: userSettings,
60+
},
61+
/* eslint-enable @typescript-eslint/naming-convention */
62+
};
63+
}
64+
65+
async function getPublicExtensions(): Promise<string[]> {
66+
return vscode.extensions.all
67+
.filter((ext) => {
68+
// Filter out built-in extensions
69+
if (ext.packageJSON.isBuiltin) {
70+
return false;
71+
}
72+
73+
// Assume if an extension doesn't have a license, it's private and should not be listed
74+
if (
75+
ext.packageJSON.license === "UNLICENSED" ||
76+
!ext.packageJSON.license
77+
) {
78+
return false;
79+
}
80+
81+
return true;
82+
})
83+
.map((ext) => `${ext.packageJSON.name} (${ext.packageJSON.version})`);
84+
}
85+
86+
function generateRubyLspInfoReport(
87+
info: Record<string, string | string[] | Record<string, unknown>>,
88+
): string {
89+
let markdown = "\n### Ruby LSP Information\n\n";
90+
91+
for (const [key, value] of Object.entries(info)) {
92+
markdown += `#### ${key}\n\n`;
93+
if (Array.isArray(value)) {
94+
if (key === "Installed Extensions") {
95+
markdown +=
96+
"&lt;details&gt;\n&lt;summary&gt;Click to expand&lt;/summary&gt;\n\n";
97+
markdown += `${value.map((val) => `- ${val}`).join("\n")}\n`;
98+
markdown += "&lt;/details&gt;\n";
99+
} else {
100+
markdown += `${value.map((val) => `- ${val}`).join("\n")}\n`;
101+
}
102+
} else if (typeof value === "object" && value !== null) {
103+
markdown +=
104+
"&lt;details&gt;\n&lt;summary&gt;Click to expand&lt;/summary&gt;\n\n";
105+
for (const [subKey, subValue] of Object.entries(value)) {
106+
markdown += `##### ${subKey}\n\n`;
107+
markdown += `\`\`\`json\n${JSON.stringify(subValue, null, 2)}\n\`\`\`\n\n`;
108+
}
109+
markdown += "&lt;/details&gt;\n";
110+
} else {
111+
markdown += `${value}\n`;
112+
}
113+
markdown += "\n";
114+
}
115+
116+
const html = `
117+
<!DOCTYPE html>
118+
<html lang="en">
119+
<head>
120+
<meta charset="UTF-8">
121+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
122+
<title>Ruby LSP Information</title>
123+
<style>
124+
body { font-family: var(--vscode-font-family); padding: 20px; }
125+
h1, h2, h3, p, li { color: var(--vscode-editor-foreground); }
126+
pre {
127+
background-color: var(--vscode-textBlockQuote-background);
128+
padding: 16px;
129+
overflow-x: auto;
130+
position: relative;
131+
}
132+
code { font-family: var(--vscode-editor-font-family); }
133+
#copyButton {
134+
position: absolute;
135+
top: 5px;
136+
right: 5px;
137+
background-color: var(--vscode-button-background);
138+
color: var(--vscode-button-foreground);
139+
border: none;
140+
padding: 5px 10px;
141+
cursor: pointer;
142+
}
143+
#copyButton:hover { background-color: var(--vscode-button-hoverBackground); }
144+
</style>
145+
</head>
146+
<body>
147+
<h1>Ruby LSP Information</h1>
148+
<p>Please copy the content below and paste it into the issue you're opening:</p>
149+
<pre><button id="copyButton">Copy</button><code id="diagnosticContent">${markdown}</code></pre>
150+
<script>
151+
const copyButton = document.getElementById('copyButton');
152+
const diagnosticContent = document.getElementById('diagnosticContent');
153+
154+
copyButton.addEventListener('click', () => {
155+
const range = document.createRange();
156+
range.selectNode(diagnosticContent);
157+
window.getSelection().removeAllRanges();
158+
window.getSelection().addRange(range);
159+
document.execCommand('copy');
160+
window.getSelection().removeAllRanges();
161+
162+
copyButton.textContent = 'Copied!';
163+
setTimeout(() => {
164+
copyButton.textContent = 'Copy';
165+
}, 2000);
166+
});
167+
</script>
168+
</body>
169+
</html>
170+
`;
171+
172+
return html;
173+
}

vscode/src/rubyLsp.ts

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Debugger } from "./debugger";
1717
import { DependenciesTree } from "./dependenciesTree";
1818
import { Rails } from "./rails";
1919
import { ChatAgent } from "./chatAgent";
20+
import { collectRubyLspInfo } from "./infoCollector";
2021

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

0 commit comments

Comments
 (0)