Skip to content

Commit ed26a60

Browse files
DonJayamanneKartik Raj
andauthored
Remove items from array in reverse order (#18383)
* Remove items from array in reverse order * Fix linter * Update src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts Co-authored-by: Kartik Raj <karraj@microsoft.com> * Update src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts Co-authored-by: Kartik Raj <karraj@microsoft.com>
1 parent 4758b35 commit ed26a60

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

news/2 Fixes/18382.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure items are removed from the array in reverse order when using array indices.

src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ export class PythonEnvInfoCache extends PythonEnvsWatcher<PythonEnvCollectionCha
8484
* exist.
8585
*/
8686
const areEnvsValid = await Promise.all(this.envs.map((e) => pathExists(e.executable.filename)));
87-
const invalidIndexes = areEnvsValid.map((isValid, index) => (isValid ? -1 : index)).filter((i) => i !== -1);
87+
const invalidIndexes = areEnvsValid
88+
.map((isValid, index) => (isValid ? -1 : index))
89+
.filter((i) => i !== -1)
90+
.reverse(); // Reversed so indexes do not change when deleting
8891
invalidIndexes.forEach((index) => {
8992
const env = this.envs.splice(index, 1)[0];
9093
this.fire({ old: env, new: undefined });

0 commit comments

Comments
 (0)