mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-29 13:03:42 +01:00
git: cleaner exports
This commit is contained in:
@@ -6,17 +6,17 @@
|
||||
'use strict';
|
||||
|
||||
import { Model } from '../model';
|
||||
import { GitExtension } from './git';
|
||||
import { API } from './git';
|
||||
import * as semver from 'semver';
|
||||
|
||||
interface ApiCtor {
|
||||
new(model: Model): GitExtension.API;
|
||||
new(model: Model): API;
|
||||
}
|
||||
|
||||
const versions: string[] = [];
|
||||
const apis = new Map<string, ApiCtor>();
|
||||
|
||||
export function getAPI(model: Model, range: string): GitExtension.API {
|
||||
export function getAPI(model: Model, range: string): API {
|
||||
if (!range) {
|
||||
throw new Error(`Please provide a Git extension API version range. Available versions: [${versions.join(', ')}]`);
|
||||
}
|
||||
|
||||
@@ -6,57 +6,62 @@
|
||||
'use strict';
|
||||
|
||||
import { Model } from '../model';
|
||||
import { GitExtension } from './git';
|
||||
import { Repository as BaseRepository } from '../repository';
|
||||
import { InputBox, ExecResult, SpawnOptions, Git, API, Repository } from './git';
|
||||
import { Api } from './api';
|
||||
import { Event, SourceControlInputBox, Uri } from 'vscode';
|
||||
import { mapEvent } from '../util';
|
||||
import { Repository } from '../repository';
|
||||
import * as cp from 'child_process';
|
||||
|
||||
class ApiInputBox implements GitExtension.InputBox {
|
||||
class ApiInputBox implements InputBox {
|
||||
set value(value: string) { this._inputBox.value = value; }
|
||||
get value(): string { return this._inputBox.value; }
|
||||
constructor(private _inputBox: SourceControlInputBox) { }
|
||||
}
|
||||
|
||||
export class ApiRepository implements GitExtension.Repository {
|
||||
export class ApiRepository implements Repository {
|
||||
|
||||
readonly rootUri: Uri;
|
||||
readonly inputBox: GitExtension.InputBox;
|
||||
readonly inputBox: InputBox;
|
||||
|
||||
constructor(_repository: Repository) {
|
||||
constructor(_repository: BaseRepository) {
|
||||
this.rootUri = Uri.file(_repository.root);
|
||||
this.inputBox = new ApiInputBox(_repository.inputBox);
|
||||
}
|
||||
}
|
||||
|
||||
@Api('1.0.0')
|
||||
export class ApiImpl implements GitExtension.API {
|
||||
export class ApiGit implements Git {
|
||||
|
||||
get gitPath(): string {
|
||||
return this._model.git.path;
|
||||
}
|
||||
|
||||
get onDidOpenRepository(): Event<GitExtension.Repository> {
|
||||
return mapEvent(this._model.onDidOpenRepository, r => new ApiRepository(r));
|
||||
}
|
||||
|
||||
get onDidCloseRepository(): Event<GitExtension.Repository> {
|
||||
return mapEvent(this._model.onDidCloseRepository, r => new ApiRepository(r));
|
||||
}
|
||||
|
||||
get repositories(): GitExtension.Repository[] {
|
||||
return this._model.repositories.map(r => new ApiRepository(r));
|
||||
}
|
||||
get path(): string { return this._model.git.path; }
|
||||
|
||||
constructor(private _model: Model) { }
|
||||
|
||||
exec(cwd: string, args: string[], options: GitExtension.SpawnOptions = {}): Promise<GitExtension.IExecResult<string>> {
|
||||
exec(cwd: string, args: string[], options: SpawnOptions = {}): Promise<ExecResult<string>> {
|
||||
return this._model.git.exec(cwd, args, options);
|
||||
}
|
||||
|
||||
spawn(cwd: string, args: string[], options: GitExtension.SpawnOptions = {}): cp.ChildProcess {
|
||||
spawn(cwd: string, args: string[], options: SpawnOptions = {}): cp.ChildProcess {
|
||||
options = { cwd, ...options };
|
||||
return this._model.git.spawn(args, options);
|
||||
}
|
||||
}
|
||||
|
||||
@Api('1.0.0')
|
||||
export class ApiImpl implements API {
|
||||
|
||||
readonly git = new ApiGit(this._model);
|
||||
|
||||
get onDidOpenRepository(): Event<Repository> {
|
||||
return mapEvent(this._model.onDidOpenRepository, r => new ApiRepository(r));
|
||||
}
|
||||
|
||||
get onDidCloseRepository(): Event<Repository> {
|
||||
return mapEvent(this._model.onDidCloseRepository, r => new ApiRepository(r));
|
||||
}
|
||||
|
||||
get repositories(): Repository[] {
|
||||
return this._model.repositories.map(r => new ApiRepository(r));
|
||||
}
|
||||
|
||||
constructor(private _model: Model) { }
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
'use strict';
|
||||
|
||||
import { Model } from '../model';
|
||||
import { GitExtension } from './git';
|
||||
import { GitExtension, Repository, API } from './git';
|
||||
import { getAPI, deprecated } from './api';
|
||||
import { ApiRepository } from './api1';
|
||||
|
||||
@@ -18,11 +18,11 @@ class NoModelGitExtension implements GitExtension {
|
||||
}
|
||||
|
||||
@deprecated
|
||||
async getRepositories(): Promise<GitExtension.Repository[]> {
|
||||
async getRepositories(): Promise<Repository[]> {
|
||||
throw new Error('Git model not found');
|
||||
}
|
||||
|
||||
getAPI(): GitExtension.API {
|
||||
getAPI(): API {
|
||||
throw new Error('Git model not found');
|
||||
}
|
||||
}
|
||||
@@ -37,11 +37,11 @@ class GitExtensionImpl implements GitExtension {
|
||||
}
|
||||
|
||||
@deprecated
|
||||
async getRepositories(): Promise<GitExtension.Repository[]> {
|
||||
async getRepositories(): Promise<Repository[]> {
|
||||
return this._model.repositories.map(repository => new ApiRepository(repository));
|
||||
}
|
||||
|
||||
getAPI(range: string): GitExtension.API {
|
||||
getAPI(range: string): API {
|
||||
return getAPI(this._model, range);
|
||||
}
|
||||
}
|
||||
|
||||
72
extensions/git/src/api/git.d.ts
vendored
72
extensions/git/src/api/git.d.ts
vendored
@@ -6,41 +6,43 @@
|
||||
import { Uri, SourceControlInputBox, Event, CancellationToken } from 'vscode';
|
||||
import * as cp from 'child_process';
|
||||
|
||||
declare module GitExtension {
|
||||
|
||||
export interface IExecResult<T extends string | Buffer> {
|
||||
readonly exitCode: number;
|
||||
readonly stdout: T;
|
||||
readonly stderr: string;
|
||||
}
|
||||
|
||||
export interface SpawnOptions extends cp.SpawnOptions {
|
||||
readonly input?: string;
|
||||
readonly encoding?: string;
|
||||
readonly log?: boolean;
|
||||
readonly cancellationToken?: CancellationToken;
|
||||
}
|
||||
|
||||
export interface API {
|
||||
readonly gitPath: string;
|
||||
readonly repositories: Repository[];
|
||||
readonly onDidOpenRepository: Event<Repository>;
|
||||
readonly onDidCloseRepository: Event<Repository>;
|
||||
|
||||
exec(cwd: string, args: string[], options?: SpawnOptions): Promise<IExecResult<string>>;
|
||||
spawn(cwd: string, args: string[], options?: SpawnOptions): cp.ChildProcess;
|
||||
}
|
||||
|
||||
export interface InputBox {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface Repository {
|
||||
readonly rootUri: Uri;
|
||||
readonly inputBox: InputBox;
|
||||
}
|
||||
export interface ExecResult<T extends string | Buffer> {
|
||||
readonly exitCode: number;
|
||||
readonly stdout: T;
|
||||
readonly stderr: string;
|
||||
}
|
||||
|
||||
export interface SpawnOptions extends cp.SpawnOptions {
|
||||
readonly input?: string;
|
||||
readonly encoding?: string;
|
||||
readonly log?: boolean;
|
||||
readonly cancellationToken?: CancellationToken;
|
||||
}
|
||||
|
||||
export interface Git {
|
||||
readonly path: string;
|
||||
exec(cwd: string, args: string[], options?: SpawnOptions): Promise<ExecResult<string>>;
|
||||
spawn(cwd: string, args: string[], options?: SpawnOptions): cp.ChildProcess;
|
||||
}
|
||||
|
||||
export interface API {
|
||||
readonly git: Git;
|
||||
readonly repositories: Repository[];
|
||||
readonly onDidOpenRepository: Event<Repository>;
|
||||
readonly onDidCloseRepository: Event<Repository>;
|
||||
}
|
||||
|
||||
export interface InputBox {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface Repository {
|
||||
readonly rootUri: Uri;
|
||||
readonly inputBox: InputBox;
|
||||
}
|
||||
|
||||
declare module GitExtension { }
|
||||
|
||||
export interface GitExtension {
|
||||
|
||||
/**
|
||||
@@ -50,14 +52,14 @@ export interface GitExtension {
|
||||
* @param range Semver version range for API compatibility.
|
||||
* @returns API instance
|
||||
*/
|
||||
getAPI(range: string): GitExtension.API;
|
||||
getAPI(range: string): API;
|
||||
|
||||
/**
|
||||
* Returns the collection of active repositories.
|
||||
*
|
||||
* @deprecated Use `API.repositories` instead.
|
||||
*/
|
||||
getRepositories(): Promise<GitExtension.Repository[]>;
|
||||
getRepositories(): Promise<Repository[]>;
|
||||
|
||||
/**
|
||||
* Returns the path to the current git executable.
|
||||
|
||||
Reference in New Issue
Block a user