Fixed KT-1476 Code completion for not imported properties
#KT-1476 Fixed
This commit is contained in:
Generated
+5
@@ -79,6 +79,11 @@
|
||||
<option name="ASSIGNMENT_WRAP" value="1" />
|
||||
<option name="PARENT_SETTINGS_INSTALLED" value="true" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="CoffeeScript">
|
||||
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
|
||||
<option name="METHOD_PARAMETERS_WRAP" value="5" />
|
||||
<option name="PARENT_SETTINGS_INSTALLED" value="true" />
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="ECMA Script Level 4">
|
||||
<option name="ELSE_ON_NEW_LINE" value="true" />
|
||||
<option name="WHILE_ON_NEW_LINE" value="true" />
|
||||
|
||||
+1
-1
@@ -163,7 +163,7 @@ public class JetFromJavaDescriptorHelper {
|
||||
|
||||
|
||||
@NotNull
|
||||
public static Collection<FqName> getTopLevelFunctionFqNames(
|
||||
public static Collection<FqName> getTopLevelCallableFqNames(
|
||||
@NotNull Project project,
|
||||
@NotNull GlobalSearchScope scope,
|
||||
boolean shouldBeExtension
|
||||
|
||||
@@ -163,10 +163,9 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac
|
||||
|
||||
//TODO: this code is temporary and is to be dropped when compiled top level functions are indexed
|
||||
val identifier = Name.identifier(name)
|
||||
val topLevelFunctionFqNames = JetFromJavaDescriptorHelper.getTopLevelFunctionFqNames(project, scope, false)
|
||||
for (fqName in topLevelFunctionFqNames) {
|
||||
for (fqName in JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, false)) {
|
||||
if (fqName.lastSegmentIs(identifier)) {
|
||||
findCompiledTopLevelEntities(fqName, context, jetScope, resolveSession).filterIsInstanceTo(result, javaClass<FunctionDescriptor>())
|
||||
findTopLevelCallables(fqName, context, jetScope, resolveSession).filterIsInstanceTo(result, javaClass<FunctionDescriptor>())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,9 +174,10 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac
|
||||
return result
|
||||
}
|
||||
|
||||
private fun findCompiledTopLevelEntities(fqName: FqName, context: JetExpression, jetScope: JetScope, resolveSession: ResolveSessionForBodies): Collection<DeclarationDescriptor> {
|
||||
private fun findTopLevelCallables(fqName: FqName, context: JetExpression, jetScope: JetScope, resolveSession: ResolveSessionForBodies): Collection<DeclarationDescriptor> {
|
||||
val importDirective = JetPsiFactory(context.getProject()).createImportDirective(ImportPath(fqName, false))
|
||||
return QualifiedExpressionResolver().analyseImportReference(importDirective, jetScope, BindingTraceContext(), resolveSession.getModuleDescriptor())
|
||||
val allDescriptors = QualifiedExpressionResolver().analyseImportReference(importDirective, jetScope, BindingTraceContext(), resolveSession.getModuleDescriptor())
|
||||
return allDescriptors.filterIsInstance(javaClass<CallableDescriptor>()).filter { it.getReceiverParameter() == null }
|
||||
}
|
||||
|
||||
private fun MutableCollection<in FunctionDescriptor>.addJetSourceTopLevelFunctions(name: String, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope) {
|
||||
@@ -198,19 +198,17 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac
|
||||
private fun getJetExtensionFunctionsByName(name: String, scope: GlobalSearchScope): Collection<PsiElement>
|
||||
= JetTopLevelExtensionFunctionShortNameIndex.getInstance().get(name, project, scope)
|
||||
|
||||
// TODO: Make it work for properties
|
||||
public fun getJetTopLevelCallables(nameFilter: (String) -> Boolean, context: JetExpression /*TODO: to be dropped*/, resolveSession: ResolveSessionForBodies, scope: GlobalSearchScope): Collection<DeclarationDescriptor> {
|
||||
val result = ArrayList<DeclarationDescriptor>()
|
||||
|
||||
JetTopLevelNonExtensionFunctionShortNameIndex.getInstance().getAllKeys(project)
|
||||
.stream()
|
||||
.filter(nameFilter)
|
||||
.forEach { result.addJetSourceTopLevelFunctions(it, resolveSession, scope) }
|
||||
|
||||
val sourceNames = JetTopLevelFunctionsFqnNameIndex.getInstance().getAllKeys(project).stream() + JetTopLevelPropertiesFqnNameIndex.getInstance().getAllKeys(project).stream()
|
||||
val allFqNames = sourceNames.map { FqName(it) } + JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, false).stream()
|
||||
|
||||
val jetScope = resolveSession.resolveToElement(context).get(BindingContext.RESOLUTION_SCOPE, context) ?: return listOf()
|
||||
JetFromJavaDescriptorHelper.getTopLevelFunctionFqNames(project, scope, false)
|
||||
.filter { nameFilter(it.shortName().asString()) }
|
||||
.flatMapTo(result) { findCompiledTopLevelEntities(it, context, jetScope, resolveSession) }
|
||||
allFqNames.filter { nameFilter(it.shortName().asString()) }
|
||||
.toList()
|
||||
.flatMapTo(result) { findTopLevelCallables(it, context, jetScope, resolveSession) }
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -231,7 +229,7 @@ public class JetShortNamesCache(private val project: Project) : PsiShortNamesCac
|
||||
|
||||
val functionFQNs = extensionFunctionsFromSourceFqNames(nameFilter, scope)
|
||||
|
||||
JetFromJavaDescriptorHelper.getTopLevelFunctionFqNames(project, scope, true)
|
||||
JetFromJavaDescriptorHelper.getTopLevelCallableFqNames(project, scope, true)
|
||||
.filterTo(functionFQNs) { nameFilter(it.shortName().asString()) }
|
||||
|
||||
// Iterate through the function with attempt to resolve found functions
|
||||
|
||||
@@ -48,7 +48,7 @@ class LookupElementsCollector(private val prefixMatcher: PrefixMatcher,
|
||||
}
|
||||
|
||||
public fun addDescriptorElements(descriptor: DeclarationDescriptor) {
|
||||
if (!descriptorFilter(descriptor)) return
|
||||
if (!descriptorFilter(descriptor)) return
|
||||
|
||||
addElement(DescriptorLookupConverter.createLookupElement(resolveSession, descriptor))
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo() {
|
||||
glob<caret>
|
||||
}
|
||||
|
||||
// EXIST: "globalProperty"
|
||||
@@ -0,0 +1,3 @@
|
||||
package foo.bar
|
||||
|
||||
val globalProperty: Int = 1
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package test
|
||||
|
||||
fun globalFun1(): Int = 1
|
||||
fun globalFun2(): Int = 1
|
||||
|
||||
object Some {
|
||||
fun globalFun3(): Int = 3
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package pack
|
||||
|
||||
fun testFun() {
|
||||
gl<caret>
|
||||
}
|
||||
|
||||
// EXIST: globalFun1, globalFun2
|
||||
// ABSENT: globalFun3
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package test
|
||||
|
||||
val globalProp1: Int = 1
|
||||
var globalProp2: Int = 2
|
||||
|
||||
val String.globalExtensionProp: Int get() = 0
|
||||
fun String.globalExtensionFun(): Int = 0
|
||||
|
||||
object Some {
|
||||
var globalProp3: Int = 3
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package pack
|
||||
|
||||
fun testFun() {
|
||||
gl<caret>
|
||||
}
|
||||
|
||||
// EXIST: globalProp1, globalProp2
|
||||
// ABSENT: globalProp3
|
||||
// ABSENT: globalExtensionProp
|
||||
// ABSENT: globalExtensionFun
|
||||
@@ -48,9 +48,19 @@ public class JvmWithLibBasicCompletionTestGenerated extends AbstractJvmWithLibBa
|
||||
doTest("idea/testData/completion/basic/custom/TopLevelNonImportedExtFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TopLevelNonImportedExtProp.kt")
|
||||
public void testTopLevelNonImportedExtProp() throws Exception {
|
||||
doTest("idea/testData/completion/basic/custom/TopLevelNonImportedExtProp.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TopLevelNonImportedFun.kt")
|
||||
public void testTopLevelNonImportedFun() throws Exception {
|
||||
doTest("idea/testData/completion/basic/custom/TopLevelNonImportedFun.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TopLevelNonImportedProperty.kt")
|
||||
public void testTopLevelNonImportedProperty() throws Exception {
|
||||
doTest("idea/testData/completion/basic/custom/TopLevelNonImportedProperty.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -98,6 +98,16 @@ public class MultiFileJvmBasicCompletionTestGenerated extends AbstractMultiFileJ
|
||||
doTest("idea/testData/completion/basic/multifile/NotImportedExtensionFunction/");
|
||||
}
|
||||
|
||||
@TestMetadata("NotImportedExtensionProperty")
|
||||
public void testNotImportedExtensionProperty() throws Exception {
|
||||
doTest("idea/testData/completion/basic/multifile/NotImportedExtensionProperty/");
|
||||
}
|
||||
|
||||
@TestMetadata("NotImportedFunction")
|
||||
public void testNotImportedFunction() throws Exception {
|
||||
doTest("idea/testData/completion/basic/multifile/NotImportedFunction/");
|
||||
}
|
||||
|
||||
@TestMetadata("NotImportedJavaClass")
|
||||
public void testNotImportedJavaClass() throws Exception {
|
||||
doTest("idea/testData/completion/basic/multifile/NotImportedJavaClass/");
|
||||
@@ -108,6 +118,11 @@ public class MultiFileJvmBasicCompletionTestGenerated extends AbstractMultiFileJ
|
||||
doTest("idea/testData/completion/basic/multifile/NotImportedObject/");
|
||||
}
|
||||
|
||||
@TestMetadata("NotImportedProperty")
|
||||
public void testNotImportedProperty() throws Exception {
|
||||
doTest("idea/testData/completion/basic/multifile/NotImportedProperty/");
|
||||
}
|
||||
|
||||
@TestMetadata("TopLevelFunction")
|
||||
public void testTopLevelFunction() throws Exception {
|
||||
doTest("idea/testData/completion/basic/multifile/TopLevelFunction/");
|
||||
|
||||
Reference in New Issue
Block a user