Skip to content

Commit d4bae06

Browse files
1 parent 2ab689f commit d4bae06

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {commands, debug, Uri, window} from "vscode";
22
import {ConnectionManager} from "../configuration/ConnectionManager";
3+
import {isNotebook} from "../utils";
34

45
/**
56
* Run related commands
@@ -14,6 +15,13 @@ export class RunCommands {
1415
return async (resource: Uri) => {
1516
let targetResource = this.getTargetResource(resource);
1617
if (targetResource) {
18+
if (await isNotebook(targetResource)) {
19+
await window.showErrorMessage(
20+
'Use "Run File as Workflow on Databricks" for running notebooks'
21+
);
22+
return;
23+
}
24+
1725
if (this.connection.state === "CONNECTING") {
1826
await this.connection.waitForConnect();
1927
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
workspace,
2020
} from "vscode";
2121
import {SyncDestination} from "../configuration/SyncDestination";
22+
import {isNotebook} from "../utils";
2223

2324
// TODO: add dispose, add persistence, reuse panel
2425

@@ -112,14 +113,6 @@ export async function runAsWorkflow({
112113
}
113114
}
114115

115-
async function isNotebook(uri: Uri): Promise<boolean> {
116-
let bytes = await workspace.fs.readFile(uri);
117-
const lines = new TextDecoder().decode(bytes).split(/\r?\n/);
118-
return (
119-
lines.length > 0 && lines[0].startsWith("# Databricks notebook source")
120-
);
121-
}
122-
123116
export class WorkflowOutputPanel {
124117
private run?: WorkflowRun;
125118
constructor(private panel: WebviewPanel, private extensionUri: Uri) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {TextDecoder} from "util";
2+
import {Uri, workspace} from "vscode";
3+
4+
export async function isNotebook(uri: Uri): Promise<boolean> {
5+
let bytes = await workspace.fs.readFile(uri);
6+
const lines = new TextDecoder().decode(bytes).split(/\r?\n/);
7+
return (
8+
lines.length > 0 && lines[0].startsWith("# Databricks notebook source")
9+
);
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import assert from "assert";
2+
import fs from "fs/promises";
3+
import {withFile} from "tmp-promise";
4+
import {Uri} from "vscode";
5+
import {isNotebook} from "./fileUtils";
6+
7+
describe(__filename, async () => {
8+
it("should detect notebook", async () => {
9+
withFile(async (file) => {
10+
await fs.writeFile(
11+
file.path,
12+
Buffer.from("# Databricks notebook source\ncontent")
13+
);
14+
assert.ok(await isNotebook(Uri.parse(file.path)));
15+
});
16+
});
17+
18+
it("should detect if not notebook", async () => {
19+
withFile(async (file) => {
20+
await fs.writeFile(file.path, Buffer.from("content"));
21+
assert.ok(!(await isNotebook(Uri.parse(file.path))));
22+
});
23+
});
24+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./FileUtils";

0 commit comments

Comments
 (0)