Skip to content

Commit

Permalink
midway broken state
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Jul 22, 2024
1 parent e6701fe commit fd28299
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/client/common/vscodeApis/workspaceApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,23 @@ export function onDidChangeTextDocument(handler: (e: vscode.TextDocumentChangeEv
export function onDidChangeConfiguration(handler: (e: vscode.ConfigurationChangeEvent) => unknown): vscode.Disposable {
return vscode.workspace.onDidChangeConfiguration(handler);
}

export function createFileSystemWatcher(
globPattern: vscode.GlobPattern,
ignoreCreateEvents?: boolean,
ignoreChangeEvents?: boolean,
ignoreDeleteEvents?: boolean,
): vscode.FileSystemWatcher {
return vscode.workspace.createFileSystemWatcher(
globPattern,
ignoreCreateEvents,
ignoreChangeEvents,
ignoreDeleteEvents,
);
}

export function onDidChangeWorkspaceFolders(
handler: (e: vscode.WorkspaceFoldersChangeEvent) => unknown,
): vscode.Disposable {
return vscode.workspace.onDidChangeWorkspaceFolders(handler);
}
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();
}

0 comments on commit fd28299

Please sign in to comment.