Skip to content

Commit 55dd5f7

Browse files
authored
Support complex variables in the extension UI (#1675)
## Changes This is just to fix broken Variables Explorer view. We still don't support overriding complex vars, for that we need to store the override file inside a .databricks folder and stop using BUNDLE_VAR env vars ## Tests e2e
1 parent e5a537f commit 55dd5f7

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ describe("Bundle Variables", async function () {
3232
varWithDefault: {
3333
default: "default",
3434
},
35+
complexVar: {
36+
type: "complex",
37+
default: {
38+
key1: "value1",
39+
key2: 123,
40+
},
41+
},
3542
},
3643
targets: {
3744
dev_test: {
@@ -112,6 +119,10 @@ describe("Bundle Variables", async function () {
112119
value: "dev",
113120
defaultValue: "default",
114121
});
122+
await assertVariableValue(section, "complexVar", {
123+
value: `{"key1":"value1","key2":123}`,
124+
defaultValue: `{"key1":"value1","key2":123}`,
125+
});
115126
});
116127

117128
it("should override default variable", async function () {

packages/databricks-vscode/src/ui/bundle-variables/VariableTreeNode.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,37 @@ export class VariableTreeNode implements BundleVariableTreeNode {
1010
public readonly parent?: BundleVariableTreeNode
1111
) {}
1212

13+
get targetValue() {
14+
const value =
15+
this.value.vscodeOverrideValue ?? this.value.valueInTarget ?? "";
16+
if (this.value.type === "complex") {
17+
return this.complexValueToString(value);
18+
} else {
19+
return String(value);
20+
}
21+
}
22+
23+
get defaultValue() {
24+
const value = this.value.default ?? this.value.valueInTarget;
25+
if (this.value.type === "complex") {
26+
return this.complexValueToString(value);
27+
} else {
28+
return String(value);
29+
}
30+
}
31+
32+
complexValueToString(value: any) {
33+
try {
34+
return JSON.stringify(value);
35+
} catch (error) {
36+
return "complex vairable";
37+
}
38+
}
39+
1340
getTreeItem(): BundleVariableTreeItem {
1441
return {
1542
label: this.key,
16-
description:
17-
this.value.vscodeOverrideValue ??
18-
this.value.valueInTarget ??
19-
"",
43+
description: this.targetValue,
2044
collapsibleState: this.value.valueInTarget
2145
? TreeItemCollapsibleState.Collapsed
2246
: TreeItemCollapsibleState.None,
@@ -28,7 +52,7 @@ export class VariableTreeNode implements BundleVariableTreeNode {
2852
return [
2953
new TreeItemTreeNode({
3054
label: "Default",
31-
description: this.value.default ?? this.value.valueInTarget,
55+
description: this.defaultValue,
3256
}),
3357
];
3458
}

0 commit comments

Comments
 (0)