Completion Unit Test: complete returns null
Can't get completion unit test to work. I'm following the guide, but `getLookupElementStrings()` (or result of `complete(...)`) is always null. Completion actually works when I try it in the IDE.
I did a bit of debugging and it boils down to LookupManagerImpl.myActiveLookup being null when getting results. What could be the cause?
Stacktrace:
at com.intellij.codeInsight.lookup.impl.LookupManagerImpl.getActiveLookup(LookupManagerImpl.java:225) // myActiveLookup == null
at com.intellij.codeInsight.lookup.LookupManager.getActiveLookup(LookupManager.java:42)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.getLookup(CodeInsightTestFixtureImpl.java:1903)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.getLookupElements(CodeInsightTestFixtureImpl.java:1274) // myEmptyLookup = false, lookup <- null => return null
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl$21.compute(CodeInsightTestFixtureImpl.java:1214)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl$21.compute(CodeInsightTestFixtureImpl.java:1195)
at com.intellij.util.ui.UIUtil$13.run(UIUtil.java:2455)
at com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded(UIUtil.java:2426)
at com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded(UIUtil.java:2452)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.complete(CodeInsightTestFixtureImpl.java:1195) // returns null
thanks!
请先登录再写评论。
Please show the whole test method's code and verify you have "<caret>" marker in the test data file where completion is invoked on.
Sure, please find them below. I can confirm that getVariants on my reference gets invoked correctly.
Test class:
CompletionWithStaticImport.es:
zzz.es:
thanks
WRONG, PLEASE IGNORE
It seems the javadoc for com.intellij.testFramework.fixtures.CodeInsightTestFixture#configureByFiles is misleading, good catch.
Please change order in arguments in
so that file containing <caret> is last.
AFAIU copyFileToProject() for zzz.es should be enough and slightly faster.
Hm, I'm not sure you're correct.. I did as you said and got non-null results, but looks like it tried to invoke completion at the very beginning of zzz.es. When I added a <caret> to zzz.es, I got nulls again.
As a test I reverted configureByFiles call and added this:
Inspecting `element` in the debugger shows that the framework got it right:
(field_decl ('field' ':' ' ' (type_ref ...)) ' ' '}'
element is that last PsiWhiteSpace before '}'.
Besides, I have another test that uses configureByFiles(..) with 2 arguments, and having <caret> in the first of them works just fine.
You're right, I missed the loop iterates backwards and got additionally confused by looking at a sample where both files have <caret>.
Did you check there are multiple completion variants at this position? <null> is expected result if "if the only item was auto-completed" (javadoc).
There's only one variant indeed.. how do I check for it then?
Edit: nevermind, found it. Just another method in CodeInsightTestFixture.
Thanks!
Konstantin Sobolev hey mate, I also have similar situation. Which method did u use instead of complete()?
Otto Dvali I didn't touch this project for a few years now, but the answer is probably here: https://github.com/SumoLogic/epigraph/blob/master/idea-plugin/src/test/java/ws/epigraph/ideaplugin/schema/features/completion/CompletionTest.java
thanks Konstantin Sobolev