REPL: fix open parenthesis not triggering "incomplete"

Check if all of the syntax errors are at EOF, not that there's a single one.
In case of open parenthesis two syntax errors are reported for some reason
This commit is contained in:
Alexander Udalov
2014-07-27 17:34:41 -07:00
parent 4213ce318e
commit 6eb5567895
7 changed files with 54 additions and 21 deletions
@@ -167,32 +167,32 @@ public final class AnalyzerWithCompilerReport {
public static class SyntaxErrorReport {
private final boolean hasErrors;
private final boolean onlyErrorAtEof;
private final boolean allErrorsAtEof;
public SyntaxErrorReport(boolean hasErrors, boolean onlyErrorAtEof) {
public SyntaxErrorReport(boolean hasErrors, boolean allErrorsAtEof) {
this.hasErrors = hasErrors;
this.onlyErrorAtEof = onlyErrorAtEof;
this.allErrorsAtEof = allErrorsAtEof;
}
public boolean isHasErrors() {
return hasErrors;
}
public boolean isOnlyErrorAtEof() {
return onlyErrorAtEof;
public boolean isAllErrorsAtEof() {
return allErrorsAtEof;
}
}
public static SyntaxErrorReport reportSyntaxErrors(@NotNull final PsiElement file, @NotNull final MessageCollector messageCollector) {
class ErrorReportingVisitor extends AnalyzingUtils.PsiErrorElementVisitor {
boolean hasErrors = false;
boolean onlyErrorAtEof = false;
boolean allErrorsAtEof = true;
private <E extends PsiElement> void reportDiagnostic(E element, DiagnosticFactory0<E> factory, String message) {
MyDiagnostic<?> diagnostic = new MyDiagnostic<E>(element, factory, message);
AnalyzerWithCompilerReport.reportDiagnostic(diagnostic, messageCollector);
if (element.getTextRange().getStartOffset() == file.getTextRange().getEndOffset()) {
onlyErrorAtEof = !hasErrors;
if (element.getTextRange().getStartOffset() != file.getTextRange().getEndOffset()) {
allErrorsAtEof = false;
}
hasErrors = true;
}
@@ -207,7 +207,7 @@ public final class AnalyzerWithCompilerReport {
file.accept(visitor);
return new SyntaxErrorReport(visitor.hasErrors, visitor.onlyErrorAtEof);
return new SyntaxErrorReport(visitor.hasErrors, visitor.allErrorsAtEof);
}
@Nullable
@@ -222,7 +222,7 @@ public class ReplInterpreter {
AnalyzerWithCompilerReport.SyntaxErrorReport syntaxErrorReport =
AnalyzerWithCompilerReport.reportSyntaxErrors(psiFile, errorCollector);
if (syntaxErrorReport.isOnlyErrorAtEof()) {
if (syntaxErrorReport.isHasErrors() && syntaxErrorReport.isAllErrorsAtEof()) {
previousIncompleteLines.add(line);
return LineResult.incomplete();
}