mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-30 21:41:46 +01:00
git api: deprecation
This commit is contained in:
@@ -40,4 +40,16 @@ export function Api(version: string): Function {
|
||||
versions.push(version);
|
||||
apis.set(version, ctor);
|
||||
};
|
||||
}
|
||||
|
||||
export function deprecated(target: any, key: string, descriptor: any): void {
|
||||
if (typeof descriptor.value !== 'function') {
|
||||
throw new Error('not supported');
|
||||
}
|
||||
|
||||
const fn = descriptor.value;
|
||||
descriptor.value = function () {
|
||||
console.warn(`Git extension API method '${key}' is deprecated.`);
|
||||
return fn.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import { Model } from '../model';
|
||||
import { Repository as ModelRepository } from '../repository';
|
||||
import { Uri, SourceControlInputBox } from 'vscode';
|
||||
import { GitExtension } from './git';
|
||||
import { getAPI } from './api';
|
||||
import { getAPI, deprecated } from './api';
|
||||
|
||||
class InputBoxImpl implements GitExtension.InputBox {
|
||||
set value(value: string) { this.inputBox.value = value; }
|
||||
@@ -28,18 +28,46 @@ class RepositoryImpl implements GitExtension.Repository {
|
||||
}
|
||||
}
|
||||
|
||||
export function createGitExtension(model?: Model): GitExtension {
|
||||
if (!model) {
|
||||
return {
|
||||
getGitPath() { throw new Error('Git model not found'); },
|
||||
getRepositories() { throw new Error('Git model not found'); },
|
||||
getAPI() { throw new Error('Git model not found'); }
|
||||
};
|
||||
class NoModelGitExtension implements GitExtension {
|
||||
|
||||
@deprecated
|
||||
async getGitPath(): Promise<string> {
|
||||
throw new Error('Git model not found');
|
||||
}
|
||||
|
||||
return {
|
||||
async getGitPath() { return model.git.path; },
|
||||
async getRepositories() { return model.repositories.map(repository => new RepositoryImpl(repository)); },
|
||||
getAPI(range: string) { return getAPI(model, range); }
|
||||
};
|
||||
@deprecated
|
||||
async getRepositories(): Promise<GitExtension.Repository[]> {
|
||||
throw new Error('Git model not found');
|
||||
}
|
||||
|
||||
getAPI(): GitExtension.API {
|
||||
throw new Error('Git model not found');
|
||||
}
|
||||
}
|
||||
|
||||
class GitExtensionImpl implements GitExtension {
|
||||
|
||||
constructor(private _model: Model) { }
|
||||
|
||||
@deprecated
|
||||
async getGitPath(): Promise<string> {
|
||||
return this._model.git.path;
|
||||
}
|
||||
|
||||
@deprecated
|
||||
async getRepositories(): Promise<GitExtension.Repository[]> {
|
||||
return this._model.repositories.map(repository => new RepositoryImpl(repository));
|
||||
}
|
||||
|
||||
getAPI(range: string): GitExtension.API {
|
||||
return getAPI(this._model, range);
|
||||
}
|
||||
}
|
||||
|
||||
export function createGitExtension(model?: Model): GitExtension {
|
||||
if (!model) {
|
||||
return new NoModelGitExtension();
|
||||
}
|
||||
|
||||
return new GitExtensionImpl(model);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user