Skip to content

Commit

Permalink
Do not run commands to check whether shell integration is working (#2…
Browse files Browse the repository at this point in the history
…2850)

Closes #22774 closes
#22743
  • Loading branch information
Kartik Raj authored and anthonykim1 committed Feb 6, 2024
1 parent a0b893c commit 5c1a185
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { injectable, inject } from 'inversify';
import { IApplicationShell, ITerminalManager, IWorkspaceService } from '../../common/application/types';
import { identifyShellFromShellPath } from '../../common/terminal/shellDetectors/baseShellDetector';
import { TerminalShellType } from '../../common/terminal/types';
import { IPersistentStateFactory } from '../../common/types';
import { createDeferred, sleep } from '../../common/utils/async';
import { cache } from '../../common/utils/decorators';
import { traceError, traceInfo, traceVerbose } from '../../logging';
Expand All @@ -22,12 +23,22 @@ const ShellIntegrationShells = [
TerminalShellType.fish,
];

export const isShellIntegrationWorkingKey = 'SHELL_INTEGRATION_WORKING_KEY';

@injectable()
export class ShellIntegrationService implements IShellIntegrationService {
/**
* It seems to have a couple of issues:
* * Ends up cluterring terminal history
* * Does not work for hidden terminals: https://github.com/microsoft/vscode/issues/199611
*/
private readonly USE_COMMAND_APPROACH = false;

constructor(
@inject(ITerminalManager) private readonly terminalManager: ITerminalManager,
@inject(IApplicationShell) private readonly appShell: IApplicationShell,
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IPersistentStateFactory) private readonly persistentStateFactory: IPersistentStateFactory,
) {}

public async isWorking(shell: string): Promise<boolean> {
Expand All @@ -50,6 +61,23 @@ export class ShellIntegrationService implements IShellIntegrationService {
if (!isSupposedToWork) {
return false;
}
if (!this.USE_COMMAND_APPROACH) {
// For now, based on problems with using the command approach, assume it always works.
return true;
}
const key = `${isShellIntegrationWorkingKey}_${shellType}`;
const persistedResult = this.persistentStateFactory.createGlobalPersistentState<boolean>(key);
if (persistedResult.value !== undefined) {
return persistedResult.value;
}
const result = await this.checkIfWorkingByRunningCommand(shell);
// Persist result to storage to avoid running commands unncecessary.
await persistedResult.updateValue(result);
return result;
}

private async checkIfWorkingByRunningCommand(shell: string): Promise<boolean> {
const shellType = identifyShellFromShellPath(shell);
const deferred = createDeferred<void>();
const timestamp = new Date().getTime();
const name = `Python ${timestamp}`;
Expand Down

0 comments on commit 5c1a185

Please sign in to comment.