diff --git a/extensions/git/src/api.d.ts b/extensions/git/src/api.d.ts new file mode 100644 index 00000000000..3273c7e4c00 --- /dev/null +++ b/extensions/git/src/api.d.ts @@ -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; + getGitPath(): Promise; +} \ No newline at end of file diff --git a/extensions/git/src/api.impl.ts b/extensions/git/src/api.impl.ts new file mode 100644 index 00000000000..ff702cf52e8 --- /dev/null +++ b/extensions/git/src/api.impl.ts @@ -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)); } + }; +} diff --git a/extensions/git/src/api.ts b/extensions/git/src/api.ts deleted file mode 100644 index cfce4c9ed8b..00000000000 --- a/extensions/git/src/api.ts +++ /dev/null @@ -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; - getGitPath(): Promise; -} - -export class APIImpl implements API { - - constructor(private model: Model) { } - - async getGitPath(): Promise { - return this.model.git.path; - } - - async getRepositories(): Promise { - return this.model.repositories.map(repository => new RepositoryImpl(repository)); - } -} - -export class NoopAPIImpl implements API { - - async getGitPath(): Promise { - throw new Error('Git model not found'); - } - - async getRepositories(): Promise { - throw new Error('Git model not found'); - } -} diff --git a/extensions/git/src/main.ts b/extensions/git/src/main.ts index 186dd806118..f4833c8985f 100644 --- a/extensions/git/src/main.ts +++ b/extensions/git/src/main.ts @@ -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; }[] = []; @@ -69,7 +71,7 @@ async function createModel(context: ExtensionContext, outputChannel: OutputChann return model; } -export async function activate(context: ExtensionContext): Promise { +export async function activate(context: ExtensionContext): Promise { const disposables: Disposable[] = []; context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose())); @@ -92,7 +94,7 @@ export async function activate(context: ExtensionContext): Promise { 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 { } } - return new NoopAPIImpl(); + return createGitExtension(); } }