forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Reliably detect whether shell integration is working" (…
- Loading branch information
Kartik Raj
committed
Nov 8, 2023
1 parent
2fc9fea
commit 934f46d
Showing
11 changed files
with
183 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
src/client/terminals/envCollectionActivation/shellIntegration.ts
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
src/client/terminals/envCollectionActivation/shellIntegrationService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
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 { createDeferred, sleep } from '../../common/utils/async'; | ||
import { cache } from '../../common/utils/decorators'; | ||
import { traceVerbose } from '../../logging'; | ||
import { IShellIntegrationService } from '../types'; | ||
|
||
/** | ||
* This is a list of shells which support shell integration: | ||
* https://code.visualstudio.com/docs/terminal/shell-integration | ||
*/ | ||
const ShellIntegrationShells = [ | ||
TerminalShellType.powershell, | ||
TerminalShellType.powershellCore, | ||
TerminalShellType.bash, | ||
TerminalShellType.zsh, | ||
TerminalShellType.fish, | ||
]; | ||
|
||
@injectable() | ||
export class ShellIntegrationService implements IShellIntegrationService { | ||
constructor( | ||
@inject(ITerminalManager) private readonly terminalManager: ITerminalManager, | ||
@inject(IApplicationShell) private readonly appShell: IApplicationShell, | ||
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService, | ||
) {} | ||
|
||
@cache(-1, true) | ||
public async isWorking(shell: string): Promise<boolean> { | ||
const isEnabled = this.workspaceService | ||
.getConfiguration('terminal') | ||
.get<boolean>('integrated.shellIntegration.enabled')!; | ||
if (!isEnabled) { | ||
traceVerbose('Shell integrated is disabled in user settings.'); | ||
} | ||
const isSupposedToWork = isEnabled && ShellIntegrationShells.includes(identifyShellFromShellPath(shell)); | ||
if (!isSupposedToWork) { | ||
return false; | ||
} | ||
const deferred = createDeferred<void>(); | ||
const timestamp = new Date().getTime(); | ||
const name = `Python ${timestamp}`; | ||
const onDidExecuteTerminalCommand = this.appShell.onDidExecuteTerminalCommand?.bind(this.appShell); | ||
if (!onDidExecuteTerminalCommand) { | ||
// Proposed API is not available, assume shell integration is working at this point. | ||
return true; | ||
} | ||
const disposable = onDidExecuteTerminalCommand((e) => { | ||
if (e.terminal.name === name) { | ||
deferred.resolve(); | ||
} | ||
}); | ||
const terminal = this.terminalManager.createTerminal({ | ||
name, | ||
shellPath: shell, | ||
hideFromUser: true, | ||
}); | ||
terminal.sendText(`echo ${shell}`); | ||
const success = await Promise.race([sleep(3000).then(() => false), deferred.promise.then(() => true)]); | ||
disposable.dispose(); | ||
return success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.