Skip to content

Commit 0c26c66

Browse files
authored
Merge pull request #3 from DeepCodeAI/dev
1.0.1
2 parents 973f39a + 3dd2dc9 commit 0c26c66

File tree

7 files changed

+38
-12
lines changed

7 files changed

+38
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [1.0.1] - 2019-05-22
2+
- Updated Java-client and added support for Java 8, required for Android Studio
3+
14
## [1.0.0] - 2019-05-21
25
### Added
36
- First public beta release

build.gradle

Lines changed: 2 additions & 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 {
@@ -36,6 +36,7 @@ patchPluginXml {
3636
untilBuild 202
3737

3838
changeNotes """
39+
1.0.1 - Updated Java-client and added support for Java 8, required for Android Studio<br>
3940
1.0.0 - First public beta release.<br>
4041
"""
4142
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ static Set<Project> getAllCachedProject() {
109109
static void removeFilesFromCache(@NotNull Collection<PsiFile> files) {
110110
try {
111111
info("Request to remove from cache " + files.size() + " files: " + files);
112+
// todo: do we really need mutex here?
112113
MUTEX.lock();
113114
int removeCounter = 0;
114115
for (PsiFile file : files) {
@@ -597,10 +598,8 @@ public static void clearCache(@Nullable final Project project) {
597598
info("Cache clearance requested for project: " + project);
598599
mapPsiFile2Hash.clear();
599600
mapPsiFile2Content.clear();
600-
final Project[] projects =
601-
(project == null)
602-
? ProjectManager.getInstance().getOpenProjects()
603-
: new Project[] {project};
601+
final Set<Project> projects =
602+
(project == null) ? getAllCachedProject() : Collections.singleton(project);
604603
for (Project prj : projects) {
605604
removeProjectFromCache(prj);
606605
ServiceManager.getService(prj, myTodoView.class).refresh();

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/MyBulkFileListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void after(@NotNull List<? extends VFileEvent> events) {
8181
public void before(@NotNull List<? extends VFileEvent> events) {
8282
DCLogger.info("MyBulkFileListener.before begins");
8383
for (Project project : AnalysisData.getAllCachedProject()) {
84+
if (project.isDisposed()) continue;
8485
Set<PsiFile> filesRemoved =
8586
getFilteredFilesByEventTypes(
8687
project, events, DeepCodeUtils::isSupportedFileFormat, VFileDeleteEvent.class);

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)