Skip to content

Commit e729aa2

Browse files
Fix project.json file watcher rewriting profile bug (#125)
To reproduce - Configure both profile and cluster - Delete both from the project.json file and save the file - Profile will be written back This PR fixes this behaviour.
1 parent 5dde088 commit e729aa2

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ export class ConnectionManager {
165165
await this.waitForConnect();
166166
}
167167

168+
this._projectConfigFile = undefined;
168169
this._apiClient = undefined;
169170
this._me = undefined;
170-
this._projectConfigFile = undefined;
171171
this.updateCluster(undefined);
172+
this.updateSyncDestination(undefined);
172173
this.updateState("DISCONNECTED");
173174
}
174175

@@ -301,6 +302,9 @@ export class ConnectionManager {
301302
}
302303

303304
private updateState(newState: ConnectionState) {
305+
if (newState === "DISCONNECTED") {
306+
this._profile = undefined;
307+
}
304308
if (this._state !== newState) {
305309
this._state = newState;
306310
this.onDidChangeStateEmitter.fire(this._state);

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,41 @@ export class ProjectConfigFileWatcher implements Disposable {
1616
fileSystemWatcher,
1717
fileSystemWatcher.onDidCreate(async (e) => {
1818
if (connectionManager.state !== "CONNECTED") {
19-
connectionManager.login();
19+
await connectionManager.login();
2020
}
2121
}, this),
2222
fileSystemWatcher.onDidChange(async (e) => {
2323
const configFile = await ProjectConfigFile.load(rootPath);
2424
if (configFile.profile !== connectionManager.profile) {
25-
connectionManager.login();
25+
await connectionManager.login();
2626
}
2727
if (connectionManager.cluster?.id !== configFile.clusterId) {
2828
if (configFile.clusterId) {
29-
connectionManager.attachCluster(configFile.clusterId);
29+
await connectionManager.attachCluster(
30+
configFile.clusterId
31+
);
3032
} else {
31-
connectionManager.detachCluster();
33+
await connectionManager.detachCluster();
3234
}
3335
}
3436
if (
3537
connectionManager.syncDestination?.path.path !==
3638
configFile.workspacePath
3739
) {
3840
if (configFile.workspacePath) {
39-
connectionManager.attachSyncDestination(
41+
await connectionManager.attachSyncDestination(
4042
Uri.from({
4143
scheme: "dbws",
4244
path: configFile.workspacePath,
4345
})
4446
);
4547
} else {
46-
connectionManager.detachSyncDestination();
48+
await connectionManager.detachSyncDestination();
4749
}
4850
}
4951
}, this),
50-
fileSystemWatcher.onDidDelete((e) => {
51-
connectionManager.logout();
52+
fileSystemWatcher.onDidDelete(async (e) => {
53+
await connectionManager.logout();
5254
}, this)
5355
);
5456
}

0 commit comments

Comments
 (0)