FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
vscode-python/src/client/pythonEnvironments/base/locators.ts at main · microsoft/vscode-python · GitHub
microsoft
vscode-python
Repository navigation
Code
Issues
344
(344)
Pull requests
53
(53)
Discussions
Actions
Wiki
Security and quality
2
(2)
Insights
Expand file tree
Breadcrumbs
vscode-python
/
src
/
client
/
pythonEnvironments
/
base
/
locators.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
78 lines (72 loc) · 2.78 KB
Breadcrumbs
vscode-python
/
src
/
client
/
pythonEnvironments
/
base
/
locators.ts
Copy path
File metadata and controls
78 lines (72 loc) · 2.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import
{
chain
}
from
'../../common/utils/async'
;
import
{
Disposables
}
from
'../../common/utils/resourceLifecycle'
;
import
{
PythonEnvInfo
}
from
'./info'
;
import
{
ICompositeLocator
,
ILocator
,
IPythonEnvsIterator
,
isProgressEvent
,
ProgressNotificationEvent
,
ProgressReportStage
,
PythonEnvUpdatedEvent
,
PythonLocatorQuery
,
}
from
'./locator'
;
import
{
PythonEnvsWatchers
}
from
'./watchers'
;
/**
* Combine the `onUpdated` event of the given iterators into a single event.
*/
export
function
combineIterators
<
I
>
(
iterators
:
IPythonEnvsIterator
<
I
>
[
]
)
:
IPythonEnvsIterator
<
I
>
{
const
result
:
IPythonEnvsIterator
<
I
>
=
chain
(
iterators
)
;
const
events
=
iterators
.
map
(
(
it
)
=>
it
.
onUpdated
)
.
filter
(
(
v
)
=>
v
)
;
if
(
!
events
||
events
.
length
===
0
)
{
// There are no sub-events, so we leave `onUpdated` undefined.
return
result
;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
result
.
onUpdated
=
(
handleEvent
:
(
e
:
PythonEnvUpdatedEvent
<
I
>
|
ProgressNotificationEvent
)
=>
any
)
=>
{
const
disposables
=
new
Disposables
(
)
;
let
numActive
=
events
.
length
;
events
.
forEach
(
(
event
)
=>
{
const
disposable
=
event
!
(
(
e
:
PythonEnvUpdatedEvent
<
I
>
|
ProgressNotificationEvent
)
=>
{
// NOSONAR
if
(
isProgressEvent
(
e
)
)
{
if
(
e
.
stage
===
ProgressReportStage
.
discoveryFinished
)
{
numActive
-=
1
;
if
(
numActive
===
0
)
{
// All the sub-events are done so we're done.
handleEvent
(
{
stage
:
ProgressReportStage
.
discoveryFinished
}
)
;
}
}
else
{
handleEvent
(
{
stage
:
e
.
stage
}
)
;
}
}
else
{
handleEvent
(
e
)
;
}
}
)
;
disposables
.
push
(
disposable
)
;
}
)
;
return
disposables
;
}
;
return
result
;
}
/**
* A wrapper around a set of locators, exposing them as a single locator.
*
* Events and iterator results are combined.
*/
export
class
Locators
<
I
=
PythonEnvInfo
>
extends
PythonEnvsWatchers
implements
ICompositeLocator
<
I
>
{
public
readonly
providerId
:
string
;
constructor
(
// The locators will be watched as well as iterated.
private
readonly
locators
:
ReadonlyArray
<
ILocator
<
I
>
>
,
)
{
super
(
locators
)
;
this
.
providerId
=
locators
.
map
(
(
loc
)
=>
loc
.
providerId
)
.
join
(
'+'
)
;
}
public
iterEnvs
(
query
?:
PythonLocatorQuery
)
:
IPythonEnvsIterator
<
I
>
{
const
iterators
=
this
.
locators
.
map
(
(
loc
)
=>
loc
.
iterEnvs
(
query
)
)
;
return
combineIterators
(
iterators
)
;
}
}
Back
|
FazBrowse Home
|
New Git URL