Proved a diagnostics for prebuilt stubs in case of stub/AST mismatch

This commit is contained in:
Dmitry Trofimov
2017-10-16 17:17:37 +02:00
parent 34244fb735
commit a1e4cc8961
3 changed files with 32 additions and 0 deletions
@@ -28,6 +28,7 @@ import com.intellij.psi.tree.IStubFileElementType;
import com.intellij.util.indexing.FileContent;
import com.intellij.util.indexing.FileContentImpl;
import com.intellij.util.indexing.IndexingDataKeys;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
@@ -83,4 +84,8 @@ public class CoreStubTreeLoader extends StubTreeLoader {
return false;
}
@Override
protected boolean isPrebuilt(@NotNull VirtualFile virtualFile) {
return false;
}
}
@@ -77,7 +77,14 @@ public abstract class StubTreeLoader {
IndexingStampInfo indexingStampInfo = getIndexingStampInfo(file);
boolean upToDate = indexingStampInfo != null && indexingStampInfo.isUpToDate(document, file, psiFile);
boolean canBePrebuilt = isPrebuilt(psiFile.getVirtualFile());
String msg = _message + "\nPlease report the problem to JetBrains with the files attached\n";
if (canBePrebuilt) {
msg += "This stub can have pre-built origin\n";
}
if (upToDate) {
msg += "INDEXED VERSION IS THE CURRENT ONE";
}
@@ -136,6 +143,8 @@ public abstract class StubTreeLoader {
return upToDate ? handleUpToDateMismatch(msg, attachments) : new RuntimeExceptionWithAttachments(msg, attachments);
}
protected abstract boolean isPrebuilt(@NotNull VirtualFile virtualFile);
private static UpToDateStubIndexMismatch handleUpToDateMismatch(@NotNull String message, Attachment[] attachments) {
return new UpToDateStubIndexMismatch(message, attachments);
}
@@ -247,4 +247,22 @@ public class StubTreeLoaderImpl extends StubTreeLoader {
protected IndexingStampInfo getIndexingStampInfo(@NotNull VirtualFile file) {
return StubUpdatingIndex.getIndexingStampInfo(file);
}
@Override
protected boolean isPrebuilt(@NotNull VirtualFile virtualFile) {
boolean canBePrebuilt = false;
try {
final PrebuiltStubsProvider prebuiltStubsProvider =
PrebuiltStubsProviders.INSTANCE.forFileType(virtualFile.getFileType());
if (prebuiltStubsProvider != null) {
canBePrebuilt = null !=
prebuiltStubsProvider
.findStub(new FileContentImpl(virtualFile, virtualFile.contentsToByteArray()));
}
}
catch (Exception e) {
// pass
}
return canBePrebuilt;
}
}