|
| 1 | +import * as vscode from "vscode"; |
| 2 | + |
| 3 | +import { Workspace } from "./workspace"; |
| 4 | + |
| 5 | +export async function diagnoseIssues(workspace: Workspace | undefined) { |
| 6 | + if (!workspace) { |
| 7 | + await vscode.window.showErrorMessage("No active Ruby workspace found."); |
| 8 | + return; |
| 9 | + } |
| 10 | + |
| 11 | + const diagnosticInfo = await collectDiagnosticInfo(workspace); |
| 12 | + const panel = vscode.window.createWebviewPanel( |
| 13 | + "rubyLspDiagnostics", |
| 14 | + "Ruby LSP Diagnostics", |
| 15 | + vscode.ViewColumn.One, |
| 16 | + { enableScripts: true }, |
| 17 | + ); |
| 18 | + |
| 19 | + panel.webview.html = generateDiagnosticsHtml(diagnosticInfo); |
| 20 | +} |
| 21 | + |
| 22 | +async function collectDiagnosticInfo( |
| 23 | + workspace: Workspace, |
| 24 | +): Promise<Record<string, string | string[]>> { |
| 25 | + const vscodeVersion = vscode.version; |
| 26 | + const rubyLspVersion = workspace.lspClient?.serverVersion ?? "Unknown"; |
| 27 | + const rubyLspAddons = |
| 28 | + workspace.lspClient?.addons?.map((addon) => addon.name) ?? []; |
| 29 | + const extensions = await getPublicExtensions(); |
| 30 | + |
| 31 | + return { |
| 32 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 33 | + "VS Code Version": vscodeVersion, |
| 34 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 35 | + "Ruby LSP Version": rubyLspVersion, |
| 36 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 37 | + "Ruby LSP Addons": rubyLspAddons, |
| 38 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 39 | + "Installed Extensions": extensions, |
| 40 | + }; |
| 41 | +} |
| 42 | + |
| 43 | +async function getPublicExtensions(): Promise<string[]> { |
| 44 | + return vscode.extensions.all |
| 45 | + .filter((ext) => { |
| 46 | + // Filter out built-in extensions |
| 47 | + if (ext.packageJSON.isBuiltin) { |
| 48 | + return false; |
| 49 | + } |
| 50 | + |
| 51 | + // Check for marketplace identifier |
| 52 | + const galleryExtension = ext.packageJSON?.extensionPack?.[0] ?? ext.id; |
| 53 | + return galleryExtension.includes("."); |
| 54 | + }) |
| 55 | + .map((ext) => `${ext.packageJSON.name} (${ext.packageJSON.version})`); |
| 56 | +} |
| 57 | + |
| 58 | +function generateDiagnosticsHtml( |
| 59 | + info: Record<string, string | string[]>, |
| 60 | +): string { |
| 61 | + let html = ` |
| 62 | + <!DOCTYPE html> |
| 63 | + <html lang="en"> |
| 64 | + <head> |
| 65 | + <meta charset="UTF-8"> |
| 66 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 67 | + <title>Ruby LSP Diagnostics</title> |
| 68 | + <style> |
| 69 | + body { font-family: var(--vscode-font-family); padding: 20px; } |
| 70 | + h1 { color: var(--vscode-editor-foreground); } |
| 71 | + dl { margin-left: 20px; } |
| 72 | + dt { font-weight: bold; margin-top: 10px; color: var(--vscode-editor-foreground); } |
| 73 | + dd { margin-left: 20px; color: var(--vscode-editor-foreground); } |
| 74 | + </style> |
| 75 | + </head> |
| 76 | + <body> |
| 77 | + <h1>Ruby LSP Diagnostics</h1> |
| 78 | + <dl> |
| 79 | + `; |
| 80 | + |
| 81 | + for (const [key, value] of Object.entries(info)) { |
| 82 | + html += `<dt>${key}:</dt>`; |
| 83 | + if (Array.isArray(value)) { |
| 84 | + html += `<dd><ul>${value.map((val) => `<li>${val}</li>`).join("")}</ul></dd>`; |
| 85 | + } else { |
| 86 | + html += `<dd>${value}</dd>`; |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + html += ` |
| 91 | + </dl> |
| 92 | + </body> |
| 93 | + </html> |
| 94 | + `; |
| 95 | + |
| 96 | + return html; |
| 97 | +} |
0 commit comments