| 63 | |
| 64 | debuggerVscodeApi.debug.registerDebugAdapterDescriptorFactory('javascript', { |
| 65 | async createDebugAdapterDescriptor() { |
| 66 | const websocket = new WebSocket('ws://localhost:5555') |
| 67 | |
| 68 | await new Promise((resolve, reject) => { |
| 69 | websocket.onopen = resolve |
| 70 | websocket.onerror = () => |
| 71 | reject(new Error('Unable to connect to debugger server. Run `npm run start:debugServer`')) |
| 72 | }) |
| 73 | |
| 74 | websocket.send( |
| 75 | JSON.stringify({ |
| 76 | main: '/workspace/test.js', |
| 77 | files: { |
| 78 | '/workspace/test.js': new TextDecoder().decode( |
| 79 | await debuggerVscodeApi.workspace.fs.readFile( |
| 80 | debuggerVscodeApi.Uri.file('/workspace/test.js') |
| 81 | ) |
| 82 | ) |
| 83 | } |
| 84 | }) |
| 85 | ) |
| 86 | |
| 87 | const adapter = new WebsocketDebugAdapter(websocket) |
| 88 | |
| 89 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 90 | adapter.onDidSendMessage((message: any) => { |
| 91 | if (message.type === 'event' && message.event === 'output') { |
| 92 | console.log('OUTPUT', message.body.output) |
| 93 | } |
| 94 | }) |
| 95 | return new debuggerVscodeApi.DebugAdapterInlineImplementation(adapter) |
| 96 | } |
| 97 | }) |
| 98 | }) |