Skip to content

Commit d1682f9

Browse files
Cleanup redundant commands and fix errors when resetting bundle variables (#1292)
## Changes <!-- Summary of your changes that are easy to understand --> ## Tests <!-- How is this tested? --> --------- Co-authored-by: Ilia Babanov <ilia.babanov@databricks.com>
1 parent ccb96b2 commit d1682f9

File tree

6 files changed

+66
-46
lines changed

6 files changed

+66
-46
lines changed

packages/databricks-vscode/package.json

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"command": "databricks.connection.configureLogin",
6161
"icon": "$(gear)",
6262
"title": "Sign in to Databricks workspace",
63-
"enablement": "databricks.context.activated",
63+
"enablement": "databricks.context.activated && databricks.context.bundle.deploymentState == idle",
6464
"category": "Databricks"
6565
},
6666
{
@@ -143,6 +143,7 @@
143143
{
144144
"command": "databricks.autocomplete.configure",
145145
"title": "Configure autocomplete for Databricks globals",
146+
"enablement": "databricks.context.activated",
146147
"category": "Databricks"
147148
},
148149
{
@@ -234,7 +235,6 @@
234235
"command": "databricks.bundle.initNewProject",
235236
"icon": "$(new-folder)",
236237
"title": "Initialize new project",
237-
"enablement": "databricks.context.activated",
238238
"category": "Databricks"
239239
},
240240
{
@@ -368,7 +368,7 @@
368368
},
369369
{
370370
"id": "dabsVariableView",
371-
"name": "Bundle Variables View",
371+
"name": "Bundle Variables",
372372
"visibility": "visible",
373373
"when": "databricks.context.bundle.isTargetSet"
374374
},
@@ -400,11 +400,6 @@
400400
"contents": "[Create a new Databricks Project](command:databricks.bundle.initNewProject)",
401401
"when": "workspaceFolderCount > 0 && databricks.context.initialized"
402402
},
403-
{
404-
"view": "configurationView",
405-
"contents": "To learn more about how to use Databricks with VS Code [read our docs](https://docs.databricks.com/dev-tools/vscode-ext.html) or [Quickstart guide](command:databricks.quickstart.open)",
406-
"when": "databricks.context.initialized"
407-
},
408403
{
409404
"view": "configurationView",
410405
"contents": "Initializing...",
@@ -414,6 +409,10 @@
414409
"view": "configurationView",
415410
"contents": "This folder is empty.\n[Create a new Databricks Project](command:databricks.bundle.initNewProject)",
416411
"when": "workspaceFolderCount == 0"
412+
},
413+
{
414+
"view": "configurationView",
415+
"contents": "To learn more about how to use Databricks with VS Code [read our docs](https://docs.databricks.com/dev-tools/vscode-ext.html) or [Quickstart guide](command:databricks.quickstart.open)"
417416
}
418417
],
419418
"menus": {
@@ -575,7 +574,7 @@
575574
{
576575
"submenu": "databricks.run",
577576
"group": "navigation@0",
578-
"when": "databricks.context.isActiveFileInActiveWorkspace && resourceLangId =~ /^(python|scala|r|sql)$/ || databricks.context.isActiveFileInActiveWorkspace && resourceExtname == .ipynb"
577+
"when": "databricks.context.isActiveFileInActiveWorkspace && databricks.context.showRunAsWorkflow || databricks.context.isActiveFileInActiveWorkspace && resourceExtname == .ipynb"
579578
}
580579
],
581580
"databricks.run": [
@@ -586,7 +585,7 @@
586585
},
587586
{
588587
"command": "databricks.run.runEditorContentsAsWorkflow",
589-
"when": "resourceLangId == python || resourceLangId == scala || resourceLangId == r || resourceLangId == sql || resourceExtname == .ipynb",
588+
"when": "resourceLangId == python || resourceExtname == .ipynb || databricks.context.showRunAsWorkflow",
590589
"group": "1_remote@2"
591590
},
592591
{
@@ -607,7 +606,7 @@
607606
},
608607
{
609608
"command": "databricks.run.runEditorContentsAsWorkflow",
610-
"when": "resourceLangId == python || resourceExtname == .ipynb"
609+
"when": "resourceLangId == python || resourceExtname == .ipynb || databricks.context.showRunAsWorkflow"
611610
},
612611
{
613612
"command": "databricks.wsfs.createFolder",
@@ -641,7 +640,7 @@
641640
"explorer/context": [
642641
{
643642
"submenu": "databricks.run",
644-
"when": "resourceLangId == python || resourceExtname == .ipynb"
643+
"when": "resourceLangId == python || resourceExtname == .ipynb || databricks.context.showRunAsWorkflow"
645644
}
646645
]
647646
},

