Skip to content

Commit 0b2fd63

Browse files
committed
feat: startup activation scaffolding
1 parent 7d36ca0 commit 0b2fd63

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Disposable, GlobalEnvironmentVariableCollection } from 'vscode';
2+
import { onDidChangeConfiguration } from '../../../common/workspace.apis';
3+
import { registerCommand } from '../../../common/command.api';
4+
import { getAutoActivationType } from '../utils';
5+
6+
export interface ActivateUsingShellStartup extends Disposable {}
7+
8+
class ActivateUsingShellStartupImpl implements ActivateUsingShellStartup {
9+
private readonly disposables: Disposable[] = [];
10+
constructor(private readonly envCollection: GlobalEnvironmentVariableCollection) {}
11+
12+
dispose() {
13+
this.disposables.forEach((disposable) => disposable.dispose());
14+
}
15+
}
16+
17+
export async function checkAndUpdateStartupScripts(): Promise<void> {
18+
// Implement the logic to check startup scripts
19+
return Promise.resolve();
20+
}
21+
22+
export async function removeAllStartupScripts(): Promise<void> {
23+
// Implement the logic to remove all startup scripts
24+
return Promise.resolve();
25+
}
26+
27+
export function registerActivateUsingShellStartup(
28+
disposables: Disposable[],
29+
environmentVariableCollection: GlobalEnvironmentVariableCollection,
30+
) {
31+
let activateUsingShellStartup: ActivateUsingShellStartup | undefined;
32+
33+
disposables.push(
34+
onDidChangeConfiguration((e) => {
35+
if (e.affectsConfiguration('python.terminal.autoActivationType')) {
36+
const autoActType = getAutoActivationType();
37+
if (autoActType === 'shellStartup') {
38+
if (!activateUsingShellStartup) {
39+
activateUsingShellStartup = new ActivateUsingShellStartupImpl(environmentVariableCollection);
40+
}
41+
} else {
42+
activateUsingShellStartup?.dispose();
43+
activateUsingShellStartup = undefined;
44+
}
45+
}
46+
}),
47+
new Disposable(() => activateUsingShellStartup?.dispose()),
48+
registerCommand('python-envs.removeStartupScripts', async () => {
49+
await removeAllStartupScripts();
50+
}),
51+
);
52+
53+
const autoActType = getAutoActivationType();
54+
if (autoActType === 'shellStartup') {
55+
activateUsingShellStartup = new ActivateUsingShellStartupImpl(environmentVariableCollection);
56+
setImmediate(async () => {
57+
await checkAndUpdateStartupScripts();
58+
});
59+
}
60+
}

0 commit comments

Comments
 (0)