Skip to content

Commit 0633c77

Browse files
committed
api.d.ts
1 parent a8deffb commit 0633c77

4 files changed

Lines changed: 79 additions & 69 deletions

File tree

extensions/git/src/api.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { Uri, SourceControlInputBox } from 'vscode';
7+
8+
declare module GitExtension {
9+
export interface API {
10+
11+
}
12+
13+
// export const availableVersions: string[];
14+
// export function getAPI(version: string): API;
15+
16+
//#region Deprecated API
17+
export interface InputBox {
18+
value: string;
19+
}
20+
21+
export interface Repository {
22+
readonly rootUri: Uri;
23+
readonly inputBox: InputBox;
24+
}
25+
//#endregion
26+
}
27+
28+
export interface GitExtension {
29+
getRepositories(): Promise<GitExtension.Repository[]>;
30+
getGitPath(): Promise<string>;
31+
}

extensions/git/src/api.impl.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import { Model } from './model';
9+
import { Repository as ModelRepository } from './repository';
10+
import { Uri, SourceControlInputBox } from 'vscode';
11+
import { GitExtension } from './api';
12+
13+
class InputBoxImpl implements GitExtension.InputBox {
14+
set value(value: string) { this.inputBox.value = value; }
15+
get value(): string { return this.inputBox.value; }
16+
constructor(private inputBox: SourceControlInputBox) { }
17+
}
18+
19+
class RepositoryImpl implements GitExtension.Repository {
20+
21+
readonly rootUri: Uri;
22+
readonly inputBox: GitExtension.InputBox;
23+
24+
constructor(repository: ModelRepository) {
25+
this.rootUri = Uri.file(repository.root);
26+
this.inputBox = new InputBoxImpl(repository.inputBox);
27+
}
28+
}
29+
30+
export function createGitExtension(model?: Model): GitExtension {
31+
if (!model) {
32+
return {
33+
getGitPath() { throw new Error('Git model not found'); },
34+
getRepositories() { throw new Error('Git model not found'); }
35+
};
36+
}
37+
38+
return {
39+
async getGitPath() { return model.git.path; },
40+
async getRepositories() { return model.repositories.map(repository => new RepositoryImpl(repository)); }
41+
};
42+
}

extensions/git/src/api.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

extensions/git/src/main.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import * as nls from 'vscode-nls';
99
const localize = nls.loadMessageBundle();
10+
1011
import { ExtensionContext, workspace, window, Disposable, commands, Uri, OutputChannel } from 'vscode';
1112
import { findGit, Git, IGit } from './git';
1213
import { Model } from './model';
@@ -16,8 +17,9 @@ import { GitDecorations } from './decorationProvider';
1617
import { Askpass } from './askpass';
1718
import { toDisposable, filterEvent, eventToPromise } from './util';
1819
import TelemetryReporter from 'vscode-extension-telemetry';
19-
import { API, NoopAPIImpl, APIImpl } from './api';
20+
import { GitExtension } from './api';
2021
import { GitProtocolHandler } from './protocolHandler';
22+
import { createGitExtension } from './api.impl';
2123

2224
const deactivateTasks: { (): Promise<any>; }[] = [];
2325

@@ -69,7 +71,7 @@ async function createModel(context: ExtensionContext, outputChannel: OutputChann
6971
return model;
7072
}
7173

72-
export async function activate(context: ExtensionContext): Promise<API> {
74+
export async function activate(context: ExtensionContext): Promise<GitExtension> {
7375
const disposables: Disposable[] = [];
7476
context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose()));
7577

@@ -92,7 +94,7 @@ export async function activate(context: ExtensionContext): Promise<API> {
9294

9395
try {
9496
const model = await createModel(context, outputChannel, telemetryReporter, disposables);
95-
return new APIImpl(model);
97+
return createGitExtension(model);
9698
} catch (err) {
9799
if (!/Git installation not found/.test(err.message || '')) {
98100
throw err;
@@ -121,7 +123,7 @@ export async function activate(context: ExtensionContext): Promise<API> {
121123
}
122124
}
123125

124-
return new NoopAPIImpl();
126+
return createGitExtension();
125127
}
126128
}
127129

0 commit comments

Comments
 (0)