Skip to content

Commit f326589

Browse files
committed
fix freezes with bulk files update (rename refactoring in few files);
1 parent 973f39a commit f326589

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77

88
//group 'org.example'
99

10-
version '1.0.0'
10+
version '1.0.1'
1111
sourceCompatibility = 1.8
1212

1313
repositories {

src/main/java/ai/deepcode/jbplugin/core/DCLogger.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ private static synchronized void doLogging(String message, Consumer<String> logF
5353
String s =
5454
ste.getClassName().substring(ste.getClassName().lastIndexOf('.') + 1)
5555
+ "."
56-
+ ste.getMethodName();
56+
+ ste.getMethodName()
57+
+ ":"
58+
+ ste.getLineNumber();
5759
joiner.add(s);
5860
}
5961
}

src/main/java/ai/deepcode/jbplugin/core/MyProjectManagerListener.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void projectOpened(@NotNull Project project) {
3333
@Override
3434
public void projectClosing(@NotNull Project project) {
3535
// lets all running ProgressIndicators release MUTEX first
36-
//RunUtils.cancelRunningIndicators(project);
36+
// RunUtils.cancelRunningIndicators(project);
3737
RunUtils.runInBackground(project, () -> AnalysisData.removeProjectFromCache(project));
3838
}
3939

@@ -43,8 +43,11 @@ public void beforeChildrenChange(@NotNull PsiTreeChangeEvent event) {
4343
final PsiFile psiFile = event.getFile();
4444
if (psiFile == null) return;
4545
if (AnalysisData.isFileInCache(psiFile)) {
46-
// immediate delete for visual updates in Panel, annotations, etc.
47-
AnalysisData.removeFilesFromCache(Collections.singleton(psiFile));
46+
// ?? immediate delete for visual updates in Panel, annotations, etc.
47+
// should be done in background to wait MUTEX released in case of currently running update
48+
RunUtils.runInBackground(
49+
psiFile.getProject(),
50+
() -> AnalysisData.removeFilesFromCache(Collections.singleton(psiFile)));
4851
}
4952
/*
5053
if (DeepCodeUtils.isSupportedFileFormat(psiFile)) {

src/main/java/ai/deepcode/jbplugin/core/RunUtils.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void run(@NotNull ProgressIndicator indicator) {
109109
private static final Map<Project, Set<ProgressIndicator>> mapProject2Indicators =
110110
new ConcurrentHashMap<>();
111111

112-
private static Set<ProgressIndicator> getRunningIndicators(@NotNull Project project) {
112+
private static synchronized Set<ProgressIndicator> getRunningIndicators(@NotNull Project project) {
113113
return mapProject2Indicators.computeIfAbsent(project, p -> new HashSet<>());
114114
}
115115

@@ -130,17 +130,28 @@ public static void cancelRunningIndicators(@NotNull Project project) {
130130
private static final Map<VirtualFile, ProgressIndicator> mapFileProcessed2CancellableIndicator =
131131
new ConcurrentHashMap<>();
132132

133+
private static final Map<VirtualFile, Runnable> mapFile2Runnable = new ConcurrentHashMap<>();
134+
133135
public static void runInBackgroundCancellable(
134136
@NotNull PsiFile psiFile, @NotNull Runnable runnable) {
135137
DCLogger.info("runInBackgroundCancellable requested for: " + psiFile.getName());
138+
final VirtualFile virtualFile = psiFile.getVirtualFile();
139+
140+
// To proceed multiple PSI events in a bunch (every 100 milliseconds)
141+
Runnable prevRunnable = mapFile2Runnable.put(virtualFile, runnable);
142+
if (prevRunnable != null) return;
143+
DCLogger.info("new Background task registered for: " + psiFile.getName());
144+
136145
final Project project = psiFile.getProject();
137146
ProgressManager.getInstance()
138147
.run(
139148
new Task.Backgroundable(project, "DeepCode: Analysing Files...") {
140149
@Override
141150
public void run(@NotNull ProgressIndicator indicator) {
151+
152+
// To let new event cancel the currently running one
142153
ProgressIndicator prevProgressIndicator =
143-
mapFileProcessed2CancellableIndicator.put(psiFile.getVirtualFile(), indicator);
154+
mapFileProcessed2CancellableIndicator.put(virtualFile, indicator);
144155
if (prevProgressIndicator != null
145156
// can't use prevProgressIndicator.isRunning() due to
146157
// https://youtrack.jetbrains.com/issue/IDEA-241055
@@ -160,7 +171,13 @@ && getRunningIndicators(project).contains(prevProgressIndicator)) {
160171
delay(100);
161172

162173
DCLogger.info("New Process started for " + psiFile.getName());
163-
runnable.run();
174+
Runnable actualRunnable = mapFile2Runnable.get(virtualFile);
175+
mapFile2Runnable.remove(virtualFile);
176+
if (actualRunnable != null) {
177+
actualRunnable.run();
178+
} else {
179+
DCLogger.warn("No actual Runnable found for: " + psiFile.getName());
180+
}
164181
DCLogger.info("Process ending for " + psiFile.getName());
165182
}
166183
});

0 commit comments

Comments
 (0)