Repository: hannah-sten/texify-idea
Issue: "Bad request: Your request URL is too long" when reporting error to TeXiFy-IDEA issue tracker

#### Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version

IntelliJ IDEA 2021.1.1 (#IU-211.7142.13)

#### Operating System 

Ubuntu

#### TeXiFy IDEA version

`0.7.5`

#### What I did (steps to reproduce)

Generate error and clicked `Report to TeXiFy-IDEA issue tracker`.

#### Minimal example to reproduce the problem

See below.

#### Expected behavior

Opens [new issue page](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/new/choose) with template populated.

#### Actual behavior

GitHub responds with "Bad request: Your request URL is too long."

#### (if applicable) The full stacktrace of the exception thrown

<details>

```
com.intellij.diagnostic.PluginException: Failed to build stub tree for research_proposal.tex [Plugin: nl.rubensten.texifyidea]
	at com.intellij.ide.plugins.PluginManagerCore.createPluginException(PluginManagerCore.java:300)
	at com.intellij.diagnostic.PluginProblemReporterImpl.createPluginExceptionByClass(PluginProblemReporterImpl.java:12)
	at com.intellij.diagnostic.PluginException.createByClass(PluginException.java:81)
	at com.intellij.psi.stubs.StubTreeBuilder.handleStubBuilderException(StubTreeBuilder.java:99)
	at com.intellij.psi.stubs.StubTreeBuilder.buildStubTree(StubTreeBuilder.java:140)
	at com.intellij.psi.stubs.StubUpdatingIndex$1.computeValue(StubUpdatingIndex.java:165)
	at com.intellij.psi.stubs.StubUpdatingIndex$1.computeValue(StubUpdatingIndex.java:142)
	at com.intellij.psi.stubs.StubUpdatingIndex$1.computeValue(StubUpdatingIndex.java:109)
	at com.intellij.util.indexing.SingleEntryIndexer.map(SingleEntryIndexer.java:30)
	at com.intellij.util.indexing.SingleEntryIndexer.map(SingleEntryIndexer.java:19)
	at com.intellij.util.indexing.impl.MapReduceIndex.mapByIndexer(MapReduceIndex.java:315)
	at com.intellij.util.indexing.impl.MapReduceIndex.mapInput(MapReduceIndex.java:305)
	at com.intellij.util.indexing.impl.storage.VfsAwareMapReduceIndex.mapInput(VfsAwareMapReduceIndex.java:168)
	at com.intellij.util.indexing.impl.storage.VfsAwareMapReduceIndex.mapInput(VfsAwareMapReduceIndex.java:39)
	at com.intellij.util.indexing.impl.MapReduceIndex.mapInputAndPrepareUpdate(MapReduceIndex.java:255)
	at com.intellij.psi.stubs.StubUpdatingIndexStorage.mapInputAndPrepareUpdate(StubUpdatingIndexStorage.java:60)
	at com.intellij.psi.stubs.StubUpdatingIndexStorage.mapInputAndPrepareUpdate(StubUpdatingIndexStorage.java:19)
	at com.intellij.indexing.composite.CompositeInvertedIndexBase.updateBaseIndex(CompositeInvertedIndexBase.java:232)
	at com.intellij.indexing.composite.CompositeInvertedIndexBase.mapInputAndPrepareUpdate(CompositeInvertedIndexBase.java:55)
	at com.intellij.indexing.composite.CompositeInvertedIndexBase.mapInputAndPrepareUpdate(CompositeInvertedIndexBase.java:26)
	at com.intellij.util.indexing.FileBasedIndexImpl.lambda$indexUnsavedDocument$14(FileBasedIndexImpl.java:1066)
	at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.freezeFileTypeTemporarilyIn(FileTypeManagerImpl.java:577)
	at com.intellij.util.indexing.FileBasedIndexImpl.indexUnsavedDocument(FileBasedIndexImpl.java:1037)
	at com.intellij.util.indexing.RegisteredIndexes$DocumentUpdateTask.doProcess(RegisteredIndexes.java:179)
	at com.intellij.util.indexing.RegisteredIndexes$DocumentUpdateTask.doProcess(RegisteredIndexes.java:170)
	at com.intellij.util.indexing.UpdateTask.process(UpdateTask.java:63)
	at com.intellij.util.indexing.UpdateTask.processAll(UpdateTask.java:32)
	at com.intellij.util.indexing.FileBasedIndexImpl.lambda$indexUnsavedDocuments$13(FileBasedIndexImpl.java:995)
	at com.intellij.util.indexing.StorageBufferingHandler.runUpdate(StorageBufferingHandler.java:19)
	at com.intellij.util.indexing.FileBasedIndexImpl.indexUnsavedDocuments(FileBasedIndexImpl.java:995)
	at com.intellij.util.indexing.FileBasedIndexImpl.ensureUpToDate(FileBasedIndexImpl.java:753)
	at com.intellij.psi.stubs.StubIndexImpl.processAllKeys(StubIndexImpl.java:426)
	at com.intellij.psi.stubs.StubIndex.processAllKeys(StubIndex.java:66)
	at com.intellij.psi.stubs.StubIndexImpl.getAllKeys(StubIndexImpl.java:414)
	at nl.hannahsten.texifyidea.index.IndexUtilBase.getKeys(IndexUtilBase.kt:143)
	at nl.hannahsten.texifyidea.index.IndexUtilBase.getItems(IndexUtilBase.kt:115)
	at nl.hannahsten.texifyidea.index.IndexUtilBase.getItems(IndexUtilBase.kt:103)
	at nl.hannahsten.texifyidea.lang.CommandManager.updateAliases(CommandManager.kt:244)
	at nl.hannahsten.texifyidea.util.LabelsKt.getLabelReferenceCommands(Labels.kt:170)
	at nl.hannahsten.texifyidea.psi.LatexParameterTextUtilKt.getReferences(LatexParameterTextUtil.kt:20)
	at nl.hannahsten.texifyidea.psi.LatexPsiImplUtil.getReferences(LatexPsiImplUtil.java:120)
	at nl.hannahsten.texifyidea.psi.impl.LatexParameterTextImpl.getReferences(LatexParameterTextImpl.java:39)
	at com.intellij.psi.impl.SharedPsiElementImplUtil.addReferences(SharedPsiElementImplUtil.java:59)
	at com.intellij.psi.impl.SharedPsiElementImplUtil.findReferenceAt(SharedPsiElementImplUtil.java:33)
	at com.intellij.psi.impl.SharedPsiElementImplUtil.findReferenceAt(SharedPsiElementImplUtil.java:51)
	at com.intellij.psi.impl.PsiElementBase.findReferenceAt(PsiElementBase.java:86)
	at com.intellij.psi.AbstractFileViewProvider.findReferenceAt(AbstractFileViewProvider.java:238)
	at com.intellij.psi.SingleRootFileViewProvider.findReferenceAt(SingleRootFileViewProvider.java:224)
	at com.intellij.psi.impl.source.PsiFileImpl.findReferenceAt(PsiFileImpl.java:526)
	at com.intellij.codeInsight.TargetElementUtilBase.findReference(TargetElementUtilBase.java:189)
	at com.intellij.codeInsight.TargetElementUtil.findReference(TargetElementUtil.java:93)
	at com.intellij.model.psi.impl.TargetsKt.fromTargetEvaluator(targets.kt:169)
	at com.intellij.model.psi.impl.TargetsKt.declarationsOrReferences(targets.kt:138)
	at com.intellij.model.psi.impl.TargetsKt.declaredReferencedData(targets.kt:43)
	at com.intellij.model.psi.impl.TargetsKt.targetSymbols(targets.kt:24)
	at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.getTargetSymbols(IdentifierHighlighterPass.java:180)
	at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.highlightReferencesAndDeclarations(IdentifierHighlighterPass.java:172)
	at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.doCollectInformation(IdentifierHighlighterPass.java:92)
	at com.intellij.codeInsight.highlighting.BackgroundHighlighter.lambda$updateHighlighted$1(BackgroundHighlighter.java:147)
	at com.intellij.codeInsight.highlighting.BackgroundHighlightingUtil.lambda$lookForInjectedFileInOtherThread$0(BackgroundHighlightingUtil.java:55)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.insideReadAction(NonBlockingReadActionImpl.java:521)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$attemptComputation$3(NonBlockingReadActionImpl.java:468)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1096)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runInReadActionWithWriteActionPriority$0(ProgressIndicatorUtils.java:79)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:157)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runWithWriteActionPriority$1(ProgressIndicatorUtils.java:119)
	at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:57)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:178)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:688)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:634)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:64)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:165)
	at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:57)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runWithWriteActionPriority(ProgressIndicatorUtils.java:116)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(ProgressIndicatorUtils.java:79)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.attemptComputation(NonBlockingReadActionImpl.java:486)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$transferToBgThread$1(NonBlockingReadActionImpl.java:408)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: com.intellij.openapi.progress.ProcessCanceledException
	at com.intellij.openapi.progress.EmptyProgressIndicator.checkCanceled(EmptyProgressIndicator.java:85)
	at com.intellij.openapi.progress.impl.CoreProgressManager.doCheckCanceled(CoreProgressManager.java:133)
	at com.intellij.openapi.progress.ProgressManager.checkCanceled(ProgressManager.java:230)
	at com.intellij.openapi.progress.ProgressIndicatorProvider.checkCanceled(ProgressIndicatorProvider.java:39)
	at com.intellij.psi.PsiRecursiveElementWalkingVisitor.visitElement(PsiRecursiveElementWalkingVisitor.java:46)
	at com.intellij.psi.util.PsiTreeUtil$4.visitElement(PsiTreeUtil.java:938)
	at com.intellij.psi.impl.PsiElementBase.accept(PsiElementBase.java:273)
	at nl.hannahsten.texifyidea.psi.impl.LatexKeyvalKeyImpl.accept(LatexKeyvalKeyImpl.java:27)
	at com.intellij.psi.PsiWalkingState.visit(PsiWalkingState.java:67)
	at com.intellij.psi.PsiWalkingState.visit(PsiWalkingState.java:24)
	at com.intellij.util.WalkingState.walkChildren(WalkingState.java:62)
	at com.intellij.util.WalkingState.elementStarted(WalkingState.java:49)
	at com.intellij.psi.PsiWalkingState.elementStarted(PsiWalkingState.java:76)
	at com.intellij.psi.PsiRecursiveElementWalkingVisitor.visitElement(PsiRecursiveElementWalkingVisitor.java:48)
	at com.intellij.psi.util.PsiTreeUtil$4.visitElement(PsiTreeUtil.java:938)
	at com.intellij.psi.impl.PsiElementBase.accept(PsiElementBase.java:273)
	at nl.hannahsten.texifyidea.psi.impl.LatexEnvironmentContentImpl.accept(LatexEnvironmentContentImpl.java:27)
	at com.intellij.psi.util.PsiTreeUtil.processElements(PsiTreeUtil.java:934)
	at com.intellij.psi.util.PsiTreeUtil.findChildrenOfAnyType(PsiTreeUtil.java:328)
	at com.intellij.psi.util.PsiTreeUtil.findChildrenOfType(PsiTreeUtil.java:291)
	at nl.hannahsten.texifyidea.psi.LatexEnvironmentUtilKt.getLabel(LatexEnvironmentUtil.kt:30)
	at nl.hannahsten.texifyidea.psi.LatexPsiImplUtil.getLabel(LatexPsiImplUtil.java:95)
	at nl.hannahsten.texifyidea.psi.impl.LatexEnvironmentImpl.getLabel(LatexEnvironmentImpl.java:68)
	at nl.hannahsten.texifyidea.index.stub.LatexEnvironmentStubElementType.createStub(LatexEnvironmentStubElementType.kt:19)
	at nl.hannahsten.texifyidea.index.stub.LatexEnvironmentStubElementType.createStub(LatexEnvironmentStubElementType.kt:12)
	at com.intellij.psi.stubs.DefaultStubBuilder$StubBuildingWalkingVisitor.createStub(DefaultStubBuilder.java:85)
	at com.intellij.psi.stubs.DefaultStubBuilder$StubBuildingWalkingVisitor.visitNode(DefaultStubBuilder.java:60)
	at com.intellij.psi.stubs.DefaultStubBuilder$StubBuildingWalkingVisitor.buildStubTree(DefaultStubBuilder.java:55)
	at com.intellij.psi.stubs.DefaultStubBuilder.buildStubTreeFor(DefaultStubBuilder.java:33)
	at com.intellij.psi.stubs.DefaultStubBuilder.buildStubTree(DefaultStubBuilder.java:22)
	at com.intellij.psi.stubs.StubTreeBuilder.lambda$buildStubTree$1(StubTreeBuilder.java:140)
	at com.intellij.psi.stubs.StubTreeBuilder.handleStubBuilderException(StubTreeBuilder.java:96)
	... 80 more
```

</details>


Changed files:
src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt
src/nl/hannahsten/texifyidea/inspections/latex/redundancy/LatexDuplicateLabelInspection.kt

diff --git a/src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt b/src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt
index 27ef7fbe0..5c313726a 100644
--- a/src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt
+++ b/src/nl/hannahsten/texifyidea/LatexErrorReportSubmitter.kt
@@ -122,7 +122,7 @@ class LatexErrorReportSubmitter : ErrorReportSubmitter() {
             return false
         }
 
-        BrowserUtil.browse(builder.toString())
+        BrowserUtil.browse(builder.toString().take(7000))
         consumer.consume(
             SubmittedReportInfo(
                 null,
diff --git a/src/nl/hannahsten/texifyidea/inspections/latex/redundancy/LatexDuplicateLabelInspection.kt b/src/nl/hannahsten/texifyidea/inspections/latex/redundancy/LatexDuplicateLabelInspection.kt
index 8f95176e8..67bdb8145 100644
--- a/src/nl/hannahsten/texifyidea/inspections/latex/redundancy/LatexDuplicateLabelInspection.kt
+++ b/src/nl/hannahsten/texifyidea/inspections/latex/redundancy/LatexDuplicateLabelInspection.kt
@@ -121,40 +121,21 @@ open class LatexDuplicateLabelInspection : TexifyInspectionBase() {
     private fun getProblemDescriptors(
         commands: Sequence<PsiElement>, isOntheFly: Boolean, manager: InspectionManager, file: PsiFile,
         getLabelDescriptor: PsiElement.() -> LabelDescriptor?
-    ): List<ProblemDescriptor> {
-
-        // Map labels to commands defining the label
-        val labelDescriptors = mutableListOf<LabelDescriptor>()
-
-        val result = mutableListOf<ProblemDescriptor>()
-
-        // Treat LaTeX and BibTeX separately because only the first parameter of \\bibitem commands counts
-        // First find all duplicate labels
-        commands.forEach { command ->
+    ): List<ProblemDescriptor> = commands
+        .mapNotNull { command ->
             // When the label is defined in \\newcommand ignore it, because there could be more than one with #1 as parameter
-            val parent = command.parentOfType(LatexCommands::class)
-            if (parent != null && parent.name == "\\\\newcommand") {
-                return@forEach
-            }
-
-            val labelDescriptor = command.getLabelDescriptor() ?: return@forEach
-            labelDescriptors.add(labelDescriptor)
+            if (command.parentOfType(LatexCommands::class)?.name == "\\\\newcommand") return@mapNotNull null
+            command.getLabelDescriptor()
         }
-
-        val duplicates = labelDescriptors.groupBy { d -> d.label }.filter { g -> g.value.size > 1 }
-
-        for (group in duplicates) {
-            // We can only mark labels in the current file
-            val currentFileDuplicates = group.value.filter { descriptor -> descriptor.element.containingFile == file }
-
-            for (labelDescriptor in currentFileDuplicates) {
-                result.add(createProblemDescriptor(labelDescriptor, isOntheFly, manager))
-            }
+        .groupBy { it.label }
+        .values
+        .filter { it.size > 1 }
+        .flatMap { descriptors ->
+            // We can only mark labels in the current file.
+            descriptors.filter { it.element.containingFile == file }
+                .map { createProblemDescriptor(it, isOntheFly, manager) }
         }
 
-        return result
-    }
-
     /**
      * make the mapping from command etc. to ProblemDescriptor
      */