forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjediProxyFactory.ts
More file actions
38 lines (34 loc) · 1.77 KB
/
jediProxyFactory.ts
File metadata and controls
38 lines (34 loc) · 1.77 KB
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
import { Disposable, Uri, workspace } from 'vscode';
import { IServiceContainer } from '../ioc/types';
import { ICommandResult, JediProxy, JediProxyHandler } from '../providers/jediProxy';
export class JediFactory implements Disposable {
private disposables: Disposable[];
private jediProxyHandlers: Map<string, JediProxyHandler<ICommandResult>>;
constructor(private extensionRootPath: string, private serviceContainer: IServiceContainer) {
this.disposables = [];
this.jediProxyHandlers = new Map<string, JediProxyHandler<ICommandResult>>();
}
public dispose() {
this.disposables.forEach(disposable => disposable.dispose());
this.disposables = [];
}
public getJediProxyHandler<T extends ICommandResult>(resource?: Uri): JediProxyHandler<T> {
const workspaceFolder = resource ? workspace.getWorkspaceFolder(resource) : undefined;
let workspacePath = workspaceFolder ? workspaceFolder.uri.fsPath : undefined;
if (!workspacePath) {
if (Array.isArray(workspace.workspaceFolders) && workspace.workspaceFolders.length > 0) {
workspacePath = workspace.workspaceFolders[0].uri.fsPath;
} else {
workspacePath = __dirname;
}
}
if (!this.jediProxyHandlers.has(workspacePath)) {
const jediProxy = new JediProxy(this.extensionRootPath, workspacePath, this.serviceContainer);
const jediProxyHandler = new JediProxyHandler(jediProxy);
this.disposables.push(jediProxy, jediProxyHandler);
this.jediProxyHandlers.set(workspacePath, jediProxyHandler);
}
// tslint:disable-next-line:no-non-null-assertion
return this.jediProxyHandlers.get(workspacePath)! as JediProxyHandler<T>;
}
}