Skip to content

Commit baad0da

Browse files
committed
Notes about activation
1 parent d4fcbb0 commit baad0da

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/features/terminal/shells/bash/bashStartup.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,22 @@ async function isStartupSetup(profile: string, key: string): Promise<ShellSetupS
7070
}
7171
async function setupStartup(profile: string, key: string, name: string): Promise<boolean> {
7272
const shellIntegrationEnabled = await getShellIntegrationEnabledCache();
73-
if ((shellIntegrationEnabled || (await shellIntegrationForActiveTerminal(name, profile))) && !isWsl()) {
73+
// shellIntegrationEnabled should not be checked here, consider a shell setup where it's
74+
// incompatible with our shell integration. `terminal.integrated.shellIntegration.enabled` sets
75+
// whether we try to inject the script, not whether it will work. `.attemptToInject` would be a
76+
// more accurate name for this.
77+
//
78+
// Doing it this way would handle these cases:
79+
// - Inject failed (.shellIntegration won't be there)
80+
// - Inject failed, but it was installed manually (.shelIntegration will be there)
81+
if (await shellIntegrationForActiveTerminal(name, profile) && !isWsl()) {
7482
removeStartup(profile, key);
7583
return true;
7684
}
85+
86+
// We may have activated here, but not have command detection. Eg. shell integration injects,
87+
// env activates, p10k disables our shell integration; we have activated, but don't know in the
88+
// extension.
7789
const activationContent = getActivationContent(key);
7890
try {
7991
if (await fs.pathExists(profile)) {
@@ -90,6 +102,8 @@ async function setupStartup(profile: string, key: string, name: string): Promise
90102
traceInfo(`SHELL: Created new ${name} profile at: ${profile}\n${activationContent}`);
91103
}
92104

105+
// If this fails for the first time, do we need a notification here telling the user to restart the terminal?
106+
93107
return true;
94108
} catch (err) {
95109
traceError(`SHELL: Failed to setup startup for profile at: ${profile}`, err);

src/features/terminal/shells/common/shellUtils.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ export async function shellIntegrationForActiveTerminal(name: string, profile?:
108108
let hasShellIntegration = activeTerminalShellIntegration();
109109
let timeout = 0;
110110

111+
// Should use onDidChangeTerminalShellIntegration event instead of polling
112+
// const result = Promise.race([
113+
// // Make sure event listener is disposed
114+
// new Promise(r => window.onDidChangeTerminalShellIntegration(() => r))),
115+
// // Note that you might not know when terminal started up, but this should be (fromNewTimeoutSetting - terminalOpened)
116+
// // It's important that the time the terminal is laucnhed is recorded and used, otherwise you might end up waiting 5s*2 if called twice
117+
// // terminalOpened = onDidOpenTerminal event time, or extension startup time (as it was already there)
118+
// timeout(fromNewTimeoutSetting)
119+
// ]);
120+
// // check result
121+
// 500ms isn't long enough
111122
while (!hasShellIntegration && timeout < SHELL_INTEGRATION_TIMEOUT) {
112123
await sleep(SHELL_INTEGRATION_POLL_INTERVAL);
113124
timeout += SHELL_INTEGRATION_POLL_INTERVAL;
@@ -134,7 +145,11 @@ export function isWsl(): boolean {
134145
}
135146

136147
export async function getShellIntegrationEnabledCache(): Promise<boolean> {
137-
const persistentState = await getGlobalPersistentState();
148+
// Cache doesn't do anything?
149+
// const persistentState = await getGlobalPersistentState();
150+
// if (persistentState.get(SHELL_INTEGRATION_STATE_KEY)) {
151+
// return
152+
// }
138153
const shellIntegrationInspect =
139154
getConfiguration('terminal.integrated').inspect<boolean>('shellIntegration.enabled');
140155

@@ -158,6 +173,6 @@ export async function getShellIntegrationEnabledCache(): Promise<boolean> {
158173
}
159174
}
160175

161-
await persistentState.set(SHELL_INTEGRATION_STATE_KEY, shellIntegrationEnabled);
176+
// await persistentState.set(SHELL_INTEGRATION_STATE_KEY, shellIntegrationEnabled);
162177
return shellIntegrationEnabled;
163178
}

src/features/terminal/terminalManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export class TerminalManagerImpl implements TerminalManager {
175175
)}`,
176176
);
177177

178+
// TODO: This needs the same treatment as in setupStartup (bashStartup.ts)
178179
if (
179180
(shellIntegrationEnabled || (await shellIntegrationForActiveTerminal(p.name))) &&
180181
!isWsl()

0 commit comments

Comments
 (0)