File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed
src/client/pythonEnvironments/base Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change 1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
4
- import { Event } from 'vscode' ;
4
+ import { Disposable , Event } from 'vscode' ;
5
+ import { Disableable } from '../../common/utils/misc' ;
5
6
import { IPythonEnvsWatcher , PythonEnvsChangedEvent , PythonEnvsWatcher } from './watcher' ;
6
7
7
8
/**
@@ -21,3 +22,33 @@ export class PythonEnvsWatchers {
21
22
} ) ;
22
23
}
23
24
}
25
+
26
+ // tslint:disable-next-line:no-any
27
+ type EnvsEventListener = ( e : PythonEnvsChangedEvent ) => any ;
28
+
29
+ /**
30
+ * A watcher wrapper that can be disabled.
31
+ *
32
+ * If disabled, events emitted by the wrapped watcher are discarded.
33
+ */
34
+ export class DisableableEnvsWatcher extends Disableable {
35
+ constructor (
36
+ // To wrap more than one use `PythonEnvWatchers`.
37
+ private readonly wrapped : IPythonEnvsWatcher
38
+ ) {
39
+ super ( ) ;
40
+ }
41
+
42
+ // tslint:disable-next-line:no-any
43
+ public onChanged ( listener : EnvsEventListener , thisArgs ?: any , disposables ?: Disposable [ ] ) : Disposable {
44
+ return this . wrapped . onChanged (
45
+ ( e : PythonEnvsChangedEvent ) => {
46
+ if ( this . isEnabled ) {
47
+ listener ( e ) ;
48
+ }
49
+ } ,
50
+ thisArgs ,
51
+ disposables
52
+ ) ;
53
+ }
54
+ }
You can’t perform that action at this time.
0 commit comments