|
| 1 | +import { injectable } from 'inversify'; |
| 2 | +import { DebugError } from '@theia/debug/lib/common/debug-service'; |
| 3 | +import { DebugSession } from '@theia/debug/lib/browser/debug-session'; |
| 4 | +import { DebugSessionOptions } from '@theia/debug/lib/browser/debug-session-options'; |
| 5 | +import { DebugSessionManager as TheiaDebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager'; |
| 6 | + |
| 7 | +@injectable() |
| 8 | +export class DebugSessionManager extends TheiaDebugSessionManager { |
| 9 | + |
| 10 | + async start(options: DebugSessionOptions): Promise<DebugSession | undefined> { |
| 11 | + return this.progressService.withProgress('Start...', 'debug', async () => { |
| 12 | + try { |
| 13 | + // Only save when dirty. To avoid saving temporary sketches. |
| 14 | + // This is a quick fix for not saving the editor when there are no dirty editors. |
| 15 | + // // https://github.com/bcmi-labs/arduino-editor/pull/172#issuecomment-741831888 |
| 16 | + if (this.shell.canSaveAll()) { |
| 17 | + await this.shell.saveAll(); |
| 18 | + } |
| 19 | + await this.fireWillStartDebugSession(); |
| 20 | + const resolved = await this.resolveConfiguration(options); |
| 21 | + |
| 22 | + // preLaunchTask isn't run in case of auto restart as well as postDebugTask |
| 23 | + if (!options.configuration.__restart) { |
| 24 | + const taskRun = await this.runTask(options.workspaceFolderUri, resolved.configuration.preLaunchTask, true); |
| 25 | + if (!taskRun) { |
| 26 | + return undefined; |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + const sessionId = await this.debug.createDebugSession(resolved.configuration); |
| 31 | + return this.doStart(sessionId, resolved); |
| 32 | + } catch (e) { |
| 33 | + if (DebugError.NotFound.is(e)) { |
| 34 | + this.messageService.error(`The debug session type "${e.data.type}" is not supported.`); |
| 35 | + return undefined; |
| 36 | + } |
| 37 | + |
| 38 | + this.messageService.error('There was an error starting the debug session, check the logs for more details.'); |
| 39 | + console.error('Error starting the debug session', e); |
| 40 | + throw e; |
| 41 | + } |
| 42 | + }); |
| 43 | + } |
| 44 | + |
| 45 | +} |
0 commit comments