<commit_before>/*
 * Use of this source code is governed by the MIT license that can be
 * found in the LICENSE file.
 */

package org.rust.lang.core.stubs.index

import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.IndexSink
import com.intellij.psi.stubs.StringStubIndexExtension
import com.intellij.psi.stubs.StubIndexKey
import org.rust.lang.core.psi.RsUseItem
import org.rust.lang.core.psi.RsUseSpeck
import org.rust.lang.core.psi.ext.ancestorStrict
import org.rust.lang.core.psi.ext.isPublic
import org.rust.lang.core.psi.ext.nameInScope
import org.rust.lang.core.psi.ext.pathOrQualifier
import org.rust.lang.core.stubs.RsFileStub
import org.rust.lang.core.stubs.RsUseSpeckStub
import org.rust.openapiext.getElements

class RsReexportIndex : StringStubIndexExtension<RsUseSpeck>() {
    override fun getVersion(): Int = RsFileStub.Type.stubVersion
    override fun getKey(): StubIndexKey<String, RsUseSpeck> = KEY

    companion object {
        val KEY: StubIndexKey<String, RsUseSpeck> =
            StubIndexKey.createIndexKey("org.rust.lang.core.stubs.index.RsReexportIndex")

        fun index(stub: RsUseSpeckStub, sink: IndexSink) {
            val useSpeck = stub.psi
            val isPublic = useSpeck.ancestorStrict<RsUseItem>()?.isPublic == true
            if (!isPublic) return
            val name = if (stub.isStarImport) {
                useSpeck.pathOrQualifier?.referenceName
            } else {
                useSpeck.nameInScope
            } ?: return
            sink.occurrence(KEY, name)
        }

        fun findReexportsByName(
            project: Project,
            target: String,
            scope: GlobalSearchScope = GlobalSearchScope.allScope(project)
        ): Collection<RsUseSpeck> = getElements(KEY, target, project, scope)
    }
}<commit_msg>Fixes IndexNotReadyException during indexing #3545<commit_after>/*
 * Use of this source code is governed by the MIT license that can be
 * found in the LICENSE file.
 */

package org.rust.lang.core.stubs.index

import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.IndexSink
import com.intellij.psi.stubs.StringStubIndexExtension
import com.intellij.psi.stubs.StubIndexKey
import org.rust.lang.core.psi.RsUseItem
import org.rust.lang.core.psi.RsUseSpeck
import org.rust.lang.core.psi.ext.ancestorStrict
import org.rust.lang.core.psi.ext.nameInScope
import org.rust.lang.core.psi.ext.pathOrQualifier
import org.rust.lang.core.stubs.RsFileStub
import org.rust.lang.core.stubs.RsUseSpeckStub
import org.rust.openapiext.getElements

class RsReexportIndex : StringStubIndexExtension<RsUseSpeck>() {
    override fun getVersion(): Int = RsFileStub.Type.stubVersion
    override fun getKey(): StubIndexKey<String, RsUseSpeck> = KEY

    companion object {
        val KEY: StubIndexKey<String, RsUseSpeck> =
            StubIndexKey.createIndexKey("org.rust.lang.core.stubs.index.RsReexportIndex")

        fun index(stub: RsUseSpeckStub, sink: IndexSink) {
            val useSpeck = stub.psi
            val isPublic = useSpeck.ancestorStrict<RsUseItem>()?.vis != null
            if (!isPublic) return
            val name = if (stub.isStarImport) {
                useSpeck.pathOrQualifier?.referenceName
            } else {
                useSpeck.nameInScope
            } ?: return
            sink.occurrence(KEY, name)
        }

        fun findReexportsByName(
            project: Project,
            target: String,
            scope: GlobalSearchScope = GlobalSearchScope.allScope(project)
        ): Collection<RsUseSpeck> = getElements(KEY, target, project, scope)
    }
}
{'fraction_non_alphanumeric': 0.09545576767948373, 'fraction_numerical': 0.0010755579456843238, 'mean_word_length': 3.092409240924092, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3750521', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1166, 'n_words': 222}