@@ -24,6 +24,7 @@ class CodeConversion
2424 private readonly VisualStudioWorkspace _visualStudioWorkspace ;
2525 public static readonly string ConverterTitle = "Code converter" ;
2626 private static readonly string Intro = Environment . NewLine + Environment . NewLine + new string ( Enumerable . Repeat ( '-' , 80 ) . ToArray ( ) ) + Environment . NewLine + "Writing converted files to disk:" ;
27+ private VisualStudioInteraction . OutputWindow _outputWindow ;
2728 private string SolutionDir => Path . GetDirectoryName ( _visualStudioWorkspace . CurrentSolution . FilePath ) ;
2829
2930 public CodeConversion ( IServiceProvider serviceProvider , VisualStudioWorkspace visualStudioWorkspace ,
@@ -32,6 +33,7 @@ public CodeConversion(IServiceProvider serviceProvider, VisualStudioWorkspace vi
3233 GetOptions = getOptions ;
3334 _serviceProvider = serviceProvider ;
3435 _visualStudioWorkspace = visualStudioWorkspace ;
36+ _outputWindow = new VisualStudioInteraction . OutputWindow ( ) ;
3537 }
3638
3739 public async Task PerformProjectConversion < TLanguageConversion > ( IReadOnlyCollection < Project > selectedProjects ) where TLanguageConversion : ILanguageConversion , new ( )
@@ -52,7 +54,7 @@ await Task.Run(() => {
5254
5355 if ( GetOptions ( ) . CopyResultToClipboardForSingleDocument ) {
5456 Clipboard . SetText ( conversionResult . ConvertedCode ?? conversionResult . GetExceptionsAsString ( ) ) ;
55- VisualStudioInteraction . OutputWindow . WriteToOutputWindow ( "Conversion result copied to clipboard." ) ;
57+ _outputWindow . WriteToOutputWindow ( "Conversion result copied to clipboard." ) ;
5658 VisualStudioInteraction . ShowMessageBox ( _serviceProvider , "Conversion result copied to clipboard." , conversionResult . GetExceptionsAsString ( ) , false ) ;
5759 }
5860
@@ -66,8 +68,9 @@ private void WriteConvertedFilesAndShowSummary(IEnumerable<ConversionResult> con
6668 string longestFilePath = null ;
6769 var longestFileLength = - 1 ;
6870
69- VisualStudioInteraction . OutputWindow . WriteToOutputWindow ( Intro ) ;
70- VisualStudioInteraction . OutputWindow . ForceShowOutputPane ( ) ;
71+ _outputWindow . Clear ( ) ;
72+ _outputWindow . WriteToOutputWindow ( Intro ) ;
73+ _outputWindow . ForceShowOutputPane ( ) ;
7174
7275 foreach ( var convertedFile in convertedFiles ) {
7376 if ( convertedFile . SourcePathOrNull == null ) continue ;
@@ -96,8 +99,8 @@ private void FinalizeConversion(List<string> files, List<string> errors, string
9699 {
97100 var options = GetOptions ( ) ;
98101 var conversionSummary = GetConversionSummary ( files , errors ) ;
99- VisualStudioInteraction . OutputWindow . WriteToOutputWindow ( conversionSummary ) ;
100- VisualStudioInteraction . OutputWindow . ForceShowOutputPane ( ) ;
102+ _outputWindow . WriteToOutputWindow ( conversionSummary ) ;
103+ _outputWindow . ForceShowOutputPane ( ) ;
101104
102105 if ( longestFilePath != null )
103106 {
@@ -113,14 +116,14 @@ private void FinalizeConversion(List<string> files, List<string> errors, string
113116 if ( shouldOverwriteSolutionAndProjectFiles )
114117 {
115118 var titleMessage = options . CreateBackups ? "Creating backups and overwriting files:" : "Overwriting files:" + "" ;
116- VisualStudioInteraction . OutputWindow . WriteToOutputWindow ( titleMessage ) ;
119+ _outputWindow . WriteToOutputWindow ( titleMessage ) ;
117120 foreach ( var fileToOverwrite in filesToOverwrite )
118121 {
119122 if ( options . CreateBackups ) File . Copy ( fileToOverwrite . SourcePathOrNull , fileToOverwrite . SourcePathOrNull + ".bak" , true ) ;
120123 File . WriteAllText ( fileToOverwrite . TargetPathOrNull , fileToOverwrite . ConvertedCode ) ;
121124
122125 var targetPathRelativeToSolutionDir = PathRelativeToSolutionDir ( fileToOverwrite . TargetPathOrNull ) ;
123- VisualStudioInteraction . OutputWindow . WriteToOutputWindow ( Environment . NewLine + $ "* { targetPathRelativeToSolutionDir } ") ;
126+ _outputWindow . WriteToOutputWindow ( Environment . NewLine + $ "* { targetPathRelativeToSolutionDir } ") ;
124127 }
125128 }
126129 }
@@ -163,7 +166,7 @@ private void LogProgress(ConversionResult convertedFile, List<string> errors)
163166 output += $ " contains errors{ Environment . NewLine } { indentedException } ";
164167 }
165168
166- VisualStudioInteraction . OutputWindow . WriteToOutputWindow ( output ) ;
169+ _outputWindow . WriteToOutputWindow ( output ) ;
167170 }
168171
169172 private string PathRelativeToSolutionDir ( string path )
0 commit comments