Skip to main content
Glama
debugBridge.ts4.44 kB
import * as vscode from 'vscode'; /** * Bridge class that handles actual VSCode debugging operations * This runs within the VSCode extension context and has access to all VSCode APIs */ export class DebugBridge { private static instance: DebugBridge; static getInstance(): DebugBridge { if (!DebugBridge.instance) { DebugBridge.instance = new DebugBridge(); } return DebugBridge.instance; } async addBreakpoint(filePath: string, lineNumber: number, condition?: string): Promise<boolean> { try { const uri = vscode.Uri.file(filePath); const position = new vscode.Position(lineNumber - 1, 0); const location = new vscode.Location(uri, position); const breakpoint = new vscode.SourceBreakpoint(location, true, condition); vscode.debug.addBreakpoints([breakpoint]); return true; } catch (error) { console.error('Failed to add breakpoint:', error); return false; } } async removeBreakpoint(filePath: string, lineNumber: number): Promise<boolean> { try { const uri = vscode.Uri.file(filePath); const breakpoints = vscode.debug.breakpoints; const toRemove = breakpoints.filter((bp: vscode.Breakpoint) => { if (bp instanceof vscode.SourceBreakpoint) { return bp.location.uri.fsPath === uri.fsPath && bp.location.range.start.line === lineNumber - 1; } return false; }); if (toRemove.length > 0) { vscode.debug.removeBreakpoints(toRemove); return true; } return false; } catch (error) { console.error('Failed to remove breakpoint:', error); return false; } } async startDebugging(configurationName?: string, workspaceFolderPath?: string): Promise<boolean> { try { let workspaceFolder: vscode.WorkspaceFolder | undefined; if (workspaceFolderPath) { const uri = vscode.Uri.file(workspaceFolderPath); workspaceFolder = vscode.workspace.getWorkspaceFolder(uri); } else { workspaceFolder = vscode.workspace.workspaceFolders?.[0]; } if (!workspaceFolder) { throw new Error('No workspace folder found'); } // Get debug configurations const configurations = vscode.workspace.getConfiguration('launch', workspaceFolder.uri); const launchConfig = configurations.get('configurations') as any[]; let debugConfig: any; if (configurationName) { debugConfig = launchConfig?.find(config => config.name === configurationName); if (!debugConfig) { throw new Error(`Debug configuration '${configurationName}' not found`); } } else { debugConfig = launchConfig?.[0]; if (!debugConfig) { throw new Error('No debug configurations found'); } } const success = await vscode.debug.startDebugging(workspaceFolder, debugConfig); return success; } catch (error) { console.error('Failed to start debugging:', error); return false; } } async stopDebugging(sessionId?: string): Promise<boolean> { try { if (sessionId) { const session = vscode.debug.activeDebugSession; if (session && session.id === sessionId) { await vscode.debug.stopDebugging(session); return true; } else { return false; } } else { const session = vscode.debug.activeDebugSession; if (session) { await vscode.debug.stopDebugging(session); return true; } else { return false; } } } catch (error) { console.error('Failed to stop debugging:', error); return false; } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/davidfirst/vscode-mcp-debugger'

If you have feedback or need assistance with the MCP directory API, please join our Discord server