Simplified code
This commit is contained in:
+2
-2
@@ -109,7 +109,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
get() = smartCompletion?.expectedInfos ?: emptyList()
|
get() = smartCompletion?.expectedInfos ?: emptyList()
|
||||||
|
|
||||||
private fun calcCompletionKind(): CompletionKind {
|
private fun calcCompletionKind(): CompletionKind {
|
||||||
if (NamedArgumentCompletion.isOnlyNamedArgumentExpected(position)) {
|
if (nameExpression != null && NamedArgumentCompletion.isOnlyNamedArgumentExpected(nameExpression)) {
|
||||||
return CompletionKind.NAMED_ARGUMENTS_ONLY
|
return CompletionKind.NAMED_ARGUMENTS_ONLY
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NamedArgumentCompletion.complete(position, collector, expectedInfos)
|
NamedArgumentCompletion.complete(collector, expectedInfos)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNonImported(completionKind: CompletionKind) {
|
private fun addNonImported(completionKind: CompletionKind) {
|
||||||
|
|||||||
+8
-32
@@ -20,19 +20,12 @@ import com.intellij.codeInsight.completion.InsertHandler
|
|||||||
import com.intellij.codeInsight.completion.InsertionContext
|
import com.intellij.codeInsight.completion.InsertionContext
|
||||||
import com.intellij.codeInsight.lookup.LookupElement
|
import com.intellij.codeInsight.lookup.LookupElement
|
||||||
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import com.intellij.psi.filters.AndFilter
|
|
||||||
import com.intellij.psi.filters.ClassFilter
|
|
||||||
import com.intellij.psi.filters.OrFilter
|
|
||||||
import com.intellij.psi.filters.position.ParentElementFilter
|
|
||||||
import org.jetbrains.kotlin.core.FirstChildInParentFilter
|
|
||||||
import org.jetbrains.kotlin.idea.JetIcons
|
import org.jetbrains.kotlin.idea.JetIcons
|
||||||
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
|
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.JetCallElement
|
import org.jetbrains.kotlin.psi.JetCallElement
|
||||||
|
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||||
import org.jetbrains.kotlin.psi.JetValueArgument
|
import org.jetbrains.kotlin.psi.JetValueArgument
|
||||||
import org.jetbrains.kotlin.psi.JetValueArgumentName
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.render
|
import org.jetbrains.kotlin.renderer.render
|
||||||
@@ -40,35 +33,18 @@ import org.jetbrains.kotlin.types.JetType
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object NamedArgumentCompletion {
|
object NamedArgumentCompletion {
|
||||||
private val positionFilter = AndFilter(
|
public fun isOnlyNamedArgumentExpected(nameExpression: JetSimpleNameExpression): Boolean {
|
||||||
LeafElementFilter(JetTokens.IDENTIFIER),
|
val thisArgument = nameExpression.parent as? JetValueArgument ?: return false
|
||||||
OrFilter(
|
if (thisArgument.isNamed()) return false
|
||||||
AndFilter(
|
|
||||||
ParentElementFilter(ClassFilter(javaClass<JetValueArgument>()), 2),
|
|
||||||
FirstChildInParentFilter(2)
|
|
||||||
),
|
|
||||||
ParentElementFilter(ClassFilter(javaClass<JetValueArgumentName>()), 2)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
public fun isOnlyNamedArgumentExpected(position: PsiElement): Boolean {
|
|
||||||
if (!positionFilter.isAcceptable(position, position)) return false
|
|
||||||
|
|
||||||
val thisArgument = position.getStrictParentOfType<JetValueArgument>()!!
|
|
||||||
|
|
||||||
val callElement = thisArgument.getStrictParentOfType<JetCallElement>() ?: return false
|
val callElement = thisArgument.getStrictParentOfType<JetCallElement>() ?: return false
|
||||||
|
|
||||||
for (argument in callElement.getValueArguments()) {
|
return callElement.valueArguments
|
||||||
if (argument == thisArgument) break
|
.takeWhile { it != thisArgument }
|
||||||
if (argument.isNamed()) return true
|
.any { it.isNamed() }
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun complete(position: PsiElement, collector: LookupElementsCollector, expectedInfos: Collection<ExpectedInfo>) {
|
public fun complete(collector: LookupElementsCollector, expectedInfos: Collection<ExpectedInfo>) {
|
||||||
if (!positionFilter.isAcceptable(position, position)) return
|
|
||||||
|
|
||||||
val nameToParameterType = HashMap<Name, MutableSet<JetType>>()
|
val nameToParameterType = HashMap<Name, MutableSet<JetType>>()
|
||||||
for (expectedInfo in expectedInfos) {
|
for (expectedInfo in expectedInfos) {
|
||||||
val argumentData = expectedInfo.additionalData as? ArgumentPositionData.Positional ?: continue
|
val argumentData = expectedInfo.additionalData as? ArgumentPositionData.Positional ?: continue
|
||||||
|
|||||||
+2
-2
@@ -50,8 +50,8 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
|||||||
get() = smartCompletion?.expectedInfos ?: emptyList()
|
get() = smartCompletion?.expectedInfos ?: emptyList()
|
||||||
|
|
||||||
override fun doComplete() {
|
override fun doComplete() {
|
||||||
if (NamedArgumentCompletion.isOnlyNamedArgumentExpected(position)) {
|
if (nameExpression != null && NamedArgumentCompletion.isOnlyNamedArgumentExpected(nameExpression)) {
|
||||||
NamedArgumentCompletion.complete(position, collector, expectedInfos)
|
NamedArgumentCompletion.complete(collector, expectedInfos)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user