Skip to content

Commit 6b8bf79

Browse files
authored
1 parent 517a9fd commit 6b8bf79

File tree

9 files changed

+41
-16
lines changed

9 files changed

+41
-16
lines changed

packages/databricks-vscode/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@
346346
},
347347
{
348348
"command": "databricks.run.runEditorContentsAsWorkflow",
349-
"when": "resourceLangId == python || resourceExtname == .ipynb",
349+
"when": "resourceLangId == python || resourceLangId == scala || resourceLangId == r || resourceLangId == sql || resourceExtname == .ipynb",
350350
"group": "navigation@1"
351351
}
352352
],
@@ -464,7 +464,10 @@
464464
{
465465
"type": "databricks-workflow",
466466
"languages": [
467-
"python"
467+
"python",
468+
"sql",
469+
"r",
470+
"scala"
468471
],
469472
"label": "Databricks Workflow",
470473
"configurationAttributes": {
@@ -666,4 +669,4 @@
666669
],
667670
"report-dir": "coverage"
668671
}
669-
}
672+
}

packages/databricks-vscode/src/configuration/ConnectionCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export class ConnectionCommands implements Disposable {
231231
alwaysShow: true,
232232
detail: workspaceConfigs.enableFilesInWorkspace
233233
? ""
234-
: `Open Databricks in the browser and create a new repo under /Repo/${me}`,
234+
: `Open Databricks in the browser and create a new Repo under /Repo/${me}`,
235235
},
236236
{
237237
label: "",

packages/databricks-vscode/src/configuration/ConnectionManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ export class ConnectionManager {
376376
this.databricksWorkspace === undefined
377377
) {
378378
throw new Error(
379-
"Can't attach a Repo when profile is not connected"
379+
"Can't attach a Sync Destination when profile is not connected"
380380
);
381381
}
382382
if (!(await SyncDestination.validateRemote(this, workspacePath))) {

packages/databricks-vscode/src/configuration/SyncDestination.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class SyncDestination {
157157
localToRemoteNotebook(localPath: Uri): string {
158158
assert.equal(localPath.scheme, "file");
159159
return this.localToRemote(localPath).replace(
160-
/^\/Workspace(\/.*)\.(py|ipynb)/g,
160+
/^\/Workspace(\/.*)\.(py|ipynb|scala|r|sql)/g,
161161
"$1"
162162
);
163163
}

packages/databricks-vscode/src/run/DatabricksWorkflowDebugAdapter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {Subject} from "./Subject";
2525
import {WorkflowRunner} from "./WorkflowRunner";
2626
import {promptForClusterStart} from "./prompts";
2727
import {CodeSynchronizer} from "../sync/CodeSynchronizer";
28+
import {isNotebook} from "../utils";
2829

2930
/**
3031
* This interface describes the mock-debug specific launch attributes
@@ -154,6 +155,13 @@ export class DatabricksWorkflowDebugSession extends LoggingDebugSession {
154155
parameters: Record<string, string>,
155156
args: Array<string>
156157
): Promise<void> {
158+
if (
159+
!(await isNotebook(Uri.file(program))) &&
160+
!program.endsWith(".py")
161+
) {
162+
return this.onError("Only Python files can be run as a workflow");
163+
}
164+
157165
if (this.connection.state === "CONNECTING") {
158166
await this.connection.waitForConnect();
159167
}

packages/databricks-vscode/src/run/RunCommands.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ export class RunCommands {
3434
if (this.connection.syncDestination === undefined) {
3535
await promptForAttachingSyncDest(async () => {
3636
window.showErrorMessage(
37-
"Execution cancelled because no Databricks Repo is attached"
37+
"Execution cancelled because no Sync Destination is configured"
3838
);
3939
});
4040
if (this.connection.syncDestination === undefined) {
4141
window.showErrorMessage(
42-
"Execution cancelled because no Databricks Repo is attached"
42+
"Execution cancelled because no Sync Destination is configured"
4343
);
4444
return;
4545
}
@@ -73,12 +73,12 @@ export class RunCommands {
7373
if (this.connection.syncDestination === undefined) {
7474
await promptForAttachingSyncDest(async () => {
7575
window.showErrorMessage(
76-
"Execution cancelled because no Databricks Repo is attached"
76+
"Execution cancelled because no Sync Destination is configured"
7777
);
7878
});
7979
if (this.connection.syncDestination === undefined) {
8080
window.showErrorMessage(
81-
"Execution cancelled because no Databricks Repo is attached"
81+
"Execution cancelled because no Sync Destination is configured"
8282
);
8383
return;
8484
}

packages/databricks-vscode/src/run/prompts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ export async function promptForAttachingSyncDest(
3030
onAccept: () => Promise<void> = async () => {}
3131
) {
3232
const response = await window.showErrorMessage(
33-
"Please configure a Databricks Repo for syncing",
34-
"Attach Repo",
33+
"Please configure a Sync Destination",
34+
"Configure Sync Destination",
3535
"Cancel"
3636
);
3737
switch (response) {
38-
case "Attach Repo":
38+
case "Configure Sync Destination":
3939
await commands.executeCommand(
4040
"databricks.connection.attachSyncDestination"
4141
);

packages/databricks-vscode/src/sync/CodeSynchronizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class CodeSynchronizer implements Disposable {
8383

8484
// This function waits for sync to reach WATCHING_FOR_CHANGES which is a
8585
// necessary condition to execute local code on databricks. This state denotes
86-
// all local changes have been synced to remote workspace repo
86+
// all local changes have been synced to remote workspace
8787
async waitForSyncComplete(): Promise<void> {
8888
if (this._state !== "WATCHING_FOR_CHANGES") {
8989
return await new Promise((resolve) => {

packages/databricks-vscode/src/utils/fileUtils.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@ import {TextDecoder} from "util";
22
import {Uri, workspace} from "vscode";
33

44
export async function isNotebook(uri: Uri): Promise<boolean> {
5-
if (uri.path.match(/\.ipynb$/)) {
5+
const ext = uri.path.split(".").pop()?.toLowerCase();
6+
if (!ext) {
7+
return false;
8+
}
9+
10+
if (ext === "ipynb") {
611
return true;
712
}
13+
14+
const comment = {
15+
py: "#",
16+
scala: "//",
17+
sql: "--",
18+
r: "#",
19+
}[ext];
20+
821
const bytes = await workspace.fs.readFile(uri);
922
const lines = new TextDecoder().decode(bytes).split(/\r?\n/);
1023
return (
11-
lines.length > 0 && lines[0].startsWith("# Databricks notebook source")
24+
lines.length > 0 &&
25+
lines[0].startsWith(`${comment} Databricks notebook source`)
1226
);
1327
}

0 commit comments

Comments
 (0)