@@ -19,6 +19,11 @@ public CSharpierProcessPipeMultipleFiles(String csharpierPath, boolean useUtf8)
1919 this .csharpierPath = csharpierPath ;
2020 this .useUtf8 = useUtf8 ;
2121 this .startProcess ();
22+
23+ this .logger .debug ("Warm CSharpier with initial format" );
24+ // warm by formatting a file twice, the 3rd time is when it gets really fast
25+ this .formatFile ("public class ClassName { }" , "Test.cs" );
26+ this .formatFile ("public class ClassName { }" , "Test.cs" );
2227 }
2328
2429 private void startProcess () {
@@ -35,41 +40,40 @@ private void startProcess() {
3540 // if we don't read the error stream, eventually too much is buffered on it and the plugin hangs
3641 var errorGobbler = new StreamGobbler (this .process .getErrorStream ());
3742 errorGobbler .start ();
38-
39-
4043 } catch (Exception e ) {
4144 this .logger .error ("error" , e );
4245 }
43-
44- this .logger .debug ("Warm CSharpier with initial format" );
45- // warm by formatting a file twice, the 3rd time is when it gets really fast
46- this .formatFile ("public class ClassName { }" , "Test.cs" );
47- this .formatFile ("public class ClassName { }" , "Test.cs" );
4846 }
4947
5048 @ Override
5149 public String formatFile (String content , String filePath ) {
5250 var stringBuilder = new StringBuilder ();
5351
5452 Runnable task = () -> {
55- try {
56- this .stdin .write (filePath );
57- this .stdin .write ('\u0003' );
58- this .stdin .write (content );
59- this .stdin .write ('\u0003' );
60- this .stdin .flush ();
61-
62- var nextCharacter = this .stdOut .read ();
63- while (nextCharacter != -1 ) {
64- if (nextCharacter == '\u0003' ) {
65- break ;
53+ var attempt = 1 ;
54+ while (attempt < 5 ) {
55+ try {
56+ this .stdin .write (filePath );
57+ this .stdin .write ('\u0003' );
58+ this .stdin .write (content );
59+ this .stdin .write ('\u0003' );
60+ this .stdin .flush ();
61+
62+ var nextCharacter = this .stdOut .read ();
63+ while (nextCharacter != -1 ) {
64+ if (nextCharacter == '\u0003' ) {
65+ break ;
66+ }
67+ stringBuilder .append ((char ) nextCharacter );
68+ nextCharacter = this .stdOut .read ();
6669 }
67- stringBuilder .append ((char ) nextCharacter );
68- nextCharacter = this .stdOut .read ();
70+ break ;
71+ } catch (IOException e ) {
72+ this .logger .warn (e );
73+ this .startProcess ();
74+ stringBuilder .setLength (0 );
75+ attempt ++;
6976 }
70- } catch (Exception e ) {
71- this .logger .error (e );
72- e .printStackTrace ();
7377 }
7478 };
7579
0 commit comments