Skip to content

Commit

Permalink
fixes #38389
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Dec 4, 2017
1 parent c243d0b commit 6d51126
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
42 changes: 42 additions & 0 deletions extensions/git/src/api.ts
Original file line number Diff line number Diff line change
@@ -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 { SourceControlInputBox, Uri } from 'vscode';

export interface InputBox {
value: string;
}

export interface Repository {
readonly rootUri: Uri;
readonly inputBox: InputBox;
}

export interface API {
getRepositories(): Promise<Repository[]>;
}

export function createApi(modelPromise: Promise<Model>) {
return {
async getRepositories(): Promise<Repository[]> {
const model = await modelPromise;

return model.repositories.map(repository => ({
rootUri: Uri.file(repository.root),
inputBox: {
set value(value: string) {
repository.inputBox.value = value;
},
get value(): string {
return repository.inputBox.value;
}
}
}));
}
};
}
18 changes: 12 additions & 6 deletions extensions/git/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import { GitDecorations } from './decorationProvider';
import { Askpass } from './askpass';
import { toDisposable } from './util';
import TelemetryReporter from 'vscode-extension-telemetry';
import { API, createApi } from './api';

async function init(context: ExtensionContext, outputChannel: OutputChannel, disposables: Disposable[]): Promise<void> {
async function init(context: ExtensionContext, outputChannel: OutputChannel, disposables: Disposable[]): Promise<Model> {
const { name, version, aiKey } = require(context.asAbsolutePath('./package.json')) as { name: string, version: string, aiKey: string };
const telemetryReporter: TelemetryReporter = new TelemetryReporter(name, version, aiKey);
disposables.push(telemetryReporter);
Expand Down Expand Up @@ -48,15 +49,17 @@ async function init(context: ExtensionContext, outputChannel: OutputChannel, dis
);

await checkGitVersion(info);

return model;
}

async function _activate(context: ExtensionContext, disposables: Disposable[]): Promise<any> {
async function _activate(context: ExtensionContext, disposables: Disposable[]): Promise<Model | undefined> {
const outputChannel = window.createOutputChannel('Git');
commands.registerCommand('git.showOutput', () => outputChannel.show());
disposables.push(outputChannel);

try {
await init(context, outputChannel, disposables);
return await init(context, outputChannel, disposables);
} catch (err) {
if (!/Git installation not found/.test(err.message || '')) {
throw err;
Expand Down Expand Up @@ -89,12 +92,15 @@ async function _activate(context: ExtensionContext, disposables: Disposable[]):
}
}

export function activate(context: ExtensionContext): any {
export function activate(context: ExtensionContext): API {
const disposables: Disposable[] = [];
context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose()));

_activate(context, disposables)
.catch(err => console.error(err));
const activatePromise = _activate(context, disposables);
const modelPromise = activatePromise.then(model => model || Promise.reject<Model>('Git model not found'));
activatePromise.catch(err => console.error(err));

return createApi(modelPromise);
}

async function checkGitVersion(info: IGit): Promise<void> {
Expand Down

0 comments on commit 6d51126

Please sign in to comment.