File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11971197 "file-type" : " ^7.2.0" ,
11981198 "iconv-lite" : " 0.4.19" ,
11991199 "jschardet" : " ^1.6.0" ,
1200+ "semver" : " ^5.5.1" ,
12001201 "vscode-extension-telemetry" : " 0.0.18" ,
12011202 "vscode-nls" : " ^3.2.4" ,
12021203 "which" : " ^1.3.0"
Original file line number Diff line number Diff line change 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 { GitExtension } from './git' ;
10+ import * as semver from 'semver' ;
11+
12+ interface ApiCtor {
13+ new ( model : Model ) : GitExtension . API ;
14+ }
15+
16+ const versions : string [ ] = [ ] ;
17+ const apis = new Map < string , ApiCtor > ( ) ;
18+
19+ export function getAPI ( model : Model , range : string ) : GitExtension . API {
20+ if ( ! range ) {
21+ throw new Error ( `Please provide a Git extension API version range. Available versions: [${ versions . join ( ', ' ) } ]` ) ;
22+ }
23+
24+ const version = semver . maxSatisfying ( versions , range ) ;
25+
26+ if ( ! version ) {
27+ throw new Error ( `There's no available Git extension API for the given range: '${ range } '. Available versions: [${ versions . join ( ', ' ) } ]` ) ;
28+ }
29+
30+ const api = apis . get ( version ) ! ;
31+ return new api ( model ) ;
32+ }
33+
34+ export function Api ( version : string ) : Function {
35+ return function ( ctor : ApiCtor ) {
36+ if ( apis . has ( version ) ) {
37+ throw new Error ( `Git extension API version ${ version } already registered.` ) ;
38+ }
39+
40+ versions . push ( version ) ;
41+ apis . set ( version , ctor ) ;
42+ } ;
43+ }
Original file line number Diff line number Diff line change 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 { GitExtension } from './git' ;
10+ import { Api } from './api' ;
11+
12+ @Api ( '0.1.0' )
13+ export class ApiImpl implements GitExtension . API {
14+
15+ constructor ( model : Model ) {
16+ // console.log(model);
17+ }
18+ }
Original file line number Diff line number Diff line change 55
66'use strict' ;
77
8- import { Model } from './model' ;
9- import { Repository as ModelRepository } from './repository' ;
8+ import { Model } from '.. /model' ;
9+ import { Repository as ModelRepository } from '.. /repository' ;
1010import { Uri , SourceControlInputBox } from 'vscode' ;
11- import { GitExtension } from './api' ;
11+ import { GitExtension } from './git' ;
12+ import { getAPI } from './api' ;
1213
1314class InputBoxImpl implements GitExtension . InputBox {
1415 set value ( value : string ) { this . inputBox . value = value ; }
@@ -31,12 +32,14 @@ export function createGitExtension(model?: Model): GitExtension {
3132 if ( ! model ) {
3233 return {
3334 getGitPath ( ) { throw new Error ( 'Git model not found' ) ; } ,
34- getRepositories ( ) { throw new Error ( 'Git model not found' ) ; }
35+ getRepositories ( ) { throw new Error ( 'Git model not found' ) ; } ,
36+ getAPI ( ) { throw new Error ( 'Git model not found' ) ; }
3537 } ;
3638 }
3739
3840 return {
3941 async getGitPath ( ) { return model . git . path ; } ,
40- async getRepositories ( ) { return model . repositories . map ( repository => new RepositoryImpl ( repository ) ) ; }
42+ async getRepositories ( ) { return model . repositories . map ( repository => new RepositoryImpl ( repository ) ) ; } ,
43+ getAPI ( range : string ) { return getAPI ( model , range ) ; }
4144 } ;
4245}
Original file line number Diff line number Diff line change @@ -10,9 +10,6 @@ declare module GitExtension {
1010
1111 }
1212
13- // export const availableVersions: string[];
14- // export function getAPI(version: string): API;
15-
1613 //#region Deprecated API
1714 export interface InputBox {
1815 value : string ;
@@ -28,4 +25,6 @@ declare module GitExtension {
2825export interface GitExtension {
2926 getRepositories ( ) : Promise < GitExtension . Repository [ ] > ;
3027 getGitPath ( ) : Promise < string > ;
28+ // export const availableVersions: string[];
29+ getAPI ( range : string ) : GitExtension . API ;
3130}
Original file line number Diff line number Diff line change @@ -17,9 +17,11 @@ import { GitDecorations } from './decorationProvider';
1717import { Askpass } from './askpass' ;
1818import { toDisposable , filterEvent , eventToPromise } from './util' ;
1919import TelemetryReporter from 'vscode-extension-telemetry' ;
20- import { GitExtension } from './api' ;
20+ import { GitExtension } from './api/git ' ;
2121import { GitProtocolHandler } from './protocolHandler' ;
22- import { createGitExtension } from './api.impl' ;
22+ import { createGitExtension } from './api/extension' ;
23+
24+ import './api/api0' ;
2325
2426const deactivateTasks : { ( ) : Promise < any > ; } [ ] = [ ] ;
2527
Original file line number Diff line number Diff line change @@ -251,6 +251,10 @@ semver@^5.3.0:
251251 version "5.5.0"
252252 resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"
253253
254+ semver@^5.5.1 :
255+ version "5.5.1"
256+ resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.1.tgz#7dfdd8814bdb7cabc7be0fb1d734cfb66c940477"
257+
254258supports-color@3.1.2 :
255259 version "3.1.2"
256260 resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.1.2.tgz#72a262894d9d408b956ca05ff37b2ed8a6e2a2d5"
You can’t perform that action at this time.
0 commit comments