fix: valid file and dir

This commit is contained in:
林万程
2025-09-13 09:44:58 +08:00
parent de46e38d45
commit 89f619b4b7
3 changed files with 49 additions and 35 deletions

View File

@@ -67,16 +67,20 @@ public class LineEndCacheUtils {
private static void cacheUpdate(Project project, Map<VirtualFile, Map<Integer, LineEndCache>> fileMap) { private static void cacheUpdate(Project project, Map<VirtualFile, Map<Integer, LineEndCache>> fileMap) {
try { try {
fileMap.forEach((file, lineMap) -> lineMap.forEach((lineNumber, lineCache) -> { if (project.isDisposed() || DumbService.isDumb(project)) {
return;
}
fileMap.forEach((file, lineMap) -> {
if (!file.isValid()) {
return;
}
lineMap.forEach((lineNumber, lineCache) -> {
@NotNull LineInfo info = lineCache.info; @NotNull LineInfo info = lineCache.info;
@Nullable List<LineExtensionInfo> list = lineCache.map.get(info.text); @Nullable List<LineExtensionInfo> list = lineCache.map.get(info.text);
if (!(lineCache.needUpdate() || list == null)) { if (!(lineCache.needUpdate() || list == null)) {
return; return;
} }
try { try {
if (project.isDisposed() || DumbService.isDumb(project) || !file.isValid()) {
return;
}
@Nullable LineExtensionInfo lineExt = LineEnd.lineExt(info); @Nullable LineExtensionInfo lineExt = LineEnd.lineExt(info);
@Nullable LineInfo info2 = LineInfo.of(info, lineNumber); @Nullable LineInfo info2 = LineInfo.of(info, lineNumber);
if (info2 == null || !info2.text.equals(info.text)) { if (info2 == null || !info2.text.equals(info.text)) {
@@ -106,7 +110,8 @@ public class LineEndCacheUtils {
LOG.info("LineEndCacheUtils lineMap.forEach catch Throwable but log to record.", e); LOG.info("LineEndCacheUtils lineMap.forEach catch Throwable but log to record.", e);
} }
} }
})); });
});
} catch (ProcessCanceledException ignored) { } catch (ProcessCanceledException ignored) {
} catch (IllegalStateException ignore) { } catch (IllegalStateException ignore) {
// ignore inSmartMode(project) throw: // ignore inSmartMode(project) throw:

View File

@@ -41,7 +41,7 @@ public class XmlLangDoc extends BaseLangDoc {
public @Nullable <T extends SettingsInfo> String treeDoc(@NotNull T info, @NotNull ProjectViewNode<?> node, public @Nullable <T extends SettingsInfo> String treeDoc(@NotNull T info, @NotNull ProjectViewNode<?> node,
@NotNull Project project) { @NotNull Project project) {
@Nullable VirtualFile virtualFile = node.getVirtualFile(); @Nullable VirtualFile virtualFile = node.getVirtualFile();
if (virtualFile == null) { if (virtualFile == null || virtualFile.isDirectory()) {
return null; return null;
} }
@Nullable FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(virtualFile); @Nullable FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(virtualFile);

View File

@@ -59,7 +59,13 @@ public abstract class BaseLangDoc extends EditorLinePainter {
if (viewProvider == null) { if (viewProvider == null) {
return null; return null;
} }
@Nullable PsiElement element = viewProvider.findElementAt(info.endOffset); @Nullable PsiElement element;
try {
element = viewProvider.findElementAt(info.endOffset);
} catch (Throwable ignored) {
// InvalidVirtualFileAccessException
return null;
}
if (element == null) { if (element == null) {
// file end // file end
element = viewProvider.findElementAt(info.endOffset - 1); element = viewProvider.findElementAt(info.endOffset - 1);
@@ -177,6 +183,9 @@ public abstract class BaseLangDoc extends EditorLinePainter {
public static @Nullable <T extends SettingsInfo> String resolveDoc(@NotNull T info, public static @Nullable <T extends SettingsInfo> String resolveDoc(@NotNull T info,
@NotNull PsiElement psiElement) { @NotNull PsiElement psiElement) {
try { try {
if (!psiElement.isValid()) {
return null;
}
// byte to src // byte to src
PsiElement navElement = psiElement.getNavigationElement(); PsiElement navElement = psiElement.getNavigationElement();
if (navElement != null) { if (navElement != null) {