11'use strict' ;
2- import { ExtensionContext } from 'vscode' ;
2+ import { Disposable , ExtensionContext , languages , workspace } from 'vscode' ;
33import { AnnotationController } from './annotations/annotationController' ;
44import { CodeLensController } from './codeLensController' ;
55import { configuration , IConfig } from './configuration' ;
66import { CurrentLineController } from './currentLineController' ;
77import { DocumentTracker , GitDocumentState } from './trackers/documentTracker' ;
88import { ExplorerCommands } from './views/explorerCommands' ;
9+ import { GitContentProvider } from './gitContentProvider' ;
910import { GitExplorer } from './views/gitExplorer' ;
11+ import { GitRevisionCodeLensProvider } from './gitRevisionCodeLensProvider' ;
1012import { GitService } from './gitService' ;
1113import { Keyboard } from './keyboard' ;
1214import { ResultsExplorer } from './views/resultsExplorer' ;
1315
1416export class Container {
1517
1618 static initialize ( context : ExtensionContext , config : IConfig ) {
17- Container . _context = context ;
18- Container . _config = config ;
19+ this . _context = context ;
20+ this . _config = config ;
1921
20- context . subscriptions . push ( Container . _tracker = new DocumentTracker < GitDocumentState > ( ) ) ;
21- context . subscriptions . push ( Container . _git = new GitService ( ) ) ;
22+ context . subscriptions . push ( this . _tracker = new DocumentTracker < GitDocumentState > ( ) ) ;
23+ context . subscriptions . push ( this . _git = new GitService ( ) ) ;
2224
2325 // Since there is a chicken/egg problem with the DocumentTracker and the GitService, initialize the tracker once the GitService is loaded
24- Container . _tracker . initialize ( ) ;
26+ this . _tracker . initialize ( ) ;
2527
26- context . subscriptions . push ( Container . _annotationController = new AnnotationController ( ) ) ;
27- context . subscriptions . push ( Container . _currentLineController = new CurrentLineController ( ) ) ;
28- context . subscriptions . push ( Container . _codeLensController = new CodeLensController ( ) ) ;
29- context . subscriptions . push ( Container . _explorerCommands = new ExplorerCommands ( ) ) ;
30- context . subscriptions . push ( Container . _keyboard = new Keyboard ( ) ) ;
28+ context . subscriptions . push ( this . _annotationController = new AnnotationController ( ) ) ;
29+ context . subscriptions . push ( this . _currentLineController = new CurrentLineController ( ) ) ;
30+ context . subscriptions . push ( this . _codeLensController = new CodeLensController ( ) ) ;
31+ context . subscriptions . push ( this . _keyboard = new Keyboard ( ) ) ;
3132
32- Container . _gitExplorer = new GitExplorer ( ) ;
33- Container . _resultsExplorer = new ResultsExplorer ( ) ;
33+ if ( config . gitExplorer . enabled ) {
34+ context . subscriptions . push ( this . _gitExplorer = new GitExplorer ( ) ) ;
35+ }
36+ else {
37+ let disposable : Disposable ;
38+ disposable = configuration . onDidChange ( e => {
39+ if ( configuration . changed ( e , configuration . name ( 'gitExplorer' ) ( 'enabled' ) . value ) ) {
40+ disposable . dispose ( ) ;
41+ context . subscriptions . push ( this . _gitExplorer = new GitExplorer ( ) ) ;
42+ }
43+ } ) ;
44+ }
45+
46+ context . subscriptions . push ( workspace . registerTextDocumentContentProvider ( GitContentProvider . scheme , new GitContentProvider ( ) ) ) ;
47+ context . subscriptions . push ( languages . registerCodeLensProvider ( GitRevisionCodeLensProvider . selector , new GitRevisionCodeLensProvider ( ) ) ) ;
3448 }
3549
3650 private static _annotationController : AnnotationController ;
3751 static get annotations ( ) {
38- return Container . _annotationController ;
52+ return this . _annotationController ;
3953 }
4054
4155 private static _codeLensController : CodeLensController ;
4256 static get codeLens ( ) {
43- return Container . _codeLensController ;
57+ return this . _codeLensController ;
4458 }
4559
4660 private static _config : IConfig | undefined ;
@@ -53,42 +67,49 @@ export class Container {
5367
5468 private static _context : ExtensionContext ;
5569 static get context ( ) {
56- return Container . _context ;
70+ return this . _context ;
5771 }
5872
59- private static _explorerCommands : ExplorerCommands ;
73+ private static _explorerCommands : ExplorerCommands | undefined ;
6074 static get explorerCommands ( ) {
61- return Container . _explorerCommands ;
75+ if ( this . _explorerCommands === undefined ) {
76+ this . _context . subscriptions . push ( this . _explorerCommands = new ExplorerCommands ( ) ) ;
77+ }
78+ return this . _explorerCommands ;
6279 }
6380
6481 private static _git : GitService ;
6582 static get git ( ) {
66- return Container . _git ;
83+ return this . _git ;
6784 }
6885
69- private static _gitExplorer : GitExplorer ;
70- static get gitExplorer ( ) {
71- return Container . _gitExplorer ;
86+ private static _gitExplorer : GitExplorer | undefined ;
87+ static get gitExplorer ( ) : GitExplorer {
88+ return this . _gitExplorer ! ;
7289 }
7390
7491 private static _keyboard : Keyboard ;
7592 static get keyboard ( ) {
76- return Container . _keyboard ;
93+ return this . _keyboard ;
7794 }
7895
7996 private static _currentLineController : CurrentLineController ;
8097 static get lineAnnotations ( ) {
81- return Container . _currentLineController ;
98+ return this . _currentLineController ;
8299 }
83100
84- private static _resultsExplorer : ResultsExplorer ;
101+ private static _resultsExplorer : ResultsExplorer | undefined ;
85102 static get resultsExplorer ( ) {
86- return Container . _resultsExplorer ;
103+ if ( this . _resultsExplorer === undefined ) {
104+ this . _context . subscriptions . push ( this . _resultsExplorer = new ResultsExplorer ( ) ) ;
105+ }
106+
107+ return this . _resultsExplorer ;
87108 }
88109
89110 private static _tracker : DocumentTracker < GitDocumentState > ;
90111 static get tracker ( ) {
91- return Container . _tracker ;
112+ return this . _tracker ;
92113 }
93114
94115 static resetConfig ( ) {
0 commit comments