User: joe Date: 20 May 25 12:39 Revision: db621d51f93a4c13fd962d22ac19e3a3641b17ae Summary: Add more debug logs for failing mixin completion test TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=10015&personal=false Index: src/main/kotlin/platform/mixin/expression/MEExpressionCompletionUtil.kt =================================================================== --- src/main/kotlin/platform/mixin/expression/MEExpressionCompletionUtil.kt (revision 88fd81ca4652534512fa51a025dc71c14c11cfda) +++ src/main/kotlin/platform/mixin/expression/MEExpressionCompletionUtil.kt (revision db621d51f93a4c13fd962d22ac19e3a3641b17ae) @@ -142,6 +142,7 @@ object MEExpressionCompletionUtil { private const val DEBUG_COMPLETION = false + var debugCompletionUnitTest = false private val NORMAL_ELEMENT = PlatformPatterns.psiElement() .inside(MEStatement::class.java) @@ -1175,12 +1176,19 @@ definitionValue: String, crossinline andThen: (InsertionContext, PsiAnnotation) -> Unit ) = withInsertHandler { context, _ -> + if (debugCompletionUnitTest) System.err.println("Here 1") context.laterRunnable = Runnable { + if (debugCompletionUnitTest) System.err.println("Here 2") context.commitDocument() + if (debugCompletionUnitTest) System.err.println("Here 3") CommandProcessor.getInstance().runUndoTransparentAction { + if (debugCompletionUnitTest) System.err.println("Here 4") runWriteAction { + if (debugCompletionUnitTest) System.err.println("Here 5") val annotation = addDefinition(context, id, definitionValue) + if (debugCompletionUnitTest) System.err.println("Here 6") if (annotation != null) { + if (debugCompletionUnitTest) System.err.println("Here 7") andThen(context, annotation) } } @@ -1189,6 +1197,7 @@ } private fun addDefinition(context: InsertionContext, id: String, definitionValue: String): PsiAnnotation? { + if (debugCompletionUnitTest) System.err.println("Here 8, ${context.startOffset}, ${context.file.text}") val contextElement = context.file.findElementAt(context.startOffset) ?: return null return addDefinition(context.project, contextElement, id, definitionValue) } @@ -1199,13 +1208,18 @@ id: String, definitionValue: String ): PsiAnnotation? { + if (debugCompletionUnitTest) System.err.println("Here 9, $id") val injectionHost = contextElement.findMultiInjectionHost() ?: return null + if (debugCompletionUnitTest) System.err.println("Here 10") val expressionAnnotation = injectionHost.parentOfType() ?: return null + if (debugCompletionUnitTest) System.err.println("Here 11") if (!expressionAnnotation.hasQualifiedName(MixinConstants.MixinExtras.EXPRESSION)) { return null } + if (debugCompletionUnitTest) System.err.println("Here 12") val modifierList = expressionAnnotation.findContainingModifierList() ?: return null + if (debugCompletionUnitTest) System.err.println("Here 13") // look for an existing definition with this id, skip if it exists for (annotation in modifierList.annotations) { if (annotation.hasQualifiedName(MixinConstants.MixinExtras.DEFINITION) && @@ -1214,6 +1228,7 @@ return null } } + if (debugCompletionUnitTest) System.err.println("Here 14") // create and add the new @Definition annotation var newAnnotation = JavaPsiFacade.getElementFactory(project).createAnnotationFromText( @@ -1228,15 +1243,19 @@ anchor = expressionAnnotation } } + if (debugCompletionUnitTest) System.err.println("Here 15, ${newAnnotation.text}, ${anchor?.text}") newAnnotation = modifierList.addAfter(newAnnotation, anchor) as PsiAnnotation // add imports and reformat + if (debugCompletionUnitTest) System.err.println("Here 16") newAnnotation = JavaCodeStyleManager.getInstance(project).shortenClassReferences(newAnnotation) as PsiAnnotation JavaCodeStyleManager.getInstance(project).optimizeImports(modifierList.containingFile) + if (debugCompletionUnitTest) System.err.println("Here 17") val annotationIndex = modifierList.annotations.indexOf(newAnnotation) val formattedModifierList = CodeStyleManager.getInstance(project).reformat(modifierList) as PsiModifierList + if (debugCompletionUnitTest) System.err.println("Here 18") return formattedModifierList.annotations.getOrNull(annotationIndex) } Index: src/test/kotlin/platform/mixin/expression/MEExpressionCompletionTest.kt =================================================================== --- src/test/kotlin/platform/mixin/expression/MEExpressionCompletionTest.kt (revision 88fd81ca4652534512fa51a025dc71c14c11cfda) +++ src/test/kotlin/platform/mixin/expression/MEExpressionCompletionTest.kt (revision db621d51f93a4c13fd962d22ac19e3a3641b17ae) @@ -86,20 +86,25 @@ MinecraftProjectSettings.getInstance(fixture.project).definitionPosRelativeToExpression = BeforeOrAfter.BEFORE + try { + MEExpressionCompletionUtil.debugCompletionUnitTest = true - val possibleItems = fixture.completeBasic() - if (possibleItems != null) { - val itemToComplete = possibleItems.firstOrNull { it.lookupString == lookupString } - if (expectedAfter != null) { - assertNotNull(itemToComplete, "Expected a completion matching \"$lookupString\"") - (fixture.lookup as LookupImpl).finishLookup('\n', itemToComplete) - } else { - assertNull(itemToComplete, "Expected no completions matching \"$lookupString\"") - return - } - } else if (expectedAfter == null) { - fail("Expected no completions matching \"$lookupString\"") - return - } + val possibleItems = fixture.completeBasic() + if (possibleItems != null) { + val itemToComplete = possibleItems.firstOrNull { it.lookupString == lookupString } + if (expectedAfter != null) { + assertNotNull(itemToComplete, "Expected a completion matching \"$lookupString\"") + (fixture.lookup as LookupImpl).finishLookup('\n', itemToComplete) + } else { + assertNull(itemToComplete, "Expected no completions matching \"$lookupString\"") + return + } + } else if (expectedAfter == null) { + fail("Expected no completions matching \"$lookupString\"") + return + } + } finally { + MEExpressionCompletionUtil.debugCompletionUnitTest = false + } // TODO: this is for debugging, remove this once we figure out why tests are failing try {