packages/databricks-vscode/src/bundle/models/BundleVariableModel.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,9 @@ export class BundleVariableModel extends BaseModelWithStateCache<BundleVariableM
137137
.filter((v) => v[1] !== undefined)
138138
);
139139
} catch (e: any) {
140-
if (e.code !== "ENOENT") {
141-
throw e;
142-
}
143140
NamedLogger.getOrCreate(Loggers.Extension).debug(
144-
"No bundle variable overrides found."
141+
"No bundle variable overrides found.",
142+
e
145143
);
146144
return {};
147145
}
@@ -252,7 +250,7 @@ export class BundleVariableModel extends BaseModelWithStateCache<BundleVariableM
252250
try {
253251
await workspace.fs.delete(this.bundleVariableFilePath);
254252
} catch (e: any) {
255-
if (e.code !== "ENOENT") {
253+
if (e.code !== "ENOENT" && e.code !== "FileNotFound") {
256254
throw e;
257255
}
258256
}

packages/databricks-vscode/src/extension.ts

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import {EnvironmentCommands} from "./language/EnvironmentCommands";
7575
import {WorkspaceFolderManager} from "./vscode-objs/WorkspaceFolderManager";
7676
import {SyncCommands} from "./sync/SyncCommands";
7777
import {CodeSynchronizer} from "./sync";
78+
import {LocalUri} from "./sync/SyncDestination";
7879

7980
// eslint-disable-next-line @typescript-eslint/no-var-requires
8081
const packageJson = require("../package.json");
@@ -151,7 +152,30 @@ export async function activate(
151152
}
152153

153154
const cli = new CliWrapper(context, loggerManager, cliLogFilePath);
154-
context.extensionPath;
155+
156+
// Loggers
157+
context.subscriptions.push(
158+
telemetry.registerCommand(
159+
"databricks.logs.openFolder",
160+
loggerManager.openLogFolder,
161+
loggerManager
162+
),
163+
telemetry.registerCommand(
164+
"databricks.bundle.showLogs",
165+
() => loggerManager.showOutputChannel("Databricks Bundle Logs"),
166+
loggerManager
167+
)
168+
);
169+
170+
// Quickstart
171+
const quickstartCommands = new QuickstartCommands(context);
172+
context.subscriptions.push(
173+
telemetry.registerCommand(
174+
"databricks.quickstart.open",
175+
quickstartCommands.openQuickstartCommand(),
176+
quickstartCommands
177+
)
178+
);
155179

156180
if (
157181
workspace.workspaceFolders === undefined ||
@@ -250,19 +274,6 @@ export async function activate(
250274

251275
cli.setPythonExtension(pythonExtensionWrapper);
252276

253-
context.subscriptions.push(
254-
telemetry.registerCommand(
255-
"databricks.logs.openFolder",
256-
loggerManager.openLogFolder,
257-
loggerManager
258-
),
259-
telemetry.registerCommand(
260-
"databricks.bundle.showLogs",
261-
() => loggerManager.showOutputChannel("Databricks Bundle Logs"),
262-
loggerManager
263-
)
264-
);
265-
266277
// manage contexts for experimental features
267278
function updateFeatureContexts() {
268279
customWhenContext.updateShowClusterView();
@@ -807,6 +818,20 @@ export async function activate(
807818
runCommands.runEditorContentsAsWorkflowCommand(),
808819
runCommands
809820
),
821+
window.onDidChangeActiveTextEditor(async (e) => {
822+
const uri = e?.document.uri;
823+
824+
if (
825+
uri &&
826+
uri.scheme === "file" &&
827+
((await FileUtils.isNotebook(new LocalUri(uri))) ||
828+
uri.fsPath.endsWith(".py"))
829+
) {
830+
customWhenContext.setShowRunAsWorkflow(true);
831+
} else {
832+
customWhenContext.setShowRunAsWorkflow(false);
833+
}
834+
}),
810835
debug.registerDebugAdapterDescriptorFactory("databricks", debugFactory),
811836
debugFactory,
812837
debug.registerDebugAdapterDescriptorFactory(
@@ -816,16 +841,6 @@ export async function activate(
816841
debugWorkflowFactory
817842
);
818843

819-
// Quickstart
820-
const quickstartCommands = new QuickstartCommands(context);
821-
context.subscriptions.push(
822-
telemetry.registerCommand(
823-
"databricks.quickstart.open",
824-
quickstartCommands.openQuickstartCommand(),
825-
quickstartCommands
826-
)
827-
);
828-
829844
showQuickStartOnFirstUse(context).catch((e) => {
830845
logging.NamedLogger.getOrCreate("Extension").error(
831846
"Quick Start error",

packages/databricks-vscode/src/test/e2e/bundle_variables.e2e.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe("Bundle Variables", async function () {
102102
}
103103

104104
it("should find bundle variable explorer and load default variables", async function () {
105-
const section = (await getViewSection("BUNDLE VARIABLES VIEW")) as
105+
const section = (await getViewSection("BUNDLE VARIABLES")) as
106106
| CustomTreeSection
107107
| undefined;
108108
assert(section);
@@ -131,7 +131,7 @@ describe("Bundle Variables", async function () {
131131
);
132132
await editor.save();
133133

134-
const section = (await getViewSection("BUNDLE VARIABLES VIEW")) as
134+
const section = (await getViewSection("BUNDLE VARIABLES")) as
135135
| CustomTreeSection
136136
| undefined;
137137
assert(section);
@@ -154,7 +154,7 @@ describe("Bundle Variables", async function () {
154154
});
155155

156156
it("should revert overrides", async function () {
157-
const section = (await getViewSection("BUNDLE VARIABLES VIEW")) as
157+
const section = (await getViewSection("BUNDLE VARIABLES")) as
158158
| CustomTreeSection
159159
| undefined;
160160
assert(section);
@@ -189,7 +189,7 @@ describe("Bundle Variables", async function () {
189189

190190
await writeRootBundleConfig(schemaDef, vscodeWorkspaceRoot);
191191

192-
const section = (await getViewSection("BUNDLE VARIABLES VIEW")) as
192+
const section = (await getViewSection("BUNDLE VARIABLES")) as
193193
| CustomTreeSection
194194
| undefined;
195195
assert(section);

packages/databricks-vscode/src/test/e2e/utils/commonUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const ViewSectionTypes = [
1515
"CONFIGURATION",
1616
"WORKSPACE EXPLORER",
1717
"BUNDLE RESOURCE EXPLORER",
18-
"BUNDLE VARIABLES VIEW",
18+
"BUNDLE VARIABLES",
1919
] as const;
2020
export type ViewSectionType = (typeof ViewSectionTypes)[number];
2121

packages/databricks-vscode/src/vscode-objs/CustomWhenContext.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,12 @@ export class CustomWhenContext {
9494
value
9595
);
9696
}
97+
98+
setShowRunAsWorkflow(value: boolean) {
99+
commands.executeCommand(
100+
"setContext",
101+
"databricks.context.showRunAsWorkflow",
102+
value
103+
);
104+
}
97105
}

0 commit comments

Comments
 (0)