Skip to content

Commit c1c4a43

Browse files
authored
Improve run button UX (#1397)
## Changes - Add login command to the run context menu if the extension is logged out - Focus config view when the login command is executed - Fix a bug where the run button isn't visible if the vscode is opened with a python file already active <img width="570" alt="Screenshot 2024-10-18 at 11 13 24" src="https://github.com/user-attachments/assets/a992c165-c849-4c67-8636-d3c28011d382"> The Sign-In item is not visible in the logged in state ## Tests Manually and existing tests
1 parent 94bf23b commit c1c4a43

File tree

5 files changed

+51
-38
lines changed

5 files changed

+51
-38
lines changed

packages/databricks-vscode/package.json

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -578,25 +578,30 @@
578578
}
579579
],
580580
"databricks.run": [
581+
{
582+
"command": "databricks.connection.configureLogin",
583+
"when": "databricks.context.activated && !databricks.context.loggedIn",
584+
"group": "1_login@0"
585+
},
581586
{
582587
"command": "databricks.run.runEditorContents",
583-
"when": "resourceLangId == python",
584-
"group": "1_remote@1"
588+
"when": "databricks.context.activated && resourceLangId == python",
589+
"group": "2_remote@1"
585590
},
586591
{
587592
"command": "databricks.run.runEditorContentsAsWorkflow",
588-
"when": "resourceLangId == python || resourceExtname == .ipynb || databricks.context.showRunAsWorkflow",
589-
"group": "1_remote@2"
593+
"when": "databricks.context.activated && resourceLangId == python || resourceExtname == .ipynb || databricks.context.showRunAsWorkflow",
594+
"group": "2_remote@2"
590595
},
591596
{
592597
"command": "databricks.run.dbconnect.debug",
593-
"when": "resourceLangId == python",
594-
"group": "2_local@1"
598+
"when": "databricks.context.activated && resourceLangId == python",
599+
"group": "3_local@1"
595600
},
596601
{
597602
"command": "databricks.run.dbconnect.run",
598-
"when": "resourceLangId == python",
599-
"group": "2_local@2"
603+
"when": "databricks.context.activated && resourceLangId == python",
604+
"group": "3_local@2"
600605
}
601606
],
602607
"commandPalette": [

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
QuickPickItemKind,
66
ThemeIcon,
77
window,
8+
commands,
89
} from "vscode";
910
import {ClusterListDataProvider} from "../cluster/ClusterListDataProvider";
1011
import {ClusterModel} from "../cluster/ClusterModel";
@@ -73,6 +74,7 @@ export class ConnectionCommands implements Disposable {
7374
}
7475

7576
async configureLoginCommand(arg?: {id: string}) {
77+
commands.executeCommand("configurationView.focus");
7678
let source: ManualLoginSource = "command";
7779
if (arg?.id === AUTH_TYPE_SWITCH_ID) {
7880
source = "authTypeSwitch";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ export class ConnectionManager implements Disposable {
392392
async configureLogin(source: ManualLoginSource) {
393393
if (this.configureLoginMutex.locked) {
394394
window.showErrorMessage(
395-
"Databricks: Already configuring workspace"
395+
"Databricks: sign in is already in progress"
396396
);
397397
return;
398398
}

packages/databricks-vscode/src/extension.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ import {EnvironmentCommands} from "./language/EnvironmentCommands";
7272
import {WorkspaceFolderManager} from "./vscode-objs/WorkspaceFolderManager";
7373
import {SyncCommands} from "./sync/SyncCommands";
7474
import {CodeSynchronizer} from "./sync";
75-
import {LocalUri} from "./sync/SyncDestination";
7675

7776
// eslint-disable-next-line @typescript-eslint/no-var-requires
7877
const packageJson = require("../package.json");
@@ -730,10 +729,11 @@ export async function activate(
730729

731730
const runCommands = new RunCommands(
732731
connectionManager,
733-
workspace.workspaceFolders[0],
732+
workspaceFolderManager,
734733
pythonExtensionWrapper,
735734
featureManager,
736-
context
735+
context,
736+
customWhenContext
737737
);
738738
const debugFactory = new DatabricksDebugAdapterFactory(
739739
connectionManager,
@@ -777,20 +777,6 @@ export async function activate(
777777
runCommands.runEditorContentsAsWorkflowCommand(),
778778
runCommands
779779
),
780-
window.onDidChangeActiveTextEditor(async (e) => {
781-
const uri = e?.document.uri;
782-
783-
if (
784-
uri &&
785-
uri.scheme === "file" &&
786-
((await FileUtils.isNotebook(new LocalUri(uri))) ||
787-
uri.fsPath.endsWith(".py"))
788-
) {
789-
customWhenContext.setShowRunAsWorkflow(true);
790-
} else {
791-
customWhenContext.setShowRunAsWorkflow(false);
792-
}
793-
}),
794780
debug.registerDebugAdapterDescriptorFactory("databricks", debugFactory),
795781
debugFactory,
796782
debug.registerDebugAdapterDescriptorFactory(

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

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
commands,
3-
debug,
4-
ExtensionContext,
5-
Uri,
6-
window,
7-
WorkspaceFolder,
8-
} from "vscode";
1+
import {commands, debug, ExtensionContext, Uri, window} from "vscode";
92
import {ConnectionManager} from "../configuration/ConnectionManager";
103
import {FileUtils} from "../utils";
114
import {LocalUri} from "../sync/SyncDestination";
@@ -17,18 +10,42 @@ import {
1710
escapeExecutableForTerminal,
1811
escapePathArgument,
1912
} from "../utils/shellUtils";
13+
import {CustomWhenContext} from "../vscode-objs/CustomWhenContext";
14+
import {WorkspaceFolderManager} from "../vscode-objs/WorkspaceFolderManager";
2015

2116
/**
2217
* Run related commands
2318
*/
2419
export class RunCommands {
2520
constructor(
2621
private connection: ConnectionManager,
27-
private readonly workspaceFolder: WorkspaceFolder,
22+
private readonly workspaceFolderManager: WorkspaceFolderManager,
2823
private readonly pythonExtension: MsPythonExtensionWrapper,
2924
private readonly featureManager: FeatureManager,
30-
private readonly context: ExtensionContext
31-
) {}
25+
private readonly context: ExtensionContext,
26+
private readonly customWhenContext: CustomWhenContext
27+
) {
28+
this.context.subscriptions.push(
29+
window.onDidChangeActiveTextEditor(async () =>
30+
this.updateRunAsWorkflowContext()
31+
)
32+
);
33+
this.updateRunAsWorkflowContext();
34+
}
35+
36+
async updateRunAsWorkflowContext() {
37+
const uri = window.activeTextEditor?.document.uri;
38+
if (
39+
uri &&
40+
uri.scheme === "file" &&
41+
((await FileUtils.isNotebook(new LocalUri(uri))) ||
42+
uri.fsPath.endsWith(".py"))
43+
) {
44+
this.customWhenContext.setShowRunAsWorkflow(true);
45+
} else {
46+
this.customWhenContext.setShowRunAsWorkflow(false);
47+
}
48+
}
3249

3350
/**
3451
* Run a Python file using the command execution API
@@ -130,7 +147,10 @@ export class RunCommands {
130147
env: {...process.env},
131148
};
132149

133-
debug.startDebugging(this.workspaceFolder, config);
150+
debug.startDebugging(
151+
this.workspaceFolderManager.activeWorkspaceFolder,
152+
config
153+
);
134154
}
135155

136156
async runFileUsingDbconnect(resource?: Uri) {

0 commit comments

Comments
 (0)