@@ -545,6 +545,73 @@ async function executeRapicgenTypeScript(generator: string, specificationFilePat
545
545
}
546
546
}
547
547
548
+ /**
549
+ * Executes the Rapicgen tool with Refitter using a settings file
550
+ * @param settingsFilePath The path to the .refitter settings file
551
+ * @param context The extension context
552
+ */
553
+ async function executeRapicgenRefitterSettings ( settingsFilePath : string , context : vscode . ExtensionContext ) : Promise < void > {
554
+ // Validate the settings file
555
+ if ( ! validateSpecificationFile ( settingsFilePath ) ) {
556
+ return ;
557
+ }
558
+
559
+ // Check if .NET SDK is installed
560
+ if ( ! isDotNetSdkInstalled ( ) ) {
561
+ vscode . window . showErrorMessage (
562
+ '.NET SDK not found. Please install .NET SDK 6.0 or higher to use this extension. Visit https://dotnet.microsoft.com/download/dotnet to download and install.'
563
+ ) ;
564
+ return ;
565
+ }
566
+
567
+ // Ensure the Rapicgen tool is installed and up-to-date
568
+ const rapicgenAvailable = await ensureRapicgenToolAvailable ( context ) ;
569
+ if ( ! rapicgenAvailable ) {
570
+ return ;
571
+ }
572
+
573
+ const command = `rapicgen csharp refitter --settings-file "${ settingsFilePath } "` ;
574
+
575
+ try {
576
+ // Show progress while generating
577
+ await vscode . window . withProgress ( {
578
+ location : vscode . ProgressLocation . Notification ,
579
+ title : 'Generating Refitter output from settings file...' ,
580
+ cancellable : false
581
+ } , async ( ) => {
582
+ try {
583
+ // Run with higher timeout since code generation can take time
584
+ const output = execSync ( command , {
585
+ encoding : 'utf-8' ,
586
+ timeout : 120000 // 2 minute timeout
587
+ } ) ;
588
+
589
+ // Log output for debugging
590
+ console . log ( `Rapicgen Refitter settings output: ${ output } ` ) ;
591
+
592
+ vscode . window . showInformationMessage ( 'Successfully generated Refitter output from settings file' ) ;
593
+ } catch ( error : unknown ) {
594
+ let errorMessage = 'Error generating Refitter output from settings file' ;
595
+
596
+ const err = error as { message ?: string ; stderr ?: string } ;
597
+ if ( err . message ) {
598
+ errorMessage += `: ${ err . message } ` ;
599
+ }
600
+
601
+ if ( err . stderr ) {
602
+ errorMessage += `\n${ err . stderr } ` ;
603
+ console . error ( 'Command stderr:' , err . stderr ) ;
604
+ }
605
+
606
+ vscode . window . showErrorMessage ( errorMessage ) ;
607
+ console . error ( 'Command execution error:' , error ) ;
608
+ }
609
+ } ) ;
610
+ } catch ( error ) {
611
+ console . error ( 'Error during Refitter settings code generation process:' , error ) ;
612
+ }
613
+ }
614
+
548
615
/**
549
616
* Validates that a specification file exists and is readable
550
617
* @param specificationFilePath The path to the OpenAPI/Swagger specification file
@@ -641,10 +708,42 @@ export function activate(context: vscode.ExtensionContext) {
641
708
642
709
executeRapicgenTypeScript ( generator . command , fileUri . fsPath , context ) ;
643
710
}
644
- ) ;
645
-
646
- context . subscriptions . push ( disposable ) ;
711
+ ) ; context . subscriptions . push ( disposable ) ;
647
712
}
713
+
714
+ // Register command for Refitter settings
715
+ const refitterSettingsDisposable = vscode . commands . registerCommand (
716
+ 'restApiClientCodeGenerator.refitterSettings' ,
717
+ async ( fileUri : vscode . Uri ) => {
718
+ if ( ! fileUri ) {
719
+ // If command was triggered from command palette, ask for file
720
+ const files = await vscode . workspace . findFiles ( '**/*.refitter' ) ;
721
+ if ( files . length === 0 ) {
722
+ vscode . window . showErrorMessage ( 'No .refitter settings files found in the workspace' ) ;
723
+ return ;
724
+ }
725
+
726
+ const fileItems = files . map ( file => ( {
727
+ label : path . basename ( file . fsPath ) ,
728
+ description : vscode . workspace . asRelativePath ( file ) ,
729
+ path : file . fsPath
730
+ } ) ) ;
731
+
732
+ const selectedFile = await vscode . window . showQuickPick ( fileItems , {
733
+ placeHolder : 'Select a .refitter settings file'
734
+ } ) ;
735
+
736
+ if ( ! selectedFile ) {
737
+ return ;
738
+ }
739
+ fileUri = vscode . Uri . file ( selectedFile . path ) ;
740
+ }
741
+
742
+ executeRapicgenRefitterSettings ( fileUri . fsPath , context ) ;
743
+ }
744
+ ) ;
745
+
746
+ context . subscriptions . push ( refitterSettingsDisposable ) ;
648
747
}
649
748
650
749
/**
0 commit comments