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:
+9
-9
@@ -167,32 +167,32 @@ public final class AnalyzerWithCompilerReport {
|
|||||||
|
|
||||||
public static class SyntaxErrorReport {
|
public static class SyntaxErrorReport {
|
||||||
private final boolean hasErrors;
|
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.hasErrors = hasErrors;
|
||||||
this.onlyErrorAtEof = onlyErrorAtEof;
|
this.allErrorsAtEof = allErrorsAtEof;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHasErrors() {
|
public boolean isHasErrors() {
|
||||||
return hasErrors;
|
return hasErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOnlyErrorAtEof() {
|
public boolean isAllErrorsAtEof() {
|
||||||
return onlyErrorAtEof;
|
return allErrorsAtEof;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SyntaxErrorReport reportSyntaxErrors(@NotNull final PsiElement file, @NotNull final MessageCollector messageCollector) {
|
public static SyntaxErrorReport reportSyntaxErrors(@NotNull final PsiElement file, @NotNull final MessageCollector messageCollector) {
|
||||||
class ErrorReportingVisitor extends AnalyzingUtils.PsiErrorElementVisitor {
|
class ErrorReportingVisitor extends AnalyzingUtils.PsiErrorElementVisitor {
|
||||||
boolean hasErrors = false;
|
boolean hasErrors = false;
|
||||||
boolean onlyErrorAtEof = false;
|
boolean allErrorsAtEof = true;
|
||||||
|
|
||||||
private <E extends PsiElement> void reportDiagnostic(E element, DiagnosticFactory0<E> factory, String message) {
|
private <E extends PsiElement> void reportDiagnostic(E element, DiagnosticFactory0<E> factory, String message) {
|
||||||
MyDiagnostic<?> diagnostic = new MyDiagnostic<E>(element, factory, message);
|
MyDiagnostic<?> diagnostic = new MyDiagnostic<E>(element, factory, message);
|
||||||
AnalyzerWithCompilerReport.reportDiagnostic(diagnostic, messageCollector);
|
AnalyzerWithCompilerReport.reportDiagnostic(diagnostic, messageCollector);
|
||||||
if (element.getTextRange().getStartOffset() == file.getTextRange().getEndOffset()) {
|
if (element.getTextRange().getStartOffset() != file.getTextRange().getEndOffset()) {
|
||||||
onlyErrorAtEof = !hasErrors;
|
allErrorsAtEof = false;
|
||||||
}
|
}
|
||||||
hasErrors = true;
|
hasErrors = true;
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,7 @@ public final class AnalyzerWithCompilerReport {
|
|||||||
|
|
||||||
file.accept(visitor);
|
file.accept(visitor);
|
||||||
|
|
||||||
return new SyntaxErrorReport(visitor.hasErrors, visitor.onlyErrorAtEof);
|
return new SyntaxErrorReport(visitor.hasErrors, visitor.allErrorsAtEof);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ public class ReplInterpreter {
|
|||||||
AnalyzerWithCompilerReport.SyntaxErrorReport syntaxErrorReport =
|
AnalyzerWithCompilerReport.SyntaxErrorReport syntaxErrorReport =
|
||||||
AnalyzerWithCompilerReport.reportSyntaxErrors(psiFile, errorCollector);
|
AnalyzerWithCompilerReport.reportSyntaxErrors(psiFile, errorCollector);
|
||||||
|
|
||||||
if (syntaxErrorReport.isOnlyErrorAtEof()) {
|
if (syntaxErrorReport.isHasErrors() && syntaxErrorReport.isAllErrorsAtEof()) {
|
||||||
previousIncompleteLines.add(line);
|
previousIncompleteLines.add(line);
|
||||||
return LineResult.incomplete();
|
return LineResult.incomplete();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
>>> fun concat(a: String, b: String, c: String, d: String) = "$a$b$c$d"
|
||||||
|
>>> concat(
|
||||||
|
... "hel",
|
||||||
|
... "lo"
|
||||||
|
... ,
|
||||||
|
... "wo" +
|
||||||
|
... "r", "l" +
|
||||||
|
... "d"
|
||||||
|
... )
|
||||||
|
helloworld
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
>>> fun sum(x: Int, y: Int) = x + y
|
||||||
|
>>> sum(
|
||||||
|
... 23,19)
|
||||||
|
42
|
||||||
@@ -31,7 +31,7 @@ import org.jetbrains.jet.repl.AbstractReplInterpreterTest;
|
|||||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@TestMetadata("compiler/testData/repl")
|
@TestMetadata("compiler/testData/repl")
|
||||||
@InnerTestClasses({ReplInterpreterTestGenerated.Classes.class, ReplInterpreterTestGenerated.Objects.class, ReplInterpreterTestGenerated.Reflection.class})
|
@InnerTestClasses({ReplInterpreterTestGenerated.Classes.class, ReplInterpreterTestGenerated.Multiline.class, ReplInterpreterTestGenerated.Objects.class, ReplInterpreterTestGenerated.Reflection.class})
|
||||||
public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
|
public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
|
||||||
public void testAllFilesPresentInRepl() throws Exception {
|
public void testAllFilesPresentInRepl() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/repl"), Pattern.compile("^(.+)\\.repl$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/repl"), Pattern.compile("^(.+)\\.repl$"), true);
|
||||||
@@ -82,16 +82,6 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
|
|||||||
doTest("compiler/testData/repl/imports.repl");
|
doTest("compiler/testData/repl/imports.repl");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("multiline.repl")
|
|
||||||
public void testMultiline() throws Exception {
|
|
||||||
doTest("compiler/testData/repl/multiline.repl");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("multiline3.repl")
|
|
||||||
public void testMultiline3() throws Exception {
|
|
||||||
doTest("compiler/testData/repl/multiline3.repl");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("simple.repl")
|
@TestMetadata("simple.repl")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
doTest("compiler/testData/repl/simple.repl");
|
doTest("compiler/testData/repl/simple.repl");
|
||||||
@@ -160,6 +150,34 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/repl/multiline")
|
||||||
|
public static class Multiline extends AbstractReplInterpreterTest {
|
||||||
|
public void testAllFilesPresentInMultiline() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/repl/multiline"), Pattern.compile("^(.+)\\.repl$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionOnSeveralLines.repl")
|
||||||
|
public void testFunctionOnSeveralLines() throws Exception {
|
||||||
|
doTest("compiler/testData/repl/multiline/functionOnSeveralLines.repl");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("multilineFunctionInvocation.repl")
|
||||||
|
public void testMultilineFunctionInvocation() throws Exception {
|
||||||
|
doTest("compiler/testData/repl/multiline/multilineFunctionInvocation.repl");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("openParenthesisIncomplete.repl")
|
||||||
|
public void testOpenParenthesisIncomplete() throws Exception {
|
||||||
|
doTest("compiler/testData/repl/multiline/openParenthesisIncomplete.repl");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simpleFunctionBodyOnNextLine.repl")
|
||||||
|
public void testSimpleFunctionBodyOnNextLine() throws Exception {
|
||||||
|
doTest("compiler/testData/repl/multiline/simpleFunctionBodyOnNextLine.repl");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/repl/objects")
|
@TestMetadata("compiler/testData/repl/objects")
|
||||||
public static class Objects extends AbstractReplInterpreterTest {
|
public static class Objects extends AbstractReplInterpreterTest {
|
||||||
public void testAllFilesPresentInObjects() throws Exception {
|
public void testAllFilesPresentInObjects() throws Exception {
|
||||||
@@ -195,6 +213,7 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest {
|
|||||||
TestSuite suite = new TestSuite("ReplInterpreterTestGenerated");
|
TestSuite suite = new TestSuite("ReplInterpreterTestGenerated");
|
||||||
suite.addTestSuite(ReplInterpreterTestGenerated.class);
|
suite.addTestSuite(ReplInterpreterTestGenerated.class);
|
||||||
suite.addTestSuite(Classes.class);
|
suite.addTestSuite(Classes.class);
|
||||||
|
suite.addTestSuite(Multiline.class);
|
||||||
suite.addTestSuite(Objects.class);
|
suite.addTestSuite(Objects.class);
|
||||||
suite.addTestSuite(Reflection.class);
|
suite.addTestSuite(Reflection.class);
|
||||||
return suite;
|
return suite;
|
||||||
|
|||||||
Reference in New Issue
Block a user