From ea331c49955c38b7124e5d588029f15741c2d590 Mon Sep 17 00:00:00 2001 From: "Andrei.Kuznetsov" Date: Tue, 30 May 2023 21:14:46 +0200 Subject: [PATCH] IDEA-320457: add support for FileTypeStrategy to FileTypeInputFilterPredicate and restore legacy behavior of ruby, html and json indexers behavior was unintentionally changed in one of the previous commits which migrated these indexers to indexing hint API. Originally these indexers were checking file type before substitution. After migration these indexers check file type after substitution. In most cases these file types are the same, so this change went unnoticed. Now (after this commit) these indexers check file type before substitution (as it was before migration). GitOrigin-RevId: 4e657675fba588df5d2cc8dac89f45c8c1d61c31 --- .../jsonSchema/impl/JsonSchemaFileValuesIndex.java | 4 +++- .../indexing/hints/FileTypeInputFilterPredicate.kt | 11 ++++++++++- .../com/intellij/htmltools/html/HtmlTagIdIndex.java | 4 +++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaFileValuesIndex.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaFileValuesIndex.java index f30c2e1906e7..28c191c213a4 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaFileValuesIndex.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaFileValuesIndex.java @@ -24,6 +24,8 @@ import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; +import static com.intellij.util.indexing.hints.BaseFileTypeInputFilter.FileTypeStrategy.BEFORE_SUBSTITUTION; + public class JsonSchemaFileValuesIndex extends FileBasedIndexExtension { public static final ID INDEX_ID = ID.create("json.file.root.values"); private static final int VERSION = 5; @@ -70,7 +72,7 @@ public class JsonSchemaFileValuesIndex extends FileBasedIndexExtension fileType instanceof JsonFileType); + return new FileTypeInputFilterPredicate(BEFORE_SUBSTITUTION, fileType -> fileType instanceof JsonFileType); } @Override diff --git a/platform/indexing-impl/src/com/intellij/util/indexing/hints/FileTypeInputFilterPredicate.kt b/platform/indexing-impl/src/com/intellij/util/indexing/hints/FileTypeInputFilterPredicate.kt index 8dcee136eb20..522cc967d67a 100644 --- a/platform/indexing-impl/src/com/intellij/util/indexing/hints/FileTypeInputFilterPredicate.kt +++ b/platform/indexing-impl/src/com/intellij/util/indexing/hints/FileTypeInputFilterPredicate.kt @@ -11,7 +11,16 @@ import org.jetbrains.annotations.ApiStatus * Returns `YES` or `NO` for given filetype predicate. Never returns `UNSURE`, therefore `acceptInput` is never invoked. */ @ApiStatus.Experimental -class FileTypeInputFilterPredicate(private val predicate: (filetype: FileType) -> Boolean) : BaseFileTypeInputFilter() { +class FileTypeInputFilterPredicate : BaseFileTypeInputFilter { + private val predicate: (filetype: FileType) -> Boolean + + constructor(predicate: (filetype: FileType) -> Boolean) : super() { + this.predicate = predicate + } + + constructor(fileTypeStrategy: FileTypeStrategy, predicate: (filetype: FileType) -> Boolean) : super(fileTypeStrategy) { + this.predicate = predicate + } constructor(vararg fileTypes: FileType) : this({ fileType -> fileTypes.contains(fileType) }) diff --git a/plugins/htmltools/src/com/intellij/htmltools/html/HtmlTagIdIndex.java b/plugins/htmltools/src/com/intellij/htmltools/html/HtmlTagIdIndex.java index 2e3fc5a6a014..0520dda5e1ec 100644 --- a/plugins/htmltools/src/com/intellij/htmltools/html/HtmlTagIdIndex.java +++ b/plugins/htmltools/src/com/intellij/htmltools/html/HtmlTagIdIndex.java @@ -24,6 +24,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import static com.intellij.util.indexing.hints.BaseFileTypeInputFilter.FileTypeStrategy.BEFORE_SUBSTITUTION; + public class HtmlTagIdIndex extends XmlIndex { public static final ID INDEX = ID.create("HtmlTagIdIndex"); @@ -36,7 +38,7 @@ public class HtmlTagIdIndex extends XmlIndex { @NotNull @Override public FileBasedIndex.InputFilter getInputFilter() { - return new BaseFileTypeInputFilter() { + return new BaseFileTypeInputFilter(BEFORE_SUBSTITUTION) { @Override public boolean whenAllOtherHintsUnsure(@NotNull IndexedFile file) { return file.getFile().isInLocalFileSystem();