<commit_before>package org.purescript.file

import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiManager
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.util.indexing.*
import com.intellij.util.io.EnumeratorStringDescriptor
import org.purescript.psi.PSForeignDataDeclaration
import org.purescript.psi.data.PSDataDeclaration
import org.purescript.psi.newtype.PSNewTypeDeclarationImpl
import org.purescript.psi.typesynonym.PSTypeSynonymDeclaration

/**
 * An index on what type declarations every module exports.
 * The index contains the following declarations:
 *  - [PSTypeSynonymDeclaration]
 *  - [PSDataDeclaration]
 *  - [PSNewTypeDeclarationImpl]
 *  - [PSForeignDataDeclaration]
 */
class ExportedTypesIndex : ScalarIndexExtension<String>(), DataIndexer<String, Void?, FileContent> {

    override fun map(inputData: FileContent): Map<String, Void?> {
        val file = inputData.psiFile as? PSFile ?: return emptyMap()
        val module = file.module ?: return emptyMap()
        val exportedNames = mutableSetOf<String>()
        module.exportedTypeSynonymDeclarations.mapTo(exportedNames) { it.name }
        module.exportedDataDeclarations.mapTo(exportedNames) { it.name }
        module.exportedNewTypeDeclarations.mapTo(exportedNames) { it.name }
        module.exportedForeignDataDeclarations.mapTo(exportedNames) { it.name }
        return exportedNames.associateWith { null }
    }

    override fun getName(): ID<String, Void?> = NAME

    override fun getIndexer() = this

    override fun getKeyDescriptor(): EnumeratorStringDescriptor =
        EnumeratorStringDescriptor.INSTANCE

    override fun getVersion() = 1

    override fun getInputFilter() =
        DefaultFileTypeSpecificInputFilter(PSFileType.INSTANCE)
<commit_msg>Change ExportedTypesIndex to not access other files while indexing<commit_after>package org.purescript.file

import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiManager
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.util.indexing.*
import com.intellij.util.io.EnumeratorStringDescriptor
import org.purescript.psi.PSForeignDataDeclaration
import org.purescript.psi.data.PSDataDeclaration
import org.purescript.psi.exports.PSExportedData
import org.purescript.psi.newtype.PSNewTypeDeclarationImpl
import org.purescript.psi.typesynonym.PSTypeSynonymDeclaration

/**
 * An index on what type declarations every module exports.
 * The index contains the following declarations:
 *  - [PSTypeSynonymDeclaration]
 *  - [PSDataDeclaration]
 *  - [PSNewTypeDeclarationImpl]
 *  - [PSForeignDataDeclaration]
 */
class ExportedTypesIndex : ScalarIndexExtension<String>(), DataIndexer<String, Void?, FileContent> {

    override fun map(inputData: FileContent): Map<String, Void?> {
        val file = inputData.psiFile as? PSFile ?: return emptyMap()
        val module = file.module ?: return emptyMap()
        val exportList = module.exportList
        return if (exportList == null) {
            val exportedNames = mutableSetOf<String>()
            module.typeSynonymDeclarations.mapTo(exportedNames) { it.name }
            module.dataDeclarations.mapTo(exportedNames) { it.name }
            module.newTypeDeclarations.mapTo(exportedNames) { it.name }
            module.foreignDataDeclarations.mapTo(exportedNames) { it.name }
            exportedNames.associateWith { null }
        } else {
            exportList.exportedItems
                .filterIsInstance<PSExportedData>()
                .associate { it.name to null }
        }
    }

    override fun getName(): ID<String, Void?> = NAME

    override fun getIndexer() = this

    override fun getKeyDescriptor(): EnumeratorStringDescriptor =
        EnumeratorStringDescriptor.INSTANCE

    override fun getVersion() = 1

    override fun getInputFilter() =
        DefaultFileTypeSpecificInputFilter(PSFileType.INSTANCE)

{'fraction_non_alphanumeric': 0.08814741035856574, 'fraction_numerical': 0.00049800796812749, 'mean_word_length': 4.027534418022528, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '5559859', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1128, 'n_words': 227}