Repository: hannah-sten/texify-idea
Issue: Autocompleting citeauthor includes natbib although biblatex is already included

<!-- **Note**: you can discard the template below if you are proposing a new feature. -->

#### Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version

PyCharm

#### Operating System 
<!--(Windows, Ubuntu, Arch Linux, MacOS, etc.)-->
Arch Linux

#### TeXiFy IDEA version

0.6.8

#### What I did (steps to reproduce)

```tex
\\documentclass[11pt]{article}

\\usepackage{biblatex}

\\begin{document}

\\citea % Autocomplete here!

\\end{document}
```

#### Expected behavior

Should not include natbib, because biblatex already provides the command, and natbib then, on compilation, conflicts with biblatex and has to be removed.

#### Actual behavior

```tex
\\documentclass[11pt]{article}

\\usepackage{biblatex}
\\usepackage{natbib}

\\begin{document}

\\citeauthor{}

\\end{document}
```

Changed files:
src/nl/hannahsten/texifyidea/lang/LatexCommand.kt, src/nl/hannahsten/texifyidea/gutter/LatexNavigationGutter.kt, src/nl/hannahsten/texifyidea/completion/TexifyCompletionContributor.kt, src/nl/hannahsten/texifyidea/inspections/latex/LatexAbsolutePathInspection.kt, src/nl/hannahsten/texifyidea/lang/LatexMathCommand.kt, src/nl/hannahsten/texifyidea/util/Magic.kt, src/nl/hannahsten/texifyidea/inspections/latex/LatexFileNotFoundInspection.kt, src/nl/hannahsten/texifyidea/inspections/LatexSpellcheckingStrategy.kt, src/nl/hannahsten/texifyidea/lang/LatexRegularCommand.kt, src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt, src/nl/hannahsten/texifyidea/inspections/latex/LatexUnicodeInspection.kt, src/nl/hannahsten/texifyidea/inspections/latex/LatexMissingImportInspection.kt, src/nl/hannahsten/texifyidea/util/Packages.kt, src/nl/hannahsten/texifyidea/folding/LatexMathSymbolFoldingBuilder.kt, src/nl/hannahsten/texifyidea/documentation/LatexDocumentationProvider.kt

