Skip to content

Commit 904bd14

Browse files
committed
Try writing to the stream a few times
1 parent 8c6a3b1 commit 904bd14

2 files changed

Lines changed: 28 additions & 24 deletions

File tree

Src/CSharpier.Rider/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pluginGroup = com.intellij.csharpier
55
pluginName = csharpier
66
# SemVer format -> https://semver.org
7-
pluginVersion = 1.3.10
7+
pluginVersion = 1.3.11-beta1
88

99
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
# for insight into build numbers and IntelliJ Platform versions.

Src/CSharpier.Rider/src/main/java/com/intellij/csharpier/CSharpierProcessPipeMultipleFiles.java

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)