Use PsiElement#getResolveScope() instead of custom helper

Fix extensions and types completion completion in code fragments in context of library source files
Also affects completion in files not in our project (not tested)
This commit is contained in:
Pavel V. Talanov
2014-10-21 21:48:11 +04:00
parent db8d1b58b8
commit a65f0d3b2a
6 changed files with 35 additions and 20 deletions
@@ -51,17 +51,38 @@ public class CodeFragmentCompletionInLibraryTest : AbstractJvmBasicCompletionTes
}
public fun testCompletionInCustomLibrary() {
testCompletionInLibraryCodeFragment("<caret>", "EXIST: parameter")
}
public fun testSecondCompletionInCustomLibrary() {
testCompletionInLibraryCodeFragment("Sh<caret>", "EXIST: ShortRange", "EXIST: Short", "INVOCATION_COUNT: 2")
}
public fun testExtensionCompletionInCustomLibrary() {
testCompletionInLibraryCodeFragment("3.extOn<caret>", "EXIST: extOnInt")
}
public fun testJavaTypesCompletion() {
testCompletionInLibraryCodeFragment("Hash<caret>", "EXIST: HashMap", "EXIST: HashSet")
}
private fun testCompletionInLibraryCodeFragment(fragmentText: String, vararg completionDirectives: String) {
setupFixtureByCodeFragment(fragmentText)
val directives = completionDirectives.map { "//$it" }.joinToString(separator = "\n")
testCompletion(directives, TargetPlatform.JVM, {
myFixture.complete(CompletionType.BASIC)
})
}
private fun setupFixtureByCodeFragment(fragmentText: String) {
val sourceFile = findLibrarySourceDir().findChild("customLibrary.kt")
val jetFile = PsiManager.getInstance(getProject()).findFile(sourceFile) as JetFile
val fooFunctionFromLibrary = jetFile.getDeclarations().first() as JetFunction
val codeFragment = JetPsiFactory(fooFunctionFromLibrary).createExpressionCodeFragment(
"<caret>",
fragmentText,
KotlinCodeFragmentFactory.getContextElement(fooFunctionFromLibrary.getBodyExpression())
)
myFixture.configureFromExistingVirtualFile(codeFragment.getVirtualFile())
testCompletion("//EXIST: parameter", TargetPlatform.JVM, {
myFixture.complete(CompletionType.BASIC)
})
}
private fun findLibrarySourceDir(): VirtualFile {