<commit_before>// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { inject, injectable } from 'inversify';
import { ConfigurationTarget, Disposable, Uri } from 'vscode';
import { IExtensionActivationService } from '../../activation/types';
import { IApplicationShell } from '../../common/application/types';
import { inDiscoveryExperiment } from '../../common/experiments/helpers';
import { traceDecorators } from '../../common/logger';
import { IDisposableRegistry, IExperimentService, IPersistentStateFactory } from '../../common/types';
import { sleep } from '../../common/utils/async';
import { Common, Interpreters } from '../../common/utils/localize';
import { IServiceContainer } from '../../ioc/types';
import { PythonEnvironment } from '../../pythonEnvironments/info';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { IPythonPathUpdaterServiceManager } from '../configuration/types';
import {
    IComponentAdapter,
    IInterpreterHelper,
    IInterpreterLocatorService,
    IInterpreterWatcherBuilder,
    WORKSPACE_VIRTUAL_ENV_SERVICE,
} from '../contracts';

const doNotDisplayPromptStateKey = 'MESSAGE_KEY_FOR_VIRTUAL_ENV';
@injectable()
export class VirtualEnvironmentPrompt implements IExtensionActivationService {
    constructor(
        @inject(IServiceContainer) private readonly serviceContainer: IServiceContainer,
        @inject(IPersistentStateFactory) private readonly persistentStateFactory: IPersistentStateFactory,
        @inject(IInterpreterHelper) private readonly helper: IInterpreterHelper,
        @inject(IPythonPathUpdaterServiceManager)
        private readonly pythonPathUpdaterService: IPythonPathUpdaterServiceManager,
        @inject(IDisposableRegistry) private readonly disposableRegistry: Disposable[],
        @inject(IApplicationShell) private readonly appShell: IApplicationShell,
        @inject(IComponentAdapter) private readonly pyenvs: IComponentAdapter,
        @inject(IExperimentService) private readonly experimentService: IExperimentService,
    ) {}

    public async activate(resource: Uri): Promise<void> {
        const disposable = this.pyenvs.onDidCreate(resource, () => this.handleNewEnvironment(resource));
        if (disposable) {
            this.disposableRegistry.push(disposable);
            return;
        }
        const builder = this.serviceContainer.get<IInterpreterWatcherBuilder>(IInterpreterWatcherBuilder);
        const watcher = await builder.getWorkspaceVirtualEnvInterpreterWatcher(resource);
        watcher.onDidCreate(
            () => {
                this.handleNewEnvironment(resource).ignoreErrors();
            },
            this,
            this.disposableRegistry,
        );
    }
<commit_msg>Remove fallback from virtual environment prompt (#15207)<commit_after>// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { inject, injectable } from 'inversify';
import { ConfigurationTarget, Disposable, Uri } from 'vscode';
import { IExtensionActivationService } from '../../activation/types';
import { IApplicationShell } from '../../common/application/types';
import { inDiscoveryExperiment } from '../../common/experiments/helpers';
import { traceDecorators } from '../../common/logger';
import { IDisposableRegistry, IExperimentService, IPersistentStateFactory } from '../../common/types';
import { sleep } from '../../common/utils/async';
import { Common, Interpreters } from '../../common/utils/localize';
import { IServiceContainer } from '../../ioc/types';
import { PythonEnvironment } from '../../pythonEnvironments/info';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { IPythonPathUpdaterServiceManager } from '../configuration/types';
import {
    IComponentAdapter,
    IInterpreterHelper,
    IInterpreterLocatorService,
    IInterpreterWatcherBuilder,
    WORKSPACE_VIRTUAL_ENV_SERVICE,
} from '../contracts';

const doNotDisplayPromptStateKey = 'MESSAGE_KEY_FOR_VIRTUAL_ENV';
@injectable()
export class VirtualEnvironmentPrompt implements IExtensionActivationService {
    constructor(
        @inject(IServiceContainer) private readonly serviceContainer: IServiceContainer,
        @inject(IPersistentStateFactory) private readonly persistentStateFactory: IPersistentStateFactory,
        @inject(IInterpreterHelper) private readonly helper: IInterpreterHelper,
        @inject(IPythonPathUpdaterServiceManager)
        private readonly pythonPathUpdaterService: IPythonPathUpdaterServiceManager,
        @inject(IDisposableRegistry) private readonly disposableRegistry: Disposable[],
        @inject(IApplicationShell) private readonly appShell: IApplicationShell,
        @inject(IComponentAdapter) private readonly pyenvs: IComponentAdapter,
        @inject(IExperimentService) private readonly experimentService: IExperimentService,
    ) {}

    public async activate(resource: Uri): Promise<void> {
        if (await inDiscoveryExperiment(this.experimentService)) {
            const disposable = this.pyenvs.onDidCreate(resource, () => this.handleNewEnvironment(resource));
            if (disposable) {
                this.disposableRegistry.push(disposable);
            }
            // This is to prevent fallback
            return;
        }

        const builder = this.serviceContainer.get<IInterpreterWatcherBuilder>(IInterpreterWatcherBuilder);
        const watcher = await builder.getWorkspaceVirtualEnvInterpreterWatcher(resource);
        watcher.onDidCreate(
            () => {
                this.handleNewEnvironment(resource).ignoreErrors();
            },
            this,
            this.disposableRegistry,
        );
    }

{'fraction_non_alphanumeric': 0.10694635488308116, 'fraction_numerical': 0.0008596973865199449, 'mean_word_length': 3.8475, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3222972', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1478, 'n_words': 328}