Skip to content

Commit 8310a1b

Browse files
authored
Avoid python extension interference in the bundle init terminal (#1595)
## Changes Fixing bugs with `setTimeout`, yeehaw! See the comment in the code. How the bug looks like: <img width="605" alt="Screenshot 2025-03-06 at 10 20 02" src="https://github.com/user-attachments/assets/86b05f9d-b696-4150-a974-ea7c39cdc8dd" /> After the fix: <img width="605" alt="Screenshot 2025-03-06 at 10 20 10" src="https://github.com/user-attachments/assets/13530213-c924-423c-bd2b-e994cca84f4c" /> The bug only happens when python extension has specific A/B test enabled, not for everyone. ## Tests We have existing e2e tests for the wizard
1 parent 3eaf3cc commit 8310a1b

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

packages/databricks-vscode/src/bundle/BundleInitWizard.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ export class BundleInitWizard {
134134
parentFolder: Uri,
135135
authProvider: AuthProvider
136136
) {
137+
const terminalDidClosePromise = new Promise<void>((resolve) => {
138+
const closeEvent = window.onDidCloseTerminal((t) => {
139+
if (t === terminal) {
140+
closeEvent.dispose();
141+
resolve();
142+
}
143+
});
144+
});
145+
const terminalDidOpenPromise = new Promise<void>((resolve) => {
146+
const openEvent = window.onDidOpenTerminal((t) => {
147+
if (t === terminal) {
148+
openEvent.dispose();
149+
// Python extension can insert env-setup text into newly opened terminals. It doesn't break our init wizard, but if it happens after we insert our command in the terminal,
150+
// then on a step where the wizard asks you to select a template, the search input will be populated with a string from the python extension, and you'll have to remove it to proceed.
151+
// Haven't found a reliable way to detect (or avoid) this behavior (other than spawning a terminal with a custom PTY, but making it work for the init wizard is non trivial).
152+
// Waiting for half a second to let the python extension do its thing...
153+
setTimeout(() => resolve(), 500);
154+
}
155+
});
156+
});
137157
const terminal = window.createTerminal({
138158
name: "Databricks Project Init",
139159
isTransient: true,
@@ -151,6 +171,7 @@ export class BundleInitWizard {
151171
// in the current workspace root or while traversing up the folder structure.
152172
cwd: tmpdir(),
153173
});
174+
await terminalDidOpenPromise;
154175
const args = [
155176
"bundle",
156177
"init",
@@ -162,15 +183,7 @@ export class BundleInitWizard {
162183
terminal.sendText(
163184
`${initialPrompt}; ${this.cli.escapedCliPath} ${args}; ${finalPrompt}`
164185
);
165-
return new Promise<void>((resolve) => {
166-
const closeEvent = window.onDidCloseTerminal(async (t) => {
167-
if (t !== terminal) {
168-
return;
169-
}
170-
closeEvent.dispose();
171-
resolve();
172-
});
173-
});
186+
return terminalDidClosePromise;
174187
}
175188

176189
private async promptForParentFolder(

0 commit comments

Comments
 (0)