Skip to content

Commit

Permalink
Silence output to stdout caused by LanguageTool
Browse files Browse the repository at this point in the history
  • Loading branch information
me-johnomar authored and valentjn committed Jul 2, 2020
1 parent 3782367 commit f6baee5
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -72,7 +74,20 @@ public List<LanguageToolRuleMatch> check(AnnotatedText annotatedText) {
List<RuleMatch> matches;

try {
matches = this.languageTool.check(annotatedText);
// workaround bugs like https://github.com/languagetool-org/languagetool/issues/3181,
// in which LT prints to stdout instead of stderr (this messes up the LSP communication
// and results in a deadlock) => temporarily discard output to stdout
PrintStream stdout = System.out;
System.setOut(new PrintStream(new OutputStream() {
public void write(int b) {
}
}, false, "utf-8"));

try {
matches = this.languageTool.check(annotatedText);
} finally {
System.setOut(stdout);
}
} catch (RuntimeException | IOException e) {
Tools.logger.severe(Tools.i18n("languageToolFailed", e.getMessage()));
e.printStackTrace();
Expand Down

0 comments on commit f6baee5

Please sign in to comment.