How should I use the PrebuiltStubsProvider extension?
In the official plug-in document of IDEA(SDK), prebuild is introduced to improve index efficiency by rewriting the findtub method. Currently, my idea is to use a disk-based persistentHashMap to save the SerializedStubTree returned by the findtub method. The next time you open the same project, you can directly obtain it from the map without rebuilding it.But now I'm running into a couple of problems.
First, I use persistentHashMap to save the created SerializedStubTree to the specified disk location. The key in the map is empty when I open it again.
Second, for the same project in different project paths, the key value of getFileId of VirtualFile varies according to the location, even if they are the same file.
What I'd like to ask for help is whether there is a demo of the PrebuiltStubsProvider extension point for reference today, and how to get the specified key value for the file content. Here's my code
public SerializedStubTree findStub(@NotNull FileContent fileContent) {
VirtualFile file = fileContent.getFile();
try {
final File f1 = new File("D:\\preindex\\Stubs.storage");
map1 = new PersistentHashMap<String, SerializedStubTree>(f1.toPath(),EnumeratorStringDescriptor.INSTANCE,
getValueExternalizer1(), 4096);
int key = file instanceof LightVirtualFile ? -1 : Math.abs(FileBasedIndex.getFileId(file));
if(map1.get(key+"")!=null) {
return map1.get(file.getName());
}else{
Stub stub = StubTreeBuilder.buildStubTree(fileContent);
SerializedStubTree stubTree = SerializedStubTree.serializeStub(stub, new SerializationManagerImpl(f1.toPath(), false),
StubForwardIndexExternalizer.createFileLocalExternalizer());
map1.put(key+"", stubTree);
return stubTree;
}
} catch (IOException e) {
e.printStackTrace();
}
//StubForwardIndexExternalizer.createFileLocalExternalizer();
return null;
}
In addition, when I save the map and open it again, the following error message is displayed:
com.intellij.util.io.PersistentEnumeratorBase$VersionUpdatedException: PersistentEnumerator storage corrupted D:\preindex\Stubs.storage
at com.intellij.util.io.PersistentEnumeratorBase.<init>(PersistentEnumeratorBase.java:227)
at com.intellij.util.io.PersistentBTreeEnumerator.<init>(PersistentBTreeEnumerator.java:73)
at com.intellij.util.io.PersistentEnumeratorDelegate.createDefaultEnumerator(PersistentEnumeratorDelegate.java:69)
at com.intellij.util.io.PersistentHashMap.<init>(PersistentHashMap.java:164)
at com.intellij.util.io.PersistentHashMap.<init>(PersistentHashMap.java:149)
It is likely that the bottom layer of the persistentHashMap is not correctly saved. I hope to get the guidance of the experienced big guy. Thank you very much.
帖子评论已关闭。
please do not crosspost between issue tracker and forum