forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvslshost.ts
More file actions
70 lines (63 loc) · 2.66 KB
/
vslshost.ts
File metadata and controls
70 lines (63 loc) · 2.66 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
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { LiveShare, SharedService } from 'vsls/vscode.js';
import { Model } from './model';
import { VSLS_GIT_PR_SESSION_NAME, VSLS_REQUEST_NAME, VSLS_REPOSITORY_INITIALIZATION_NAME, VSLS_STATE_CHANGE_NOFITY_NAME } from '../constants';
export class VSLSHost implements vscode.Disposable {
private _sharedService?: SharedService;
private _disposables: vscode.Disposable[];
constructor(private _api: LiveShare, private _model: Model) {
this._disposables = [];
}
public async initialize() {
this._sharedService = await this._api!.shareService(VSLS_GIT_PR_SESSION_NAME) || undefined;
if (this._sharedService) {
this._sharedService.onRequest(VSLS_REQUEST_NAME, this._gitHandler.bind(this));
}
}
private async _gitHandler(args: any[]) {
let type = args[0];
let workspaceFolderPath = args[1];
let workspaceFolderUri = vscode.Uri.parse(workspaceFolderPath);
let localWorkSpaceFolderUri = this._api.convertSharedUriToLocal(workspaceFolderUri);
let localRepository: any = this._model.repositories.filter(repository => repository.rootUri.toString() === localWorkSpaceFolderUri.toString())[0];
if (localRepository) {
let commandArgs = args.slice(2);
if (type === VSLS_REPOSITORY_INITIALIZATION_NAME) {
this._disposables.push(localRepository.state.onDidChange((e: any) => {
this._sharedService!.notify(VSLS_STATE_CHANGE_NOFITY_NAME, {
HEAD: localRepository.state.HEAD,
remotes: localRepository.state.remotes,
refs: localRepository.state.refs
});
}));
return {
HEAD: localRepository.state.HEAD,
remotes: localRepository.state.remotes,
refs: localRepository.state.refs,
rootUri: workspaceFolderUri.toString() // file: --> vsls:/
};
}
if (type === 'show') {
let path = commandArgs[1];
let vslsFileUri = workspaceFolderUri.with({path: path});
let localFileUri = this._api.convertSharedUriToLocal(vslsFileUri);
commandArgs[1] = localFileUri.fsPath;
return localRepository[type](...commandArgs);
}
if (localRepository[type]) {
return localRepository[type](...commandArgs);
}
} else {
return null;
}
}
public dispose() {
this._disposables.forEach(d => d.dispose());
this._sharedService = undefined;
this._disposables = [];
}
}