pref: Cache update ReadAction.nonBlocking once
This commit is contained in:
@@ -78,7 +78,9 @@ public class LineEndCacheUtils {
|
||||
isRun = true;
|
||||
AppExecutorUtil.getAppScheduledExecutorService().scheduleWithFixedDelay(() -> {
|
||||
try {
|
||||
cacheUpdate();
|
||||
ReadAction.nonBlocking(LineEndCacheUtils::cacheUpdate)
|
||||
.inSmartMode(project)
|
||||
.submit(AppExecutorUtil.getAppExecutorService());
|
||||
} catch (ProcessCanceledException ignored) {
|
||||
} catch (Throwable e) {
|
||||
LOG.info("LineEndCacheUtils checkScheduleAndInit catch Throwable but log to record.", e);
|
||||
@@ -91,62 +93,60 @@ public class LineEndCacheUtils {
|
||||
|
||||
private static void cacheUpdate() {
|
||||
cache.forEach((project, fileMap) -> {
|
||||
ReadAction.nonBlocking(() -> {
|
||||
try {
|
||||
if (project.isDisposed()) {
|
||||
cache.remove(project);
|
||||
try {
|
||||
if (project.isDisposed()) {
|
||||
cache.remove(project);
|
||||
return;
|
||||
}
|
||||
fileMap.forEach((file, lineMap) -> lineMap.forEach((lineNumber, lineCache) -> {
|
||||
@NotNull LineInfo info = lineCache.info;
|
||||
@Nullable List<LineExtensionInfo> list = lineCache.map.get(info.text);
|
||||
if (!(lineCache.needUpdate() || list == null)) {
|
||||
return;
|
||||
}
|
||||
fileMap.forEach((file, lineMap) -> lineMap.forEach((lineNumber, lineCache) -> {
|
||||
@NotNull LineInfo info = lineCache.info;
|
||||
@Nullable List<LineExtensionInfo> list = lineCache.map.get(info.text);
|
||||
if (!(lineCache.needUpdate() || list == null)) {
|
||||
try {
|
||||
if (project.isDisposed() || DumbService.isDumb(project)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (project.isDisposed() || DumbService.isDumb(project)) {
|
||||
return;
|
||||
}
|
||||
@Nullable LineExtensionInfo lineExt = LineEnd.lineExt(info);
|
||||
@Nullable LineInfo info2 = LineInfo.of(info, lineNumber);
|
||||
if (info2 == null || !info2.text.equals(info.text)) {
|
||||
return;
|
||||
}
|
||||
@Nullable LineExtensionInfo lineExt = LineEnd.lineExt(info);
|
||||
@Nullable LineInfo info2 = LineInfo.of(info, lineNumber);
|
||||
if (info2 == null || !info2.text.equals(info.text)) {
|
||||
return;
|
||||
}
|
||||
if (list != null) {
|
||||
list.clear();
|
||||
}
|
||||
// fix delete line get doc from before line because PsiFile be not updated
|
||||
if ("}".equals(info.text.trim())) {
|
||||
return;
|
||||
}
|
||||
if (lineExt != null) {
|
||||
if (list != null) {
|
||||
list.clear();
|
||||
}
|
||||
// fix delete line get doc from before line because PsiFile be not updated
|
||||
if ("}".equals(info.text.trim())) {
|
||||
return;
|
||||
}
|
||||
if (lineExt != null) {
|
||||
if (list != null) {
|
||||
list.add(lineExt);
|
||||
} else {
|
||||
@NotNull ArrayList<LineExtensionInfo> lineExtList = new ArrayList<>(1);
|
||||
lineExtList.add(lineExt);
|
||||
lineCache.map.put(info.text, lineExtList);
|
||||
}
|
||||
}
|
||||
lineCache.updated();
|
||||
} catch (ProcessCanceledException ignore) {
|
||||
// ignore
|
||||
} catch (Throwable e) {
|
||||
@Nullable String msg = e.getMessage();
|
||||
if (msg == null || !msg.contains("File is not valid")) {
|
||||
LOG.info("LineEndCacheUtils lineMap.forEach catch Throwable but log to record.", e);
|
||||
list.add(lineExt);
|
||||
} else {
|
||||
@NotNull ArrayList<LineExtensionInfo> lineExtList = new ArrayList<>(1);
|
||||
lineExtList.add(lineExt);
|
||||
lineCache.map.put(info.text, lineExtList);
|
||||
}
|
||||
}
|
||||
}));
|
||||
} catch (ProcessCanceledException ignored) {
|
||||
} catch (IllegalStateException ignore) {
|
||||
// ignore inSmartMode(project) throw:
|
||||
// @NotNull method com/intellij/openapi/project/impl/ProjectImpl.getEarlyDisposable must not
|
||||
// return null
|
||||
} catch (Throwable e) {
|
||||
LOG.info("LineEndCacheUtils cache.forEach catch Throwable but log to record.", e);
|
||||
}
|
||||
}).inSmartMode(project).submit(AppExecutorUtil.getAppExecutorService());
|
||||
lineCache.updated();
|
||||
} catch (ProcessCanceledException ignore) {
|
||||
// ignore
|
||||
} catch (Throwable e) {
|
||||
@Nullable String msg = e.getMessage();
|
||||
if (msg == null || !msg.contains("File is not valid")) {
|
||||
LOG.info("LineEndCacheUtils lineMap.forEach catch Throwable but log to record.", e);
|
||||
}
|
||||
}
|
||||
}));
|
||||
} catch (ProcessCanceledException ignored) {
|
||||
} catch (IllegalStateException ignore) {
|
||||
// ignore inSmartMode(project) throw:
|
||||
// @NotNull method com/intellij/openapi/project/impl/ProjectImpl.getEarlyDisposable must not
|
||||
// return null
|
||||
} catch (Throwable e) {
|
||||
LOG.info("LineEndCacheUtils cache.forEach catch Throwable but log to record.", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,9 @@ public class TreeCacheUtils {
|
||||
isRun = true;
|
||||
AppExecutorUtil.getAppScheduledExecutorService().scheduleWithFixedDelay(() -> {
|
||||
try {
|
||||
cacheUpdate();
|
||||
ReadAction.nonBlocking(TreeCacheUtils::cacheUpdate)
|
||||
.inSmartMode(project)
|
||||
.submit(AppExecutorUtil.getAppExecutorService());
|
||||
} catch (Throwable e) {
|
||||
LOG.info("TreeCacheUtils checkScheduleAndInit catch Throwable but log to record.", e);
|
||||
}
|
||||
@@ -72,21 +74,20 @@ public class TreeCacheUtils {
|
||||
}
|
||||
nodeCache.forEach((node, treeCache) -> {
|
||||
if (treeCache.needUpdate) {
|
||||
ReadAction.nonBlocking(() -> {
|
||||
try {
|
||||
if (project.isDisposed() || DumbService.isDumb(project)) {
|
||||
return;
|
||||
}
|
||||
treeCache.doc = Tree.treeDoc(node, project);
|
||||
treeCache.needUpdate = false;
|
||||
} catch (ProcessCanceledException ignore) {
|
||||
// ignore
|
||||
} catch (Throwable e) {
|
||||
LOG.info("TreeCacheUtils nodeCache.forEach catch Throwable but log to record.", e);
|
||||
try {
|
||||
if (project.isDisposed() || DumbService.isDumb(project)) {
|
||||
return;
|
||||
}
|
||||
}).inSmartMode(project).executeSynchronously();
|
||||
treeCache.doc = Tree.treeDoc(node, project);
|
||||
treeCache.needUpdate = false;
|
||||
} catch (ProcessCanceledException ignore) {
|
||||
// ignore
|
||||
} catch (Throwable e) {
|
||||
LOG.info("TreeCacheUtils nodeCache.forEach catch Throwable but log to record.", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (ProcessCanceledException ignored) {
|
||||
} catch (IllegalStateException ignore) {
|
||||
// ignore inSmartMode(project) throw:
|
||||
// @NotNull method com/intellij/openapi/project/impl/ProjectImpl.getEarlyDisposable must not return null
|
||||
|
||||
Reference in New Issue
Block a user