Skip to content

Commit

Permalink
fix: only add the current path if the container is not currently writing
Browse files Browse the repository at this point in the history
  • Loading branch information
tyron12233 committed Feb 6, 2022
1 parent b16f43f commit 3be31fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public <T> T get(Function1<CompileTask, T> fun) {
}
}

public boolean isWriting() {
return mIsWriting;
}

void initialize(Runnable runnable) {
synchronized (mLock) {
assertIsNotReader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.tyron.completion.java.JavaCompilerProvider;
import com.tyron.completion.java.action.CommonJavaContextKeys;
import com.tyron.completion.java.action.FindCurrentPath;
import com.tyron.completion.java.compiler.CompilerContainer;
import com.tyron.completion.java.compiler.JavaCompilerService;

import org.openjdk.source.tree.CompilationUnitTree;
Expand All @@ -30,16 +31,20 @@ public static void addEditorKeys(DataContext context, Project project, File file
JavaCompilerProvider service = CompilerService.getInstance().getIndex(JavaCompilerProvider.KEY);
JavaCompilerService compiler = service.getCompiler(project, (JavaModule) currentModule);

compiler.getCachedContainer().run(task -> {
if (task != null) {
CompilationUnitTree root = task.root(file);
if (root != null) {
FindCurrentPath findCurrentPath = new FindCurrentPath(task.task);
TreePath currentPath = findCurrentPath.scan(root, cursor);
context.putData(CommonJavaContextKeys.CURRENT_PATH, currentPath);
CompilerContainer cachedContainer = compiler.getCachedContainer();
// don't block the ui thread
if (!cachedContainer.isWriting()) {
cachedContainer.run(task -> {
if (task != null) {
CompilationUnitTree root = task.root(file);
if (root != null) {
FindCurrentPath findCurrentPath = new FindCurrentPath(task.task);
TreePath currentPath = findCurrentPath.scan(root, cursor);
context.putData(CommonJavaContextKeys.CURRENT_PATH, currentPath);
}
}
}
});
});
}
context.putData(CommonJavaContextKeys.COMPILER, compiler);
}
}
Expand Down

0 comments on commit 3be31fb

Please sign in to comment.