diff --git a/src/nl/hannahsten/texifyidea/completion/TexifyCompletionContributor.kt b/src/nl/hannahsten/texifyidea/completion/TexifyCompletionContributor.kt
index a6cf5e182..cbc4ea420 100644
--- a/src/nl/hannahsten/texifyidea/completion/TexifyCompletionContributor.kt
+++ b/src/nl/hannahsten/texifyidea/completion/TexifyCompletionContributor.kt
@@ -91,7 +91,7 @@ open class TexifyCompletionContributor : CompletionContributor() {
                                 val name = command.commandToken.text
                                 val cmd = LatexRegularCommand[name.substring(1)] ?: return false
 
-                                val args = cmd.getArgumentsOf(RequiredFileArgument::class)
+                                val args = cmd.first().getArgumentsOf(RequiredFileArgument::class)
                                 if (args.isNotEmpty()) processingContext.put("type", args.first())
 
                                 return args.isNotEmpty()
@@ -114,7 +114,7 @@ open class TexifyCompletionContributor : CompletionContributor() {
                                 val name = command.commandToken.text
                                 val cmd = LatexRegularCommand[name.substring(1)] ?: return false
 
-                                val args = cmd.getArgumentsOf(RequiredFolderArgument::class)
+                                val args = cmd.first().getArgumentsOf(RequiredFolderArgument::class)
                                 if (args.isNotEmpty()) processingContext.put("type", args.first())
 
                                 return args.isNotEmpty()
@@ -137,7 +137,7 @@ open class TexifyCompletionContributor : CompletionContributor() {
                                 val name = command.commandToken.text
                                 val cmd = LatexRegularCommand[name.substring(1)] ?: return false
 
-                                val args = cmd.getArgumentsOf(RequiredPicturePathArgument::class)
+                                val args = cmd.first().getArgumentsOf(RequiredPicturePathArgument::class)
                                 if (args.isNotEmpty()) processingContext.put("type", args.first())
 
                                 return args.isNotEmpty()
diff --git a/src/nl/hannahsten/texifyidea/documentation/LatexDocumentationProvider.kt b/src/nl/hannahsten/texifyidea/documentation/LatexDocumentationProvider.kt
index 8c0a77b0b..307213b16 100644
--- a/src/nl/hannahsten/texifyidea/documentation/LatexDocumentationProvider.kt
+++ b/src/nl/hannahsten/texifyidea/documentation/LatexDocumentationProvider.kt
@@ -43,12 +43,12 @@ class LatexDocumentationProvider : DocumentationProvider {
         val command = LatexCommand.lookup(element) ?: return null
 
         // Special case for package inclusion commands
-        if (command.command in PACKAGE_COMMANDS) {
+        if (command.first().command in PACKAGE_COMMANDS) {
             val pkg = element.requiredParameters.getOrNull(0) ?: return null
             return runTexdoc(Package(pkg))
         }
 
-        return runTexdoc(command.dependency)
+        return runTexdoc(command.first().dependency)
     }
 
     override fun generateDoc(element: PsiElement, originalElement: PsiElement?): String? {
diff --git a/src/nl/hannahsten/texifyidea/folding/LatexMathSymbolFoldingBuilder.kt b/src/nl/hannahsten/texifyidea/folding/LatexMathSymbolFoldingBuilder.kt
index 5af51abf9..deb66b257 100644
--- a/src/nl/hannahsten/texifyidea/folding/LatexMathSymbolFoldingBuilder.kt
+++ b/src/nl/hannahsten/texifyidea/folding/LatexMathSymbolFoldingBuilder.kt
@@ -25,7 +25,7 @@ class LatexMathSymbolFoldingBuilder : FoldingBuilderEx() {
             val commands = mathEnvironment.childrenOfType(LatexCommands::class)
 
             for (command in commands) {
-                val display = LatexMathCommand[command.commandToken.text.substring(1)]?.display ?:continue
+                val display = LatexMathCommand[command.commandToken.text.substring(1)]?.first()?.display ?:continue
 
                 descriptors.add(object : FoldingDescriptor(command.commandToken.node, command.commandToken.textRange, group) {
                     override fun getPlaceholderText() = display
diff --git a/src/nl/hannahsten/texifyidea/gutter/LatexNavigationGutter.kt b/src/nl/hannahsten/texifyidea/gutter/LatexNavigationGutter.kt
index 360964e7c..d5d68795b 100644
--- a/src/nl/hannahsten/texifyidea/gutter/LatexNavigationGutter.kt
+++ b/src/nl/hannahsten/texifyidea/gutter/LatexNavigationGutter.kt
@@ -57,8 +57,8 @@ class LatexNavigationGutter : RelatedItemLineMarkerProvider() {
             return
         }
 
-        val arguments = commandHuh!!.getArgumentsOf(RequiredFileArgument::class.java)
-        if (arguments.isEmpty() && !ignoreFileArgument) {
+        val arguments = commandHuh?.firstOrNull()?.getArgumentsOf(RequiredFileArgument::class.java)
+        if (arguments?.isNullOrEmpty() == true && !ignoreFileArgument) {
             return
         }
 
diff --git a/src/nl/hannahsten/texifyidea/inspections/LatexSpellcheckingStrategy.kt b/src/nl/hannahsten/texifyidea/inspections/LatexSpellcheckingStrategy.kt
index ce4a987a2..bfe560d6c 100644
--- a/src/nl/hannahsten/texifyidea/inspections/LatexSpellcheckingStrategy.kt
+++ b/src/nl/hannahsten/texifyidea/inspections/LatexSpellcheckingStrategy.kt
@@ -73,11 +73,11 @@ class LatexSpellcheckingStrategy : SpellcheckingStrategy() {
     private fun getArguments(commandName: String): Array<out Argument>? {
         val cmdHuh = LatexRegularCommand[commandName]
         if (cmdHuh != null) {
-            return cmdHuh.arguments
+            return cmdHuh.first().arguments
         }
 
         val mathCmdHuh = LatexMathCommand[commandName] ?: return null
 
-        return mathCmdHuh.arguments
+        return mathCmdHuh.first().arguments
     }
 }
diff --git a/src/nl/hannahsten/texifyidea/inspections/latex/LatexAbsolutePathInspection.kt b/src/nl/hannahsten/texifyidea/inspections/latex/LatexAbsolutePathInspection.kt
index a677421c4..72c42a626 100644
--- a/src/nl/hannahsten/texifyidea/inspections/latex/LatexAbsolutePathInspection.kt
+++ b/src/nl/hannahsten/texifyidea/inspections/latex/LatexAbsolutePathInspection.kt
@@ -33,7 +33,7 @@ class LatexAbsolutePathInspection : TexifyInspectionBase() {
             val name = command.commandToken.text
             val cmd = LatexRegularCommand[name.substring(1)] ?: continue
 
-            val args = cmd.getArgumentsOf(RequiredFileArgument::class)
+            val args = cmd.first().getArgumentsOf(RequiredFileArgument::class)
             if (args.isEmpty()) continue
 
             val support = args.first().isAbsolutePathSupported
diff --git a/src/nl/hannahsten/texifyidea/inspections/latex/LatexFileNotFoundInspection.kt b/src/nl/hannahsten/texifyidea/inspections/latex/LatexFileNotFoundInspection.kt
index c3b0e5f3f..770b2169d 100644
--- a/src/nl/hannahsten/texifyidea/inspections/latex/LatexFileNotFoundInspection.kt
+++ b/src/nl/hannahsten/texifyidea/inspections/latex/LatexFileNotFoundInspection.kt
@@ -75,7 +75,7 @@ open class LatexFileNotFoundInspection : TexifyInspectionBase() {
             val default = LatexCommand.lookup(command.name) ?: continue
 
             // Remove optional arguments from list of commands
-            val arguments = default.arguments.mapNotNull { it as? RequiredArgument }
+            val arguments = default.first().arguments.mapNotNull { it as? RequiredArgument }
 
             // Remove optional parameters from list of parameters
             val parameters = command.parameterList.filter { it.requiredParam != null }
@@ -135,7 +135,7 @@ open class LatexFileNotFoundInspection : TexifyInspectionBase() {
             if (extension == "") {
                 val name = command.commandToken.text
                 LatexRegularCommand[name.substring(1)]?.apply {
-                    val args = this.getArgumentsOf(RequiredFileArgument::class)
+                    val args = this.first().getArgumentsOf(RequiredFileArgument::class)
                     if (args.isNotEmpty()) extension = args.first().defaultExtension
                 }
             }
diff --git a/src/nl/hannahsten/texifyidea/inspections/latex/LatexMissingImportInspection.kt b/src/nl/hannahsten/texifyidea/inspections/latex/LatexMissingImportInspection.kt
index 8de8cdc4c..da49c717d 100644
--- a/src/nl/hannahsten/texifyidea/inspections/latex/LatexMissingImportInspection.kt
+++ b/src/nl/hannahsten/texifyidea/inspections/latex/LatexMissingImportInspection.kt
@@ -4,6 +4,8 @@ import com.intellij.codeInspection.InspectionManager
 import com.intellij.codeInspection.LocalQuickFix
 import com.intellij.codeInspection.ProblemDescriptor
 import com.intellij.codeInspection.ProblemHighlightType
+import com.intellij.notification.Notification
+import com.intellij.notification.NotificationType
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.util.TextRange
 import com.intellij.psi.PsiFile
@@ -105,31 +107,36 @@ open class LatexMissingImportInspection : TexifyInspectionBase() {
         val commands = file.commandsInFile()
         for (command in commands) {
             val name = command.commandToken.text.substring(1)
-            val latexCommand = LatexCommand.lookup(name) ?: continue
-            val pack = latexCommand.dependency
+            val latexCommands = LatexCommand.lookup(name) ?: continue
 
-            if (pack.isDefault) {
-                continue
-            }
+            // In case there are multiple commands with this name, we don't know which one the user wants.
+            // So we don't know which of the dependencies the user needs: we assume that if at least one of them is present it will be the right one.
+            val dependencies = latexCommands.map { it.dependency }
 
-            // amsfonts is included in amssymb
-            if (pack == AMSFONTS && includedPackages.contains(AMSSYMB.name)) {
+            if (dependencies.isEmpty() || dependencies.any { it.isDefault }) {
                 continue
             }
 
-            // amsmath is included in mathtools
-            if (pack == AMSMATH && includedPackages.contains(MATHTOOLS.name)) {
-                continue
+            // Packages included in other packages
+            for (packageInclusion in Magic.Package.packagesLoadingOtherPackages) {
+                if (packageInclusion.value.intersect(dependencies.toSet()).isNotEmpty() && includedPackages.contains(packageInclusion.key.name)) {
+                    continue
+                }
             }
 
-            if (!includedPackages.contains(pack.name)) {
+            // If none of the dependencies are included
+            if (includedPackages.toSet().intersect(dependencies.map { it.name }).isEmpty()) {
+                // We know dependencies is not empty
+                val range = TextRange(0, latexCommands.minBy { it.command.length }!!.command.length + 1)
+                val dependencyNames = dependencies.joinToString { it.name }.replaceAfterLast(", ", "or ${dependencies.last().name}")
+                val fixes = dependencies.map { ImportCommandFix(it) }.toTypedArray()
                 descriptors.add(manager.createProblemDescriptor(
                         command,
-                        TextRange(0, latexCommand.command.length + 1),
-                        "Command requires ${pack.name} package",
+                        range,
+                        "Command requires $dependencyNames package",
                         ProblemHighlightType.ERROR,
                         isOntheFly,
-                        ImportCommandFix(pack.name)
+                        *fixes
                 ))
             }
         }
@@ -138,16 +145,17 @@ open class LatexMissingImportInspection : TexifyInspectionBase() {
     /**
      * @author Hannah Schellekens
      */
-    private class ImportCommandFix(val import: String) : LocalQuickFix {
+    private class ImportCommandFix(val pack: nl.hannahsten.texifyidea.lang.Package) : LocalQuickFix {
 
-        override fun getFamilyName() = "Add import for package '$import'"
+        override fun getFamilyName() = "Add import for package '${pack.name}'"
 
         override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
             val command = descriptor.psiElement as LatexCommands
-            val latexCommand = LatexCommand.lookup(command.commandToken.text) ?: return
             val file = command.containingFile
 
-            PackageUtils.insertUsepackage(file, latexCommand.dependency)
+            if (!PackageUtils.insertUsepackage(file, pack)) {
+                Notification("LatexMissingImportInspection", "Conflicting package detected", "The package ${pack.name} was not inserted because a conflicting package was detected.", NotificationType.INFORMATION).notify(project)
+            }
         }
     }
 
diff --git a/src/nl/hannahsten/texifyidea/inspections/latex/LatexUnicodeInspection.kt b/src/nl/hannahsten/texifyidea/inspections/latex/LatexUnicodeInspection.kt
index a8e1aa64f..7cadd3875 100644
--- a/src/nl/hannahsten/texifyidea/inspections/latex/LatexUnicodeInspection.kt
+++ b/src/nl/hannahsten/texifyidea/inspections/latex/LatexUnicodeInspection.kt
@@ -200,10 +200,10 @@ class LatexUnicodeInspection : TexifyInspectionBase() {
             // Try to find in lookup for special command
             val replacement: String?
             val command: LatexCommand? = if (inMathMode) {
-                LatexMathCommand.findByDisplay(c)
+                LatexMathCommand.findByDisplay(c)?.firstOrNull()
             }
             else {
-                LatexRegularCommand.findByDisplay(c)
+                LatexRegularCommand.findByDisplay(c)?.firstOrNull()
             }
 
             // Replace with found command or with standard substitution
diff --git a/src/nl/hannahsten/texifyidea/lang/LatexCommand.kt b/src/nl/hannahsten/texifyidea/lang/LatexCommand.kt
index bec43d4e2..eff1f4dff 100644
--- a/src/nl/hannahsten/texifyidea/lang/LatexCommand.kt
+++ b/src/nl/hannahsten/texifyidea/lang/LatexCommand.kt
@@ -16,9 +16,9 @@ interface LatexCommand : Dependend {
          *
          * @param commandName
          *          The command name to look up. Can start with or without `\\`
-         * @return The found command, or `null` when the command doesn't exist.
+         * @return The found commands, or `null` when the command doesn't exist.
          */
-        fun lookup(commandName: String?): LatexCommand? {
+        fun lookup(commandName: String?): Set<LatexCommand>? {
             var result = commandName ?: return null
             if (result.startsWith("\\\\")) {
                 result = result.substring(1)
@@ -33,7 +33,7 @@ interface LatexCommand : Dependend {
          * @param command The command PSI element to look up. Takes into account whether it is placed in math mode.
          * @return The found command, or `null` when the command does not exist.
          */
-        fun lookup(command: LatexCommands): LatexCommand? {
+        fun lookup(command: LatexCommands): Set<LatexCommand>? {
             val name = command.commandToken.text
             val commandName = name.substring(1)
 
diff --git a/src/nl/hannahsten/texifyidea/lang/LatexMathCommand.kt b/src/nl/hannahsten/texifyidea/lang/LatexMathCommand.kt
index e61ff7e4f..8d15ea12f 100644
--- a/src/nl/hannahsten/texifyidea/lang/LatexMathCommand.kt
+++ b/src/nl/hannahsten/texifyidea/lang/LatexMathCommand.kt
@@ -10,6 +10,7 @@ import nl.hannahsten.texifyidea.lang.Package.Companion.LATEXSYMB
 /**
  * @author Sten Wessel
  */
+@Suppress("unused")
 enum class LatexMathCommand(
         override val command: String,
         override vararg val arguments: Argument = emptyArray(),
@@ -347,22 +348,22 @@ enum class LatexMathCommand(
 
     companion object {
 
-        private val lookup = HashMap<String, LatexMathCommand>()
-        private val lookupDisplay = HashMap<String, LatexMathCommand>()
+        private val lookup = HashMap<String, MutableSet<LatexMathCommand>>()
+        private val lookupDisplay = HashMap<String, MutableSet<LatexMathCommand>>()
 
         init {
             for (command in values()) {
-                lookup[command.command] = command
+                lookup.getOrPut(command.command) { mutableSetOf() }.add(command)
                 if (command.display != null) {
-                    lookupDisplay.putIfAbsent(command.display!!, command)
+                    lookupDisplay.putIfAbsent(command.display!!, mutableSetOf(command))?.add(command)
                 }
             }
         }
 
         @JvmStatic
-        operator fun get(command: String) = lookup[command]
+        operator fun get(command: String) = lookup[command]?.toSet()
 
         @JvmStatic
-        fun findByDisplay(display: String) = lookupDisplay[display]
+        fun findByDisplay(display: String) = lookupDisplay[display]?.toSet()
     }
 }
\\ No newline at end of file
diff --git a/src/nl/hannahsten/texifyidea/lang/LatexRegularCommand.kt b/src/nl/hannahsten/texifyidea/lang/LatexRegularCommand.kt
index 9d079f227..73439b025 100644
--- a/src/nl/hannahsten/texifyidea/lang/LatexRegularCommand.kt
+++ b/src/nl/hannahsten/texifyidea/lang/LatexRegularCommand.kt
@@ -420,23 +420,23 @@ enum class LatexRegularCommand(
 
     companion object {
 
-        private val lookup = HashMap<String, LatexRegularCommand>()
-        private val lookupDisplay = HashMap<String, LatexRegularCommand>()
+        private val lookup = HashMap<String, MutableSet<LatexRegularCommand>>()
+        private val lookupDisplay = HashMap<String, MutableSet<LatexRegularCommand>>()
 
         init {
             @Suppress("RemoveRedundantQualifierName")
             for (command in LatexRegularCommand.values()) {
-                lookup[command.command] = command
+                lookup.getOrPut(command.command) { mutableSetOf() }.add(command)
                 if (command.display != null) {
-                    lookupDisplay.putIfAbsent(command.display!!, command)
+                    lookupDisplay.putIfAbsent(command.display!!, mutableSetOf(command))?.add(command)
                 }
             }
         }
 
         @JvmStatic
-        operator fun get(command: String) = lookup[command]
+        operator fun get(command: String) = lookup[command]?.toSet()
 
         @JvmStatic
-        fun findByDisplay(display: String) = lookupDisplay[display]
+        fun findByDisplay(display: String) = lookupDisplay[display]?.toSet()
     }
 }
diff --git a/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt b/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt
index 98285151b..048ec6a79 100644
--- a/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt
+++ b/src/nl/hannahsten/texifyidea/structure/latex/LatexStructureViewElement.kt
@@ -180,8 +180,7 @@ class LatexStructureViewElement(private val element: PsiElement) : StructureView
 
             // Find file
             val latexCommandHuh = LatexRegularCommand[name.substring(1)] ?: continue
-            val argument = latexCommandHuh
-                    .getArgumentsOf(RequiredFileArgument::class.java)[0]
+            val argument = latexCommandHuh.first().getArgumentsOf(RequiredFileArgument::class.java)[0]
 
             val fileNames = cmd.includedFileNames() ?: continue
             val containingFile = element.containingFile
diff --git a/src/nl/hannahsten/texifyidea/util/Magic.kt b/src/nl/hannahsten/texifyidea/util/Magic.kt
index a055312a0..31c7fa838 100644
--- a/src/nl/hannahsten/texifyidea/util/Magic.kt
+++ b/src/nl/hannahsten/texifyidea/util/Magic.kt
@@ -6,6 +6,12 @@ import nl.hannahsten.texifyidea.TexifyIcons
 import nl.hannahsten.texifyidea.file.*
 import nl.hannahsten.texifyidea.inspections.latex.LatexLineBreakInspection
 import nl.hannahsten.texifyidea.lang.Package
+import nl.hannahsten.texifyidea.lang.Package.Companion.AMSFONTS
+import nl.hannahsten.texifyidea.lang.Package.Companion.AMSMATH
+import nl.hannahsten.texifyidea.lang.Package.Companion.AMSSYMB
+import nl.hannahsten.texifyidea.lang.Package.Companion.BIBLATEX
+import nl.hannahsten.texifyidea.lang.Package.Companion.MATHTOOLS
+import nl.hannahsten.texifyidea.lang.Package.Companion.NATBIB
 import org.intellij.lang.annotations.Language
 import java.awt.Color
 import java.util.regex.Pattern
@@ -669,6 +675,21 @@ object Magic {
         val index = hashSetOf(
                 "makeidx", "multind", "index", "splitidx", "splitindex", "imakeidx", "hvindex", "idxlayout", "repeatindex", "indextools"
         )
+
+        /**
+         * Known conflicting packages.
+         */
+        val conflictingPackages = listOf(
+                setOf(BIBLATEX, NATBIB)
+        )
+
+        /**
+         * Maps packages to the packages it loads.
+         */
+        val packagesLoadingOtherPackages = mapOf(
+                AMSSYMB to setOf(AMSFONTS),
+                MATHTOOLS to setOf(AMSMATH)
+        )
     }
 
     /**
diff --git a/src/nl/hannahsten/texifyidea/util/Packages.kt b/src/nl/hannahsten/texifyidea/util/Packages.kt
index cd3ae42dc..ff2981b64 100644
--- a/src/nl/hannahsten/texifyidea/util/Packages.kt
+++ b/src/nl/hannahsten/texifyidea/util/Packages.kt
@@ -104,31 +104,43 @@ object PackageUtils {
 
     /**
      * Inserts a usepackage statement for the given package in the root file of the fileset containing the given file.
-     * Will not insert a new statement when the package has already been included.
+     * Will not insert a new statement when the package has already been included, or when a conflicting package is already included.
      *
-     * @param file
-     *         The file to add the usepackage statement to.
-     * @param pack
-     *          The package to include.
+     * @param file The file to add the usepackage statement to.
+     * @param pack The package to include.
+     *
+     * @return false if the package was not inserted, because a conflicting package is already present.
      */
     @JvmStatic
-    fun insertUsepackage(file: PsiFile, pack: Package) {
+    fun insertUsepackage(file: PsiFile, pack: Package): Boolean {
         if (pack.isDefault) {
-            return
+            return true
         }
 
         if (file.includedPackages().contains(pack.name)) {
-            return
+            return true
+        }
+
+        // Don't insert when a conflicting package is already present
+        if (Magic.Package.conflictingPackages.any { it.contains(pack) }) {
+            for (conflicts in Magic.Package.conflictingPackages) {
+                // Assuming the package is not already included
+                if (conflicts.contains(pack) && file.includedPackages().toSet().intersect(conflicts.map {it.name }).isNotEmpty()) {
+                    return false
+                }
+            }
         }
 
         // Packages should always be included in the root file
         val rootFile = file.findRootFile()
 
-        val document = rootFile.document() ?: return
+        val document = rootFile.document() ?: return true
 
         val params = pack.parameters
         val parameterString = StringUtil.join(params, ",")
         insertUsepackage(document, rootFile, pack.name, parameterString)
+
+        return true
     }
 
     /**