@@ -18,10 +18,11 @@ import {
1818 TASK_PROVE_SUPB_PLAIN_NAME ,
1919 TASK_TYPE_SPARK ,
2020 findBuildAndRunTask ,
21- getBuildAndRunTasks ,
21+ getTasksWithPrefix ,
2222 getConventionalTaskLabel ,
2323 isFromWorkspace ,
2424 workspaceTasksFirst ,
25+ getBuildAndRunTaskName ,
2526} from './taskProviders' ;
2627import { createHelloWorldProject , walkthroughStartDebugging } from './walkthrough' ;
2728
@@ -43,6 +44,16 @@ export const CMD_BUILD_AND_RUN_MAIN = 'ada.buildAndRunMain';
4344 */
4445export const CMD_BUILD_AND_DEBUG_MAIN = 'ada.buildAndDebugMain' ;
4546
47+ /**
48+ * Identifier for a hidden command used for building and running a project main,
49+ * using GNATemulator.
50+ * The command accepts a parameter which is the URI of the main source file.
51+ * It is triggered by CodeLenses provided by the extension.
52+ *
53+ * @see {@link buildAndRunMainWithGNATemulator }
54+ */
55+ export const CMD_BUILD_AND_RUN_GNATEMULATOR = 'ada.buildAndRunGNATemulator' ;
56+
4657/**
4758 * Identifier for a hidden command that returns an array of strings constituting
4859 * the -P and -X project and scenario arguments.
@@ -127,6 +138,12 @@ export function registerCommands(context: vscode.ExtensionContext, clients: Exte
127138 context . subscriptions . push (
128139 vscode . commands . registerCommand ( CMD_BUILD_AND_DEBUG_MAIN , buildAndDebugSpecifiedMain ) ,
129140 ) ;
141+ context . subscriptions . push (
142+ vscode . commands . registerCommand (
143+ CMD_BUILD_AND_RUN_GNATEMULATOR ,
144+ buildAndRunMainWithGNATemulator ,
145+ ) ,
146+ ) ;
130147
131148 context . subscriptions . push (
132149 vscode . commands . registerCommand ( CMD_GPR_PROJECT_ARGS , gprProjectArgs ) ,
@@ -241,7 +258,7 @@ let lastUsedTaskInfo: { source: string; name: string } | undefined;
241258 * @returns the TaskExecution corresponding to the task.
242259 */
243260async function buildAndRunMainLast ( ) {
244- const buildAndRunTasks = await getBuildAndRunTasks ( ) ;
261+ const buildAndRunTasks = await getTasksWithPrefix ( getBuildAndRunTaskName ( ) ) ;
245262 if ( lastUsedTaskInfo ) {
246263 const matchingTasks = buildAndRunTasks . filter ( matchesLastUsedTask ) ;
247264 assert ( matchingTasks . length <= 1 ) ;
@@ -305,7 +322,7 @@ async function buildAndRunMainAsk() {
305322 ] ,
306323 } ;
307324 }
308- const adaTasksMain = await getBuildAndRunTasks ( ) ;
325+ const adaTasksMain = await getTasksWithPrefix ( getBuildAndRunTaskName ( ) ) ;
309326
310327 if ( adaTasksMain . length > 0 ) {
311328 const tasksFromWorkspace = adaTasksMain . filter ( isFromWorkspace ) ;
@@ -555,17 +572,23 @@ export async function checkSrcDirectories(atStartup = false, displayYesNoPopup =
555572 * displayed.
556573 *
557574 * @param main - a URI of a document
575+ * @param useGNATemulator - whether the main should be ran through
576+ * GNATemulator.
558577 */
559- async function buildAndRunSpecifiedMain ( main : vscode . Uri ) : Promise < void > {
578+ async function buildAndRunSpecifiedMain (
579+ main : vscode . Uri ,
580+ useGNATemulator : boolean = false ,
581+ ) : Promise < void > {
560582 const adaMain = await findAdaMain ( main . fsPath ) ;
561583 if ( adaMain ) {
562- const task = await findBuildAndRunTask ( adaMain ) ;
584+ const task = await findBuildAndRunTask ( adaMain , useGNATemulator ) ;
563585 if ( task ) {
564586 lastUsedTaskInfo = { source : task . source , name : task . name } ;
565587 await vscode . tasks . executeTask ( task ) ;
566588 } else {
589+ const taskLabel = useGNATemulator ? 'Build and Run GNATemulator' : 'Build and Run' ;
567590 void vscode . window . showErrorMessage (
568- `Could not find the 'Build and Run ' task for the project main ` +
591+ `Could not find the '${ taskLabel } ' task for the project main ` +
569592 `${ adaMain . mainRelPath ( ) } ` ,
570593 { modal : true } ,
571594 ) ;
@@ -579,6 +602,18 @@ async function buildAndRunSpecifiedMain(main: vscode.Uri): Promise<void> {
579602 }
580603}
581604
605+ /*
606+ * This is a command handler that builds and runs the main given as parameter,
607+ * using GNATemulator to run the executable.
608+ * If the given URI does not match one of the project Mains an error is
609+ * displayed.
610+ *
611+ * @param main - a URI of a document
612+ */
613+ async function buildAndRunMainWithGNATemulator ( main : vscode . Uri ) : Promise < void > {
614+ return buildAndRunSpecifiedMain ( main , true ) ;
615+ }
616+
582617/**
583618 * This is a command handler that builds the main given as parameter and starts
584619 * a debug session on that main. If the given URI does not match one of the
0 commit comments