11import * as vscode from 'vscode' ;
2- import { Disposable , LanguageClient } from 'vscode-languageclient/node' ;
2+ import { Disposable , ExecuteCommandRequest , LanguageClient } from 'vscode-languageclient/node' ;
33import { AdaCodeLensProvider } from './AdaCodeLensProvider' ;
44import { createClient } from './clients' ;
55import { AdaInitialDebugConfigProvider , initializeDebugging } from './debugConfigProvider' ;
66import { GnatTaskProvider } from './gnatTaskProvider' ;
7+ import { initializeTesting } from './gnattest' ;
78import { GprTaskProvider } from './gprTaskProvider' ;
89import { TERMINAL_ENV_SETTING_NAME } from './helpers' ;
910import { registerTaskProviders } from './taskProviders' ;
@@ -31,6 +32,23 @@ export class ExtensionState {
3132 private registeredTaskProviders : Disposable [ ] ;
3233
3334 public readonly codelensProvider = new AdaCodeLensProvider ( ) ;
35+ public readonly testController : vscode . TestController ;
36+ public readonly testData : Map < vscode . TestItem , object > = new Map ( ) ;
37+
38+ /**
39+ * The following fields are caches for ALS requests
40+ */
41+ cachedProjectFile : string | undefined ;
42+ cachedObjectDir : string | undefined ;
43+ cachedMains : string [ ] | undefined ;
44+ cachedExecutables : string [ ] | undefined ;
45+
46+ public clearALSCache ( ) {
47+ this . cachedProjectFile = undefined ;
48+ this . cachedObjectDir = undefined ;
49+ this . cachedMains = undefined ;
50+ this . cachedExecutables = undefined ;
51+ }
3452
3553 constructor ( context : vscode . ExtensionContext ) {
3654 this . context = context ;
@@ -52,6 +70,7 @@ export class ExtensionState {
5270 const result = initializeDebugging ( this . context ) ;
5371 this . initialDebugConfigProvider = result . providerInitial ;
5472 this . dynamicDebugConfigProvider = result . providerDynamic ;
73+ this . testController = initializeTesting ( context ) ;
5574 }
5675
5776 public start = async ( ) => {
@@ -110,6 +129,7 @@ export class ExtensionState {
110129 e . affectsConfiguration ( 'ada.scenarioVariables' ) ||
111130 e . affectsConfiguration ( 'ada.projectFile' )
112131 ) {
132+ this . clearALSCache ( ) ;
113133 this . unregisterTaskProviders ( ) ;
114134 this . registerTaskProviders ( ) ;
115135 }
@@ -121,4 +141,60 @@ export class ExtensionState {
121141 void this . showReloadWindowPopup ( ) ;
122142 }
123143 } ;
144+
145+ /**
146+ * @returns the full path of the main project file from the ALS
147+ */
148+ public async getProjectFile ( ) : Promise < string > {
149+ if ( ! this . cachedProjectFile ) {
150+ this . cachedProjectFile = ( await this . adaClient . sendRequest ( ExecuteCommandRequest . type , {
151+ command : 'als-project-file' ,
152+ } ) ) as string ;
153+ }
154+
155+ return this . cachedProjectFile ;
156+ }
157+
158+ /**
159+ *
160+ * @returns the full path of the project object directory obtained from the ALS
161+ */
162+ public async getObjectDir ( ) : Promise < string > {
163+ if ( ! this . cachedObjectDir ) {
164+ this . cachedObjectDir = ( await this . adaClient . sendRequest ( ExecuteCommandRequest . type , {
165+ command : 'als-object-dir' ,
166+ } ) ) as string ;
167+ }
168+
169+ return this . cachedObjectDir ;
170+ }
171+
172+ /**
173+ *
174+ * @returns the list of full paths of main sources defined in the project from the ALS
175+ */
176+ public async getMains ( ) : Promise < string [ ] > {
177+ if ( ! this . cachedMains ) {
178+ this . cachedMains = ( await this . adaClient . sendRequest ( ExecuteCommandRequest . type , {
179+ command : 'als-mains' ,
180+ } ) ) as string [ ] ;
181+ }
182+
183+ return this . cachedMains ;
184+ }
185+
186+ /**
187+ *
188+ * @returns the list of full paths of executables corresponding to main
189+ * sources defined in the project from the ALS
190+ */
191+ public async getExecutables ( ) : Promise < string [ ] > {
192+ if ( ! this . cachedExecutables ) {
193+ this . cachedExecutables = ( await this . adaClient . sendRequest ( ExecuteCommandRequest . type , {
194+ command : 'als-executables' ,
195+ } ) ) as string [ ] ;
196+ }
197+
198+ return this . cachedExecutables ;
199+ }
124200}
0 commit comments