diff --git a/packages/databricks-vscode/package.json b/packages/databricks-vscode/package.json index 7787207a9..e3fbf0eae 100644 --- a/packages/databricks-vscode/package.json +++ b/packages/databricks-vscode/package.json @@ -392,7 +392,8 @@ { "command": "databricks.run.debugEditorContents", "when": "resourceLangId == python" - }, { + }, + { "command": "databricks.run.runEditorContentsAsWorkflow", "when": "resourceLangId == python || resourceExtname == .ipynb" }, diff --git a/packages/databricks-vscode/src/run/DatabricksRuntime.ts b/packages/databricks-vscode/src/run/DatabricksRuntime.ts index 8e21891f5..79d0e50cb 100644 --- a/packages/databricks-vscode/src/run/DatabricksRuntime.ts +++ b/packages/databricks-vscode/src/run/DatabricksRuntime.ts @@ -7,11 +7,13 @@ import { CancellationTokenSource, commands, + debug, Disposable, Event, EventEmitter, ExtensionContext, Uri, + workspace, } from "vscode"; import { @@ -214,6 +216,10 @@ export class DatabricksRuntime implements Disposable { )} ...\n` ); + if (shouldDebug) { + setTimeout(this.attachDebugger.bind(this), 3000); + } + this.state = "EXECUTING"; const response = await executionContext.execute( await this.compileCommandString( @@ -291,6 +297,40 @@ export class DatabricksRuntime implements Disposable { } } + private async attachDebugger() { + // TODO start tunnel process + const mapper = this.connection.syncDestinationMapper; + if (!mapper) { + return; + } + + const workspaceFolder = + workspace.workspaceFolders && workspace.workspaceFolders[0]; + + if (!workspaceFolder) { + return; + } + + const debugConfig = { + type: "python", + name: "Databricks: Remote Attach Debugger", + request: "attach", + connect: { + host: "localhost", + port: 5678, + }, + pathMappings: [ + { + localRoot: workspaceFolder.uri.path, + remoteRoot: mapper.remoteUri.workspacePrefixPath, + }, + ], + justMyCode: true, + }; + + debug.startDebugging(workspaceFolder, debugConfig); + } + private async compileCommandString( program: string, args: Array,