Skip to content

Commit 13fdf4c

Browse files
Kartik Rajkarthiknadig
authored andcommitted
Fix unresponsive extension issues caused by discovery component (#17781)
* Fix unresponsive extension issues caused by discovery component * News entry * Add doc comment
1 parent ca2b5a4 commit 13fdf4c

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

news/2 Fixes/11924.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix unresponsive extension issues caused by discovery component.

src/client/common/utils/misc.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import type { TextDocument, Uri } from 'vscode';
55
import { InteractiveInputScheme, NotebookCellScheme } from '../constants';
66
import { InterpreterUri } from '../installer/types';
7-
import { arePathsSame, isParentPath } from '../platform/fs-paths';
7+
import { isParentPath } from '../platform/fs-paths';
88
import { Resource } from '../types';
99
import { isPromise } from './async';
1010
import { StopWatch } from './stopWatch';
@@ -103,19 +103,19 @@ function isUri(resource?: Uri | any): resource is Uri {
103103
* The scheme must match, as well as path.
104104
*
105105
* @param checkParent - if `true`, match if the candidate is rooted under `uri`
106+
* or if the candidate matches `uri` exactly.
106107
* @param checkChild - if `true`, match if `uri` is rooted under the candidate
107-
* @param checkExact - if `true`, match if the candidate matches `uri` exactly
108+
* or if the candidate matches `uri` exactly.
108109
*/
109110
export function getURIFilter(
110111
uri: Uri,
111112
opts: {
112113
checkParent?: boolean;
113114
checkChild?: boolean;
114-
checkExact?: boolean;
115-
} = { checkExact: true },
115+
} = { checkParent: true },
116116
): (u: Uri) => boolean {
117117
let uriPath = uri.path;
118-
while (uri.path.endsWith('/')) {
118+
while (uriPath.endsWith('/')) {
119119
uriPath = uriPath.slice(0, -1);
120120
}
121121
const uriRoot = `${uriPath}/`;
@@ -124,12 +124,9 @@ export function getURIFilter(
124124
return false;
125125
}
126126
let candidatePath = candidate.path;
127-
while (candidate.path.endsWith('/')) {
127+
while (candidatePath.endsWith('/')) {
128128
candidatePath = candidatePath.slice(0, -1);
129129
}
130-
if (opts.checkExact && arePathsSame(candidatePath, uriPath)) {
131-
return true;
132-
}
133130
if (opts.checkParent && isParentPath(candidatePath, uriRoot)) {
134131
return true;
135132
}

src/client/pythonEnvironments/base/locatorUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ function getSearchLocationFilters(query: PythonLocatorQuery): ((u: Uri) => boole
5555
return query.searchLocations.roots.map((loc) =>
5656
getURIFilter(loc, {
5757
checkParent: true,
58-
checkExact: true,
5958
}),
6059
);
6160
}

src/client/pythonEnvironments/base/locators/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class WorkspaceLocators<I = PythonEnvInfo> extends LazyResourceBasedLocat
7373
if (query?.searchLocations !== undefined) {
7474
const root = this.roots[key];
7575
// Match any related search location.
76-
const filter = getURIFilter(root, { checkParent: true, checkChild: true, checkExact: true });
76+
const filter = getURIFilter(root, { checkParent: true, checkChild: true });
7777
// Ignore any requests for global envs.
7878
if (!query.searchLocations.roots.some(filter)) {
7979
// This workspace folder did not match the query, so skip it!

src/test/pythonEnvironments/base/locatorUtils.unit.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const envL2 = createLocatedEnv('/conda/envs/envL2', '3.8.3', PythonEnvKind.Conda
3737
const locatedEnvs = [envL1, envL2];
3838

3939
const envS1 = createNamedEnv('env S1', '3.9', PythonEnvKind.OtherVirtual, `${homeDir}/some-dir/bin/python`);
40-
setSearchLocation(envS1, homeDir);
40+
setSearchLocation(envS1, `${homeDir}/`); // Have a search location ending in '/'
4141
const envS2 = createNamedEnv('env S2', '3.9', PythonEnvKind.OtherVirtual, `${homeDir}/some-dir2/bin/python`);
4242
setSearchLocation(envS2, homeDir);
4343
const envS3 = createNamedEnv('env S2', '3.9', PythonEnvKind.OtherVirtual, `${workspaceRoot.fsPath}/p/python`);
@@ -178,6 +178,20 @@ suite('Python envs locator utils - getQueryFilter', () => {
178178
assert.deepEqual(filtered, expected);
179179
});
180180

181+
test("match multiple (one location) uri path ending in '/'", () => {
182+
const expected = [envS3, envSL2];
183+
const searchLocations = {
184+
roots: [Uri.file(`${workspaceRoot.path}/`)],
185+
doNotIncludeNonRooted: true,
186+
};
187+
const query: PythonLocatorQuery = { searchLocations };
188+
189+
const filter = getQueryFilter(query);
190+
const filtered = envs.filter(filter);
191+
192+
assert.deepEqual(filtered, expected);
193+
});
194+
181195
test('match multiple (multiple locations)', () => {
182196
const expected = [envS3, ...rootedLocatedEnvs];
183197
const searchLocations = {

0 commit comments

Comments
 (0)