forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6701fe
commit fd28299
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/client/pythonEnvironments/base/locators/common/pythonWatcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { | ||
Disposable, | ||
Event, | ||
EventEmitter, | ||
FileChangeType, | ||
FileSystemWatcher, | ||
RelativePattern, | ||
Uri, | ||
WorkspaceFolder, | ||
WorkspaceFoldersChangeEvent, | ||
} from 'vscode'; | ||
import { NativeEnvInfo } from './nativePythonFinder'; | ||
import { NativePythonEnvironmentKind } from './nativePythonUtils'; | ||
import { | ||
createFileSystemWatcher, | ||
getWorkspaceFolder, | ||
getWorkspaceFolderPaths, | ||
} from '../../../../common/vscodeApis/workspaceApis'; | ||
|
||
export interface PythonWorkspaceEnvEvent { | ||
type: FileChangeType; | ||
workspaceFolder: WorkspaceFolder; | ||
envs?: NativeEnvInfo[]; | ||
} | ||
|
||
export interface PythonGlobalEnvEvent { | ||
kind?: NativePythonEnvironmentKind; | ||
type?: FileChangeType; | ||
} | ||
|
||
export interface PythonWatcher extends Disposable { | ||
watchPath(uri: Uri): Disposable; | ||
onDidWorkspaceEnvChanged: Event<PythonWorkspaceEnvEvent>; | ||
onDidGlobalEnvChanged: Event<PythonGlobalEnvEvent>; | ||
} | ||
|
||
class PythonWatcherImpl implements PythonWatcher { | ||
private disposables: Disposable[] = []; | ||
|
||
private readonly _onDidWorkspaceEnvChanged = new EventEmitter<PythonWorkspaceEnvEvent>(); | ||
|
||
private readonly _onDidGlobalEnvChanged = new EventEmitter<PythonGlobalEnvEvent>(); | ||
|
||
constructor() { | ||
this.disposables.push(this._onDidWorkspaceEnvChanged, this._onDidGlobalEnvChanged); | ||
} | ||
|
||
onDidGlobalEnvChanged: Event<PythonGlobalEnvEvent> = this._onDidGlobalEnvChanged.event; | ||
|
||
onDidWorkspaceEnvChanged: Event<PythonWorkspaceEnvEvent> = this._onDidWorkspaceEnvChanged.event; | ||
|
||
watchPath(uri: Uri): Disposable { | ||
const wf = getWorkspaceFolder(uri); | ||
if (wf) { | ||
const watcher = this.watchWorkspaceFolder(wf); | ||
return watcher; | ||
} | ||
} | ||
|
||
private watchWorkspaceFolder(workspaceFolder: WorkspaceFolder): Disposable { | ||
const watcher = createFileSystemWatcher(new RelativePattern(workspaceFolder)); | ||
} | ||
} | ||
|
||
export function createPythonWatcher(): PythonWatcher { | ||
return new PythonWatcherImpl(); | ||
} |