Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/startup-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ All three trigger `initialize()` lazily (once-only, guarded by `_initialized` de
---

POST-INIT:
1. register terminal package watcher
1. register package watchers for workspace-selected and terminal-activated environments
2. register settings change listener (`registerInterpreterSettingsChangeListener`) — re-runs priority chain if settings change
3. initialize terminal manager
4. send telemetry (manager selection, project structure, discovery summary)
25 changes: 6 additions & 19 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ import { cleanupStartupScripts } from './features/terminal/shellStartupSetupHand
import { TerminalActivationImpl } from './features/terminal/terminalActivationState';
import { TerminalEnvVarInjector } from './features/terminal/terminalEnvVarInjector';
import { TerminalManager, TerminalManagerImpl } from './features/terminal/terminalManager';
import { registerTerminalPackageWatcher } from './features/terminal/terminalPackageWatcher';
import { getEnvironmentForTerminal } from './features/terminal/utils';
import { openSearchSettings } from './features/views/envManagerSearch';
import { EnvManagerView } from './features/views/envManagersView';
import { ProjectView } from './features/views/projectView';
import { PythonStatusBarImpl } from './features/views/pythonStatusBar';
import { updateViewsAndStatus } from './features/views/revealHandler';
import { TemporaryStateManager } from './features/views/temporaryStateManager';
import { ProjectItem, PythonEnvTreeItem } from './features/views/treeViewItems';
import { PythonEnvTreeItem } from './features/views/treeViewItems';
import { collectEnvironmentInfo, getEnvManagerAndPackageManagerConfigLevels, runPetInTerminalImpl } from './helpers';
import { EnvironmentManagers, ProjectCreators, PythonProjectManager } from './internal.api';
import { registerSystemPythonFeatures } from './managers/builtin/main';
import { registerInlineScriptFeatures } from './managers/builtin/inlineScript/main';
import { registerSystemPythonFeatures } from './managers/builtin/main';
import { SysPythonManager } from './managers/builtin/sysPythonManager';
import {
createNativePythonFinder,
getNativePythonToolsPathAndSource,
getNativePythonToolsVersion,
NativePythonFinder,
} from './managers/common/nativePythonFinder';
import { registerPackageWatchers } from './managers/common/packageWatcher';
import { IDisposable } from './managers/common/types';
import { registerCondaFeatures } from './managers/conda/main';
import { registerPipenvFeatures } from './managers/pipenv/main';
Expand Down Expand Up @@ -364,17 +364,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
});
}),
commands.registerCommand('python-envs.removePythonProject', async (item) => {
// Clear environment association before removing project
if (item instanceof ProjectItem) {
const uri = item.project.uri;
const manager = envManagers.getEnvironmentManager(uri);
if (manager) {
manager.set(uri, undefined);
} else {
traceError(`No environment manager found for ${uri.fsPath}`);
}
}
await removePythonProject(item, projectManager);
await removePythonProject(item, projectManager, envManagers);
}),
commands.registerCommand('python-envs.clearCache', async () => {
await clearPersistentState();
Expand Down Expand Up @@ -672,6 +662,8 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
safeRegister('shellStartupVars', shellStartupVarsMgr.initialize()),
]);

context.subscriptions.push(registerPackageWatchers(envManagers, terminalActivation, outputChannel));

failureStage = 'envSelection';
stageWatch.reset();
await applyInitialEnvironmentSelection(
Expand All @@ -683,11 +675,6 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
globalScopeDeferredRef,
);

// Register manager-agnostic terminal watcher for package-modifying commands
failureStage = 'terminalWatcher';
stageWatch.reset();
registerTerminalPackageWatcher(api, terminalActivation, outputChannel, context.subscriptions);

// Register listener for interpreter settings changes for interpreter re-selection
failureStage = 'settingsListener';
stageWatch.reset();
Expand Down
7 changes: 6 additions & 1 deletion src/features/envCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,12 @@ export async function addPythonProjectCommand(
}
}

export async function removePythonProject(item: ProjectItem, wm: PythonProjectManager): Promise<void> {
export async function removePythonProject(
item: ProjectItem,
wm: PythonProjectManager,
em: EnvironmentManagers,
): Promise<void> {
await em.setEnvironment(item.project.uri, undefined);
await removePythonProjectSetting([{ project: item.project }]);
wm.remove(item.project);
}
Expand Down
111 changes: 0 additions & 111 deletions src/features/terminal/terminalPackageWatcher.ts

This file was deleted.

6 changes: 5 additions & 1 deletion src/internal.api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Pep440Version } from '@renovatebot/pep440';
import { CancellationError, Disposable, Event, LogOutputChannel, MarkdownString, Uri } from 'vscode';
import { CancellationError, Disposable, Event, LogOutputChannel, MarkdownString, RelativePattern, Uri } from 'vscode';
import {
CreateEnvironmentOptions,
CreateEnvironmentScope,
Expand Down Expand Up @@ -380,6 +380,10 @@ export class InternalPackageManager implements PackageManager {
return this.manager.getPackages(environment, options);
}

getPackageWatchTargets(environment: PythonEnvironment): RelativePattern[] {
return this.manager.getPackageWatchTargets?.(environment) ?? [];
}

onDidChangePackages(handler: (e: DidChangePackagesEventArgs) => void): Disposable {
return this.manager.onDidChangePackages ? this.manager.onDidChangePackages(handler) : new Disposable(() => {});
}
Expand Down
6 changes: 0 additions & 6 deletions src/managers/builtin/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createSimpleDebounce } from '../../common/utils/debounce';
import { createFileSystemWatcher, onDidDeleteFiles } from '../../common/workspace.apis';
import { getPythonApi } from '../../features/pythonApi';
import { NativePythonFinder } from '../common/nativePythonFinder';
import { registerPackageWatcherForManager } from '../common/packageWatcher';
import { PipPackageManager } from './pipPackageManager';
import { SysPythonManager } from './sysPythonManager';
import { VenvManager } from './venvManager';
Expand Down Expand Up @@ -41,9 +40,4 @@ export async function registerSystemPythonFeatures(
venvDebouncedRefresh.trigger();
}),
);

disposables.push(
registerPackageWatcherForManager(envManager, pkgManager, log),
registerPackageWatcherForManager(venvManager, pkgManager, log),
);
}
6 changes: 5 additions & 1 deletion src/managers/builtin/pipPackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ export class PipPackageManager implements PackageManager, Disposable {
async getPackages(environment: PythonEnvironment, options?: GetPackagesOptions): Promise<Package[] | undefined> {
if (options?.skipCache || !this.packages.has(environment.envId.id)) {
const data = await refreshPipPackages(environment, this.log);
const packages = (data ?? []).map((pkg) => this.api.createPackageItem(pkg, environment, this));
if (data === undefined) {
return this.packages.get(environment.envId.id);
}

const packages = data.map((pkg) => this.api.createPackageItem(pkg, environment, this));
this.packages.set(environment.envId.id, packages);
return packages;
}
Expand Down
Loading
Loading