<commit_before>package nl.rubensten.texifyidea.run

import com.intellij.execution.Location
import com.intellij.execution.actions.ConfigurationContext
import com.intellij.execution.actions.RunConfigurationProducer
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.util.Ref
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import nl.rubensten.texifyidea.file.LatexFileType
import nl.rubensten.texifyidea.util.hasBibliography

/**
 * @author <NAME>
 */
class LatexRunConfigurationProducer : RunConfigurationProducer<LatexRunConfiguration>(LatexRunConfigurationType.instance) {

    override fun setupConfigurationFromContext(runConfiguration: LatexRunConfiguration,
                                               context: ConfigurationContext,
                                               sourceElement: Ref<PsiElement>): Boolean {
        val location = context.location ?: return false
        val container = getEntryPointContainer(location) ?: return false
        val mainFile = container.virtualFile ?: return false

        // Only activate on .tex files.
        val extension = mainFile.extension
        val texTension = LatexFileType.defaultExtension
        if (extension == null || !extension.equals(texTension, ignoreCase = true)) {
            return false
        }

        // Setup run configuration.
        runConfiguration.mainFile = mainFile
        runConfiguration.setDefaultAuxiliaryDirectories()
        runConfiguration.setDefaultCompiler()
        runConfiguration.setDefaultOutputFormat()
        runConfiguration.setSuggestedName()

        if (container.hasBibliography()) {
            runConfiguration.generateBibRunConfig()
        }

        return true
    }

    private fun getEntryPointContainer(location: Location<*>?): PsiFile? {
        if (location == null) {
            return null
        }

        val locationElement = location.psiElement
        return locationElement.containingFile
    }

    override fun isConfigurationFromContext(runConfiguration: LatexRunConfiguration,
                                            context: ConfigurationContext): Boolean {
        val mainFile = runConfiguration.mainFile
        val psiFile = context.dataContext.getData(PlatformDataKeys.PSI_FILE) ?: return false

        val currentFile = psiFile.virtualFile

        return mainFile.path == currentFile.path
    }
}<commit_msg>Fixed #466.<commit_after>package nl.rubensten.texifyidea.run

import com.intellij.execution.Location
import com.intellij.execution.actions.ConfigurationContext
import com.intellij.execution.actions.RunConfigurationProducer
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.util.Ref
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import nl.rubensten.texifyidea.file.LatexFileType
import nl.rubensten.texifyidea.util.hasBibliography

/**
 * @author <NAME>
 */
class LatexRunConfigurationProducer : RunConfigurationProducer<LatexRunConfiguration>(LatexRunConfigurationType.instance) {

    override fun setupConfigurationFromContext(runConfiguration: LatexRunConfiguration,
                                               context: ConfigurationContext,
                                               sourceElement: Ref<PsiElement>): Boolean {
        val location = context.location ?: return false
        val container = getEntryPointContainer(location) ?: return false
        val mainFile = container.virtualFile ?: return false

        // Only activate on .tex files.
        val extension = mainFile.extension
        val texTension = LatexFileType.defaultExtension
        if (extension == null || !extension.equals(texTension, ignoreCase = true)) {
            return false
        }

        // Setup run configuration.
        runConfiguration.mainFile = mainFile
        runConfiguration.setDefaultAuxiliaryDirectories()
        runConfiguration.setDefaultCompiler()
        runConfiguration.setDefaultOutputFormat()
        runConfiguration.setSuggestedName()

        if (container.hasBibliography()) {
            runConfiguration.generateBibRunConfig()
        }

        return true
    }

    private fun getEntryPointContainer(location: Location<*>?): PsiFile? {
        if (location == null) {
            return null
        }

        val locationElement = location.psiElement
        return locationElement.containingFile
    }

    override fun isConfigurationFromContext(runConfiguration: LatexRunConfiguration,
                                            context: ConfigurationContext): Boolean {
        val mainFile = runConfiguration.mainFile
        val psiFile = context.dataContext.getData(PlatformDataKeys.PSI_FILE) ?: return false
        val currentFile = psiFile.virtualFile ?: return false
        return mainFile?.path == currentFile.path
    }
}
{'fraction_non_alphanumeric': 0.07264869314673801, 'fraction_numerical': 0.0006174109899156205, 'mean_word_length': 2.814756671899529, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1462841', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1149, 'n_words': 239}