mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-13 15:35:20 +01:00
api.d.ts
This commit is contained in:
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Uri, SourceControlInputBox } from 'vscode';
|
||||
|
||||
declare module GitExtension {
|
||||
export interface API {
|
||||
|
||||
}
|
||||
|
||||
// export const availableVersions: string[];
|
||||
// export function getAPI(version: string): API;
|
||||
|
||||
//#region Deprecated API
|
||||
export interface InputBox {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface Repository {
|
||||
readonly rootUri: Uri;
|
||||
readonly inputBox: InputBox;
|
||||
}
|
||||
//#endregion
|
||||
}
|
||||
|
||||
export interface GitExtension {
|
||||
getRepositories(): Promise<GitExtension.Repository[]>;
|
||||
getGitPath(): Promise<string>;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { Model } from './model';
|
||||
import { Repository as ModelRepository } from './repository';
|
||||
import { Uri, SourceControlInputBox } from 'vscode';
|
||||
import { GitExtension } from './api';
|
||||
|
||||
class InputBoxImpl implements GitExtension.InputBox {
|
||||
set value(value: string) { this.inputBox.value = value; }
|
||||
get value(): string { return this.inputBox.value; }
|
||||
constructor(private inputBox: SourceControlInputBox) { }
|
||||
}
|
||||
|
||||
class RepositoryImpl implements GitExtension.Repository {
|
||||
|
||||
readonly rootUri: Uri;
|
||||
readonly inputBox: GitExtension.InputBox;
|
||||
|
||||
constructor(repository: ModelRepository) {
|
||||
this.rootUri = Uri.file(repository.root);
|
||||
this.inputBox = new InputBoxImpl(repository.inputBox);
|
||||
}
|
||||
}
|
||||
|
||||
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'); }
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
async getGitPath() { return model.git.path; },
|
||||
async getRepositories() { return model.repositories.map(repository => new RepositoryImpl(repository)); }
|
||||
};
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { Model } from './model';
|
||||
import { Repository as ModelRepository } from './repository';
|
||||
import { Uri, SourceControlInputBox } from 'vscode';
|
||||
|
||||
export interface InputBox {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export class InputBoxImpl implements InputBox {
|
||||
set value(value: string) { this.inputBox.value = value; }
|
||||
get value(): string { return this.inputBox.value; }
|
||||
constructor(private inputBox: SourceControlInputBox) { }
|
||||
}
|
||||
|
||||
export interface Repository {
|
||||
readonly rootUri: Uri;
|
||||
readonly inputBox: InputBox;
|
||||
}
|
||||
|
||||
export class RepositoryImpl implements Repository {
|
||||
|
||||
readonly rootUri: Uri;
|
||||
readonly inputBox: InputBox;
|
||||
|
||||
constructor(repository: ModelRepository) {
|
||||
this.rootUri = Uri.file(repository.root);
|
||||
this.inputBox = new InputBoxImpl(repository.inputBox);
|
||||
}
|
||||
}
|
||||
|
||||
export interface API {
|
||||
getRepositories(): Promise<Repository[]>;
|
||||
getGitPath(): Promise<string>;
|
||||
}
|
||||
|
||||
export class APIImpl implements API {
|
||||
|
||||
constructor(private model: Model) { }
|
||||
|
||||
async getGitPath(): Promise<string> {
|
||||
return this.model.git.path;
|
||||
}
|
||||
|
||||
async getRepositories(): Promise<Repository[]> {
|
||||
return this.model.repositories.map(repository => new RepositoryImpl(repository));
|
||||
}
|
||||
}
|
||||
|
||||
export class NoopAPIImpl implements API {
|
||||
|
||||
async getGitPath(): Promise<string> {
|
||||
throw new Error('Git model not found');
|
||||
}
|
||||
|
||||
async getRepositories(): Promise<Repository[]> {
|
||||
throw new Error('Git model not found');
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { ExtensionContext, workspace, window, Disposable, commands, Uri, OutputChannel } from 'vscode';
|
||||
import { findGit, Git, IGit } from './git';
|
||||
import { Model } from './model';
|
||||
@@ -16,8 +17,9 @@ import { GitDecorations } from './decorationProvider';
|
||||
import { Askpass } from './askpass';
|
||||
import { toDisposable, filterEvent, eventToPromise } from './util';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
import { API, NoopAPIImpl, APIImpl } from './api';
|
||||
import { GitExtension } from './api';
|
||||
import { GitProtocolHandler } from './protocolHandler';
|
||||
import { createGitExtension } from './api.impl';
|
||||
|
||||
const deactivateTasks: { (): Promise<any>; }[] = [];
|
||||
|
||||
@@ -69,7 +71,7 @@ async function createModel(context: ExtensionContext, outputChannel: OutputChann
|
||||
return model;
|
||||
}
|
||||
|
||||
export async function activate(context: ExtensionContext): Promise<API> {
|
||||
export async function activate(context: ExtensionContext): Promise<GitExtension> {
|
||||
const disposables: Disposable[] = [];
|
||||
context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose()));
|
||||
|
||||
@@ -92,7 +94,7 @@ export async function activate(context: ExtensionContext): Promise<API> {
|
||||
|
||||
try {
|
||||
const model = await createModel(context, outputChannel, telemetryReporter, disposables);
|
||||
return new APIImpl(model);
|
||||
return createGitExtension(model);
|
||||
} catch (err) {
|
||||
if (!/Git installation not found/.test(err.message || '')) {
|
||||
throw err;
|
||||
@@ -121,7 +123,7 @@ export async function activate(context: ExtensionContext): Promise<API> {
|
||||
}
|
||||
}
|
||||
|
||||
return new NoopAPIImpl();
|
||||
return createGitExtension();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user