<commit_before>package com.emberjs.index

import com.emberjs.project.EmberProjectComponent
import com.emberjs.resolver.EmberName
import com.emberjs.utils.guessProject
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Condition
import com.intellij.openapi.vfs.VfsUtil.isAncestor
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.util.CommonProcessors
import com.intellij.util.FilteringProcessor
import com.intellij.util.Processor
import com.intellij.util.indexing.*
import com.intellij.util.indexing.FileBasedIndex.ValueProcessor

class EmberNameIndex() : ScalarIndexExtension<EmberName>() {

    override fun getName() = NAME
    override fun getVersion() = 3
    override fun getKeyDescriptor() = EmberNameKeyDescriptor()
    override fun dependsOnFileContent() = false

    override fun getInputFilter() = FileBasedIndex.InputFilter { it.extension in FILE_EXTENSIONS }

    override fun getIndexer() = DataIndexer<EmberName, Void?, FileContent> { inputData ->
        val file = inputData.file
        val project = file.guessProject() ?: return@DataIndexer mapOf()
        val roots = EmberProjectComponent.getInstance(project)?.roots ?: return@DataIndexer mapOf()

        roots.filter { isAncestor(it, file, true) }
                .map { EmberName.from(it, file) }
                .filterNotNull()
                .associateBy({ it }, { null })
    }

    companion object {
        val NAME: ID<EmberName, Void> = ID.create("ember.names")
        private val FILE_EXTENSIONS = setOf("js", "hbs", "handlebars")

        private val index by lazy { FileBasedIndex.getInstance() }

        fun getAllKeys(project: Project): Collection<EmberName>
                = index.getAllKeys(NAME, project)

        fun processAllKeys(processor: Processor<EmberName>, scope: GlobalSearchScope, idFilter: IdFilter? = null)
                = index.processAllKeys(NAME, processor, scope, idFilter)
<commit_msg>index/EmberNameIndex: Use EmberName.from(file) with automatic root lookup<commit_after>package com.emberjs.index

import com.emberjs.resolver.EmberName
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Condition
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.util.CommonProcessors
import com.intellij.util.FilteringProcessor
import com.intellij.util.Processor
import com.intellij.util.indexing.*

class EmberNameIndex() : ScalarIndexExtension<EmberName>() {

    override fun getName() = NAME
    override fun getVersion() = 4
    override fun getKeyDescriptor() = EmberNameKeyDescriptor()
    override fun dependsOnFileContent() = false

    override fun getInputFilter() = FileBasedIndex.InputFilter { it.extension in FILE_EXTENSIONS }

    override fun getIndexer() = DataIndexer<EmberName, Void?, FileContent> { inputData ->
        EmberName.from(inputData.file)?.let { mapOf(it to null) } ?: emptyMap()
    }

    companion object {
        val NAME: ID<EmberName, Void> = ID.create("ember.names")
        private val FILE_EXTENSIONS = setOf("js", "hbs", "handlebars")

        private val index by lazy { FileBasedIndex.getInstance() }

        fun getAllKeys(project: Project): Collection<EmberName>
                = index.getAllKeys(NAME, project)

        fun processAllKeys(processor: Processor<EmberName>, scope: GlobalSearchScope, idFilter: IdFilter? = null)
                = index.processAllKeys(NAME, processor, scope, idFilter)

{'fraction_non_alphanumeric': 0.1003117030320204, 'fraction_numerical': 0.0005667327854916407, 'mean_word_length': 3.971830985915493, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '2269491', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1028, 'n_words': 223}