Skip to content

Commit

Permalink
fixed flickering errors while typing
Browse files Browse the repository at this point in the history
  • Loading branch information
peq committed Oct 9, 2021
1 parent b4f265b commit c4f4c8b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Expand Up @@ -529,7 +529,14 @@ private CompilationUnit replaceCompilationUnit(WFile filename, String contents,
if (gui.getErrorCount() > 0) {
WLogger.info("found " + gui.getErrorCount() + " errors in file " + filename);
}
reportErrors("sync cu " + filename, filename, gui.getErrorsAndWarnings());
ImmutableList.Builder<CompileError> errors = ImmutableList.<CompileError>builder()
.addAll(gui.getErrorsAndWarnings());

if (otherErrors.containsKey(filename)) {
errors.addAll(otherErrors.get(filename));
}

reportErrors("sync cu " + filename, filename, errors.build());
}
return cu;
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;

import static org.hamcrest.CoreMatchers.containsString;
Expand Down Expand Up @@ -545,5 +546,51 @@ public void moduleTransitive() throws IOException {
assertThat(errors.get(fileT1), CoreMatchers.containsString("Could not find function foo"));
}

@Test
public void keepTypeErrorsWhileEditing() throws IOException {
File projectFolder = new File("./temp/testProject2/");
File wurstFolder = new File(projectFolder, "wurst");
newCleanFolder(wurstFolder);


String packageT1 = string(
"package T1",
"init",
" foo()"
);

String packageT1updated = string(
"package T1",
"init",
" foo()",
" if ("
);

WFile fileT1 = WFile.create(new File(wurstFolder, "T1.wurst"));
WFile fileWurst = WFile.create(new File(wurstFolder, "Wurst.wurst"));


writeFile(fileT1, packageT1);
writeFile(fileWurst, "package Wurst\n");


ModelManagerImpl manager = new ModelManagerImpl(projectFolder, new BufferManager());
Map<WFile, String> errors = keepErrorsInMap(manager);


// first build the project
manager.buildProject();
// should show the type error
assertThat(errors.get(fileT1), CoreMatchers.containsString("Reference to function foo could not be resolved."));


// now, update package T1 and introduce a syntax error
manager.syncCompilationUnitContent(fileT1, packageT1updated);

// now the errors should contain the syntax error and the type error
assertThat(errors.get(fileT1), CoreMatchers.containsString("Reference to function foo could not be resolved."));
assertThat(errors.get(fileT1), CoreMatchers.containsString("extraneous input '(' expecting NL"));
}


}

0 comments on commit c4f4c8b

Please sign in to comment.