1
1
import * as vscode from 'vscode' ;
2
- import { Disposable , LanguageClient } from 'vscode-languageclient/node' ;
2
+ import { Disposable , ExecuteCommandRequest , LanguageClient } from 'vscode-languageclient/node' ;
3
3
import { AdaCodeLensProvider } from './AdaCodeLensProvider' ;
4
4
import { createClient } from './clients' ;
5
5
import { AdaInitialDebugConfigProvider , initializeDebugging } from './debugConfigProvider' ;
6
6
import { GnatTaskProvider } from './gnatTaskProvider' ;
7
+ import { initializeTesting } from './gnattest' ;
7
8
import { GprTaskProvider } from './gprTaskProvider' ;
8
9
import { TERMINAL_ENV_SETTING_NAME } from './helpers' ;
9
10
import { registerTaskProviders } from './taskProviders' ;
@@ -31,6 +32,23 @@ export class ExtensionState {
31
32
private registeredTaskProviders : Disposable [ ] ;
32
33
33
34
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
+ }
34
52
35
53
constructor ( context : vscode . ExtensionContext ) {
36
54
this . context = context ;
@@ -52,6 +70,7 @@ export class ExtensionState {
52
70
const result = initializeDebugging ( this . context ) ;
53
71
this . initialDebugConfigProvider = result . providerInitial ;
54
72
this . dynamicDebugConfigProvider = result . providerDynamic ;
73
+ this . testController = initializeTesting ( context ) ;
55
74
}
56
75
57
76
public start = async ( ) => {
@@ -110,6 +129,7 @@ export class ExtensionState {
110
129
e . affectsConfiguration ( 'ada.scenarioVariables' ) ||
111
130
e . affectsConfiguration ( 'ada.projectFile' )
112
131
) {
132
+ this . clearALSCache ( ) ;
113
133
this . unregisterTaskProviders ( ) ;
114
134
this . registerTaskProviders ( ) ;
115
135
}
@@ -121,4 +141,60 @@ export class ExtensionState {
121
141
void this . showReloadWindowPopup ( ) ;
122
142
}
123
143
} ;
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
+ }
124
200
}
0 commit comments