Skip to content

Commit

Permalink
Add better parsing wait
Browse files Browse the repository at this point in the history
  • Loading branch information
jumanji144 committed Sep 21, 2023
1 parent 13eddf2 commit 92cb925
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import software.coley.recaf.util.FxThreadUtil;
import software.coley.recaf.workspace.model.bundle.Bundle;

import java.time.Duration;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand All @@ -49,7 +50,6 @@ public class AssemblerPane extends AbstractContentPane<PathNode<?>> implements U
private List<ASTElement> lastRoughAst;
private List<ASTElement> lastPartialAst;
private List<ASTElement> lastAst;
private long lastAstParse = 0;

@Inject
public AssemblerPane(@Nonnull AssemblerPipelineManager pipelineManager,
Expand All @@ -67,7 +67,9 @@ public AssemblerPane(@Nonnull AssemblerPipelineManager pipelineManager,
new ProblemGraphicFactory()
);

this.editor.getTextChangeEventStream().subscribe(event -> parseAST(ast -> {}));
this.editor.getTextChangeEventStream().successionEnds(Duration.ofMillis(timeToWait)).addObserver(e -> {
parseAST(ast -> {});
});

this.pipelineManager.getServiceConfig().getDisassemblyAstParseDelay().addChangeListener(
(observable, oldVal, newVal) -> timeToWait = newVal);
Expand Down Expand Up @@ -102,8 +104,7 @@ private void disassemble() {

private void parseAST(Consumer<List<ASTElement>> acceptor) {
if(editor.getText().isBlank()) return;
if(lastAstParse > System.currentTimeMillis() - timeToWait) return;
lastAstParse = System.currentTimeMillis();

CompletableFuture.runAsync(() -> {
try {
problemTracking.removeByPhase(ProblemPhase.LINT);
Expand Down Expand Up @@ -137,10 +138,10 @@ private void assemble() {
return;
CompletableFuture.runAsync(() -> {
try {
if(lastAst == null || lastAstParse < System.currentTimeMillis() - timeToWait) {
parseAST(ast -> assemble());
parseAST(ast -> {});

if(!problemTracking.getProblems().isEmpty() && lastAst == null)
return;
}

problemTracking.removeByPhase(ProblemPhase.BUILD);

Expand Down

0 comments on commit 92cb925

Please sign in to comment.