Skip to content

Commit f835c57

Browse files
committed
Only watch files on a non virtual workspace
1 parent 947935d commit f835c57

File tree

6 files changed

+28
-23
lines changed

6 files changed

+28
-23
lines changed

src/client/pythonEnvironments/base/locators/common/resourceBasedLocator.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { IDisposable } from '../../../../common/types';
55
import { createDeferred, Deferred } from '../../../../common/utils/async';
66
import { Disposables } from '../../../../common/utils/resourceLifecycle';
77
import { traceError } from '../../../../logging';
8-
import { arePathsSame } from '../../../common/externalDependencies';
8+
import { arePathsSame, isVirtualWorkspace } from '../../../common/externalDependencies';
99
import { getEnvPath } from '../../info/env';
1010
import { BasicEnvInfo, IPythonEnvsIterator, Locator, PythonLocatorQuery } from '../../locator';
1111

@@ -123,10 +123,14 @@ export abstract class LazyResourceBasedLocator extends Locator<BasicEnvInfo> imp
123123
return;
124124
}
125125
this.watchersReady = createDeferred<void>();
126-
await this.initWatchers().catch((ex) => {
127-
traceError(ex);
128-
this.watchersReady?.reject(ex);
129-
});
130-
this.watchersReady.resolve();
126+
127+
// Don't create any file watchers in a virtual workspace.
128+
if (!(await isVirtualWorkspace())) {
129+
await this.initWatchers().catch((ex) => {
130+
traceError(ex);
131+
this.watchersReady?.reject(ex);
132+
});
133+
this.watchersReady.resolve();
134+
}
131135
}
132136
}

src/client/pythonEnvironments/base/locators/lowLevel/workspaceVirtualEnvLocator.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
import * as path from 'path';
5-
import { Uri } from 'vscode';
65
import { chain, iterable } from '../../../../common/utils/async';
76
import { findInterpretersInDir, looksLikeBasicVirtualPython } from '../../../common/commonUtils';
87
import { pathExists } from '../../../common/externalDependencies';
@@ -54,9 +53,9 @@ async function getVirtualEnvKind(interpreterPath: string): Promise<PythonEnvKind
5453
export class WorkspaceVirtualEnvironmentLocator extends FSWatchingLocator {
5554
public readonly providerId: string = 'workspaceVirtualEnvLocator';
5655

57-
public constructor(private readonly root: Uri) {
56+
public constructor(private readonly root: string) {
5857
super(
59-
() => (this.root.scheme === 'file' ? getWorkspaceVirtualEnvDirs(this.root.fsPath) : []),
58+
() => getWorkspaceVirtualEnvDirs(this.root),
6059
getVirtualEnvKind,
6160
{
6261
// Note detecting kind of virtual env depends on the file structure around the
@@ -68,8 +67,8 @@ export class WorkspaceVirtualEnvironmentLocator extends FSWatchingLocator {
6867
}
6968

7069
protected doIterEnvs(): IPythonEnvsIterator<BasicEnvInfo> {
71-
async function* iterator(root: Uri) {
72-
const envRootDirs = root.scheme === 'file' ? await getWorkspaceVirtualEnvDirs(root.fsPath) : [];
70+
async function* iterator(root: string) {
71+
const envRootDirs = await getWorkspaceVirtualEnvDirs(root);
7372
const envGenerators = envRootDirs.map((envRootDir) => {
7473
async function* generator() {
7574
traceVerbose(`Searching for workspace virtual envs in: ${envRootDir}`);

src/client/pythonEnvironments/common/externalDependencies.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import * as fsapi from 'fs-extra';
55
import * as path from 'path';
66
import * as vscode from 'vscode';
7+
import { IWorkspaceService } from '../../common/application/types';
78
import { ExecutionResult, IProcessServiceFactory, ShellOptions, SpawnOptions } from '../../common/process/types';
89
import { IDisposable, IConfigurationService } from '../../common/types';
910
import { chain, iterable } from '../../common/utils/async';
@@ -27,6 +28,13 @@ export async function exec(file: string, args: string[], options: SpawnOptions =
2728
return service.exec(file, args, options);
2829
}
2930

31+
// Workspace
32+
33+
export async function isVirtualWorkspace(): Promise<boolean> {
34+
const service = internalServiceContainer.get<IWorkspaceService>(IWorkspaceService);
35+
return service.isVirtualWorkspace;
36+
}
37+
3038
// filesystem
3139

3240
export function pathExists(absPath: string): Promise<boolean> {

src/client/pythonEnvironments/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function watchRoots(args: WatchRootsArgs): IDisposable {
179179

180180
function createWorkspaceLocator(ext: ExtensionState): WorkspaceLocators {
181181
const locators = new WorkspaceLocators(watchRoots, [
182-
(root: vscode.Uri) => [new WorkspaceVirtualEnvironmentLocator(root), new PoetryLocator(root.fsPath)],
182+
(root: vscode.Uri) => [new WorkspaceVirtualEnvironmentLocator(root.fsPath), new PoetryLocator(root.fsPath)],
183183
// Add an ILocator factory func here for each kind of workspace-rooted locator.
184184
]);
185185
ext.disposables.push(locators);

src/test/pythonEnvironments/base/locators/lowLevel/workspaceVirtualEnvLocator.testvirtualenvs.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
22
// Licensed under the MIT License.
33

44
import * as path from 'path';
5-
import { Uri } from 'vscode';
65
import { PythonEnvKind } from '../../../../../client/pythonEnvironments/base/info';
76
import { WorkspaceVirtualEnvironmentLocator } from '../../../../../client/pythonEnvironments/base/locators/lowLevel/workspaceVirtualEnvLocator';
87
import { TEST_LAYOUT_ROOT } from '../../../common/commonTestConstants';
98
import { testLocatorWatcher } from './watcherTestUtils';
109

1110
suite('WorkspaceVirtualEnvironment Locator', async () => {
1211
const testWorkspaceFolder = path.join(TEST_LAYOUT_ROOT, 'workspace', 'folder1');
13-
testLocatorWatcher(
14-
testWorkspaceFolder,
15-
async (root?: string) => new WorkspaceVirtualEnvironmentLocator(Uri.file(root!)),
16-
{
17-
arg: testWorkspaceFolder,
18-
kind: PythonEnvKind.Venv,
19-
},
20-
);
12+
testLocatorWatcher(testWorkspaceFolder, async (root?: string) => new WorkspaceVirtualEnvironmentLocator(root!), {
13+
arg: testWorkspaceFolder,
14+
kind: PythonEnvKind.Venv,
15+
});
2116
});

src/test/pythonEnvironments/base/locators/lowLevel/workspaceVirtualEnvLocator.unit.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import * as path from 'path';
55
import * as sinon from 'sinon';
6-
import { Uri } from 'vscode';
76
import * as fsWatcher from '../../../../../client/common/platform/fileSystemWatcher';
87
import * as platformUtils from '../../../../../client/common/utils/platform';
98
import { PythonEnvKind } from '../../../../../client/pythonEnvironments/base/info';
@@ -28,7 +27,7 @@ suite('WorkspaceVirtualEnvironment Locator', () => {
2827
/* do nothing */
2928
},
3029
});
31-
locator = new WorkspaceVirtualEnvironmentLocator(Uri.file(testWorkspaceFolder));
30+
locator = new WorkspaceVirtualEnvironmentLocator(testWorkspaceFolder);
3231
});
3332
teardown(async () => {
3433
await locator.dispose();

0 commit comments

Comments
 (0)