Skip to content

Commit 0a641d4

Browse files
Provide default sync destination if not set (#569)
https://user-images.githubusercontent.com/88345179/225662235-59621b9c-81bd-4ca9-9393-a65b35785838.mov --------- Co-authored-by: Fabian Jakobs <fabian.jakobs@databricks.com>
1 parent 646601a commit 0a641d4

File tree

4 files changed

+70
-11
lines changed

4 files changed

+70
-11
lines changed

packages/databricks-vscode/src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
} from "./workspace-fs";
3535
import {generateBundleSchema} from "./bundle/GenerateBundle";
3636
import {CustomWhenContext} from "./vscode-objs/CustomWhenContext";
37+
import {WorkspaceStateManager} from "./vscode-objs/WorkspaceState";
3738

3839
export async function activate(
3940
context: ExtensionContext
@@ -85,8 +86,11 @@ export async function activate(
8586
metadata: packageMetadata,
8687
});
8788

89+
const workspaceStateManager = new WorkspaceStateManager(context);
90+
8891
const configureAutocomplete = new ConfigureAutocomplete(
8992
context,
93+
workspaceStateManager,
9094
workspace.workspaceFolders[0].uri.fsPath
9195
);
9296
context.subscriptions.push(
@@ -115,6 +119,7 @@ export async function activate(
115119
);
116120
const workspaceFsCommands = new WorkspaceFsCommands(
117121
workspace.workspaceFolders[0].uri,
122+
workspaceStateManager,
118123
connectionManager,
119124
workspaceFsDataProvider
120125
);

packages/databricks-vscode/src/language/ConfigureAutocomplete.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ConfigurationTarget,
1313
} from "vscode";
1414
import {Loggers} from "../logger";
15+
import {WorkspaceStateManager} from "../vscode-objs/WorkspaceState";
1516

1617
type Resource = Uri | undefined;
1718

@@ -65,6 +66,7 @@ export class ConfigureAutocomplete implements Disposable {
6566

6667
constructor(
6768
private readonly context: ExtensionContext,
69+
private readonly workspaceState: WorkspaceStateManager,
6870
private readonly workspaceFolder: string
6971
) {
7072
this.configure();
@@ -113,12 +115,7 @@ export class ConfigureAutocomplete implements Disposable {
113115
}
114116

115117
private async configure(force = false) {
116-
if (
117-
!force &&
118-
this.context.workspaceState.get<boolean>(
119-
"databricks.autocompletion.skipConfigure"
120-
)
121-
) {
118+
if (!force && this.workspaceState.skipAutocompleteConfigure) {
122119
return;
123120
}
124121

@@ -181,10 +178,7 @@ export class ConfigureAutocomplete implements Disposable {
181178
}
182179

183180
if (choice === "Never for this workspace") {
184-
this.context.workspaceState.update(
185-
"databricks.autocompletion.skipConfigure",
186-
true
187-
);
181+
this.workspaceState.skipAutocompleteConfigure = true;
188182
return;
189183
}
190184

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {randomUUID} from "crypto";
2+
import {ExtensionContext} from "vscode";
3+
4+
export class WorkspaceStateManager {
5+
constructor(private context: ExtensionContext) {}
6+
7+
get skipAutocompleteConfigure() {
8+
return this.context.workspaceState.get(
9+
"databricks.autocompletion.skipConfigure",
10+
false
11+
);
12+
}
13+
14+
set skipAutocompleteConfigure(value: boolean) {
15+
this.context.workspaceState.update(
16+
"databricks.autocompletion.skipConfigure",
17+
true
18+
);
19+
}
20+
21+
get fixedUUID() {
22+
let uuid = this.context.workspaceState.get<string>(
23+
"databricks.fixedUUID"
24+
);
25+
if (!uuid) {
26+
uuid = randomUUID();
27+
this.context.workspaceState.update("databricks.fixedUUID", uuid);
28+
}
29+
return uuid;
30+
}
31+
}

packages/databricks-vscode/src/workspace-fs/WorkspaceFsCommands.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,44 @@ import {Loggers} from "../logger";
1212
import {workspaceConfigs} from "../vscode-objs/WorkspaceConfigs";
1313
import {createDirWizard} from "./createDirectoryWizard";
1414
import {WorkspaceFsDataProvider} from "./WorkspaceFsDataProvider";
15+
import path from "node:path";
16+
import {WorkspaceStateManager} from "../vscode-objs/WorkspaceState";
1517

1618
export class WorkspaceFsCommands implements Disposable {
1719
private disposables: Disposable[] = [];
1820

1921
constructor(
2022
private _workspaceFolder: Uri,
23+
private readonly _workspaceState: WorkspaceStateManager,
2124
private _connectionManager: ConnectionManager,
2225
private _workspaceFsDataProvider: WorkspaceFsDataProvider
23-
) {}
26+
) {
27+
this.disposables.push(
28+
this._connectionManager.onDidChangeState(async (state) => {
29+
if (
30+
state !== "CONNECTED" ||
31+
!workspaceConfigs.enableFilesInWorkspace ||
32+
this._connectionManager.syncDestinationMapper !== undefined
33+
) {
34+
return;
35+
}
36+
37+
const root = await this.getValidRoot(
38+
this._connectionManager.databricksWorkspace?.currentFsRoot
39+
.path
40+
);
41+
42+
const element = await root?.mkdir(
43+
`${path.basename(
44+
this._workspaceFolder.fsPath
45+
)}-${this._workspaceState.fixedUUID.slice(0, 8)}`
46+
);
47+
if (element) {
48+
this.attachSyncDestination(element);
49+
}
50+
})
51+
);
52+
}
2453

2554
async attachSyncDestination(element: WorkspaceFsEntity) {
2655
await this._connectionManager.attachSyncDestination(

0 commit comments

Comments
 (0)