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.
Show notification reaffirming Python extension still handles activati…
…on when in `pythonTerminalEnvVarActivation` experiment (#21802) Closes #21793 Only show notification when terminal prompt does not already indicate that env is activated.
- Loading branch information
Kartik Raj
authored
Aug 15, 2023
1 parent
b447bf1
commit 9c740b9
Showing
15 changed files
with
545 additions
and
22 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
80 changes: 80 additions & 0 deletions
80
src/client/interpreter/activation/terminalEnvVarCollectionPrompt.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,80 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import { Uri } from 'vscode'; | ||
import { IActiveResourceService, IApplicationShell, ITerminalManager } from '../../common/application/types'; | ||
import { | ||
IConfigurationService, | ||
IDisposableRegistry, | ||
IExperimentService, | ||
IPersistentStateFactory, | ||
} from '../../common/types'; | ||
import { Common, Interpreters } from '../../common/utils/localize'; | ||
import { IExtensionSingleActivationService } from '../../activation/types'; | ||
import { ITerminalEnvVarCollectionService } from './types'; | ||
import { inTerminalEnvVarExperiment } from '../../common/experiments/helpers'; | ||
|
||
export const terminalEnvCollectionPromptKey = 'TERMINAL_ENV_COLLECTION_PROMPT_KEY'; | ||
|
||
@injectable() | ||
export class TerminalEnvVarCollectionPrompt implements IExtensionSingleActivationService { | ||
public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: false }; | ||
|
||
constructor( | ||
@inject(IApplicationShell) private readonly appShell: IApplicationShell, | ||
@inject(IPersistentStateFactory) private readonly persistentStateFactory: IPersistentStateFactory, | ||
@inject(ITerminalManager) private readonly terminalManager: ITerminalManager, | ||
@inject(IDisposableRegistry) private readonly disposableRegistry: IDisposableRegistry, | ||
@inject(IActiveResourceService) private readonly activeResourceService: IActiveResourceService, | ||
@inject(ITerminalEnvVarCollectionService) | ||
private readonly terminalEnvVarCollectionService: ITerminalEnvVarCollectionService, | ||
@inject(IConfigurationService) private readonly configurationService: IConfigurationService, | ||
@inject(IExperimentService) private readonly experimentService: IExperimentService, | ||
) {} | ||
|
||
public async activate(): Promise<void> { | ||
if (!inTerminalEnvVarExperiment(this.experimentService)) { | ||
return; | ||
} | ||
this.disposableRegistry.push( | ||
this.terminalManager.onDidOpenTerminal(async (terminal) => { | ||
const cwd = | ||
'cwd' in terminal.creationOptions && terminal.creationOptions.cwd | ||
? terminal.creationOptions.cwd | ||
: this.activeResourceService.getActiveResource(); | ||
const resource = typeof cwd === 'string' ? Uri.file(cwd) : cwd; | ||
const settings = this.configurationService.getSettings(resource); | ||
if (!settings.terminal.activateEnvironment) { | ||
return; | ||
} | ||
if (this.terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)) { | ||
// No need to show notification if terminal prompt already indicates when env is activated. | ||
return; | ||
} | ||
await this.notifyUsers(); | ||
}), | ||
); | ||
} | ||
|
||
private async notifyUsers(): Promise<void> { | ||
const notificationPromptEnabled = this.persistentStateFactory.createGlobalPersistentState( | ||
terminalEnvCollectionPromptKey, | ||
true, | ||
); | ||
if (!notificationPromptEnabled.value) { | ||
return; | ||
} | ||
const prompts = [Common.doNotShowAgain]; | ||
const selection = await this.appShell.showInformationMessage( | ||
Interpreters.terminalEnvVarCollectionPrompt, | ||
...prompts, | ||
); | ||
if (!selection) { | ||
return; | ||
} | ||
if (selection === prompts[0]) { | ||
await notificationPromptEnabled.updateValue(false); | ||
} | ||
} | ||
} |
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
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.