mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-30 05:21:08 +01:00
git: getAPI
This commit is contained in:
45
extensions/git/src/api/extension.ts
Normal file
45
extensions/git/src/api/extension.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 './git';
|
||||
import { getAPI } 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'); },
|
||||
getAPI() { throw new Error('Git model not found'); }
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
async getGitPath() { return model.git.path; },
|
||||
async getRepositories() { return model.repositories.map(repository => new RepositoryImpl(repository)); },
|
||||
getAPI(range: string) { return getAPI(model, range); }
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user