Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/git/src/api/extension.ts
3320 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Model } from '../model';
7
import { GitExtension, Repository, API } from './git';
8
import { ApiRepository, ApiImpl } from './api1';
9
import { Event, EventEmitter } from 'vscode';
10
11
function deprecated(original: any, context: ClassMemberDecoratorContext) {
12
if (context.kind !== 'method') {
13
throw new Error('not supported');
14
}
15
16
const key = context.name.toString();
17
return function (this: any, ...args: any[]): any {
18
console.warn(`Git extension API method '${key}' is deprecated.`);
19
return original.apply(this, args);
20
};
21
}
22
23
export class GitExtensionImpl implements GitExtension {
24
25
enabled: boolean = false;
26
27
private _onDidChangeEnablement = new EventEmitter<boolean>();
28
readonly onDidChangeEnablement: Event<boolean> = this._onDidChangeEnablement.event;
29
30
private _model: Model | undefined = undefined;
31
32
set model(model: Model | undefined) {
33
this._model = model;
34
35
const enabled = !!model;
36
37
if (this.enabled === enabled) {
38
return;
39
}
40
41
this.enabled = enabled;
42
this._onDidChangeEnablement.fire(this.enabled);
43
}
44
45
get model(): Model | undefined {
46
return this._model;
47
}
48
49
constructor(model?: Model) {
50
if (model) {
51
this.enabled = true;
52
this._model = model;
53
}
54
}
55
56
@deprecated
57
async getGitPath(): Promise<string> {
58
if (!this._model) {
59
throw new Error('Git model not found');
60
}
61
62
return this._model.git.path;
63
}
64
65
@deprecated
66
async getRepositories(): Promise<Repository[]> {
67
if (!this._model) {
68
throw new Error('Git model not found');
69
}
70
71
return this._model.repositories.map(repository => new ApiRepository(repository));
72
}
73
74
getAPI(version: number): API {
75
if (!this._model) {
76
throw new Error('Git model not found');
77
}
78
79
if (version !== 1) {
80
throw new Error(`No API version ${version} found.`);
81
}
82
83
return new ApiImpl(this._model);
84
}
85
}
86
87