shared index: add api to notify on index version changed

GitOrigin-RevId: 12cb1d2d06dfbad1d75455ce93c39cf9fd9d29eb
This commit is contained in:
Dmitro Batko
2020-03-10 08:32:39 +00:00
committed by intellij-monorepo-bot
parent b7a7b777ec
commit ff9322dd60
3 changed files with 40 additions and 0 deletions
@@ -188,6 +188,17 @@ public final class StubIndexImpl extends StubIndexEx implements PersistentStateC
else registrationResultSink.registerIndexAsInitiallyBuilt(indexKey);
if (indexRootHasChildren) FileUtil.deleteWithRenaming(indexRootDir);
IndexingStamp.rewriteVersion(indexKey, version); // todo snapshots indices
try {
if (needRebuild) {
for (FileBasedIndexInfrastructureExtension ex : FileBasedIndexInfrastructureExtension.EP_NAME.getExtensionList()) {
ex.onStubIndexVersionChanged(indexKey);
}
}
} catch (Exception e) {
LOG.error(e);
}
} else {
registrationResultSink.registerIndexAsUptoDate(indexKey);
}
@@ -333,6 +333,17 @@ public final class FileBasedIndexImpl extends FileBasedIndexEx {
File rootDir = IndexInfrastructure.getIndexRootDir(name);
if (versionFileExisted) FileUtil.deleteWithRenaming(rootDir);
IndexingStamp.rewriteVersion(name, version);
try {
if (versionFileExisted) {
for (FileBasedIndexInfrastructureExtension ex : FileBasedIndexInfrastructureExtension.EP_NAME.getExtensionList()) {
ex.onFileBasedIndexVersionChanged(name);
}
}
} catch (Exception e) {
LOG.error(e);
}
} else {
registrationStatusSink.registerIndexAsUptoDate(name);
}
@@ -6,6 +6,7 @@ import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.stubs.StubIndexKey;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -49,6 +50,23 @@ public interface FileBasedIndexInfrastructureExtension {
@NotNull UpdatableIndex<K, V, FileContent> baseIndex);
/**
* Notifies the extension to handle that version of existing file based index version has been changed.
*
* Actually {@link FileBasedIndex} notifies even if index composite version (extension version + implementation version)
* is changed {@link FileBasedIndexImpl#getIndexExtensionVersion(FileBasedIndexExtension)}.
*
* @param indexId that version is updated.
*/
void onFileBasedIndexVersionChanged(@NotNull ID<?, ?> indexId);
/**
* Notifies the extension to handle that version of existing stub index has been changed.
*
* @param indexId that version is updated.
*/
void onStubIndexVersionChanged(@NotNull StubIndexKey<?, ?> indexId);
/**
* Executed when IntelliJ is shutting down it's indexes (IDE shutdown or plugin load/unload). It is the best time
* for the component to flush it's state to the disk and close all pending connections.