FIR IDE: move addElementToCompletion to FirCompletionContributorBase
This commit is contained in:
committed by
TeamCityServer
parent
e624f2c136
commit
ae212f36f5
-16
@@ -146,22 +146,6 @@ private class KotlinWithNameReferenceCompletionProvider(
|
||||
private val shouldCompleteTopLevelCallablesFromIndex: Boolean
|
||||
get() = prefixMatcher.prefix.isNotEmpty()
|
||||
|
||||
private fun KtAnalysisSession.addSymbolToCompletion(completionResultSet: CompletionResultSet, expectedType: KtType?, symbol: KtSymbol) {
|
||||
if (symbol !is KtNamedSymbol) return
|
||||
with(lookupElementFactory) {
|
||||
createLookupElement(symbol)
|
||||
?.let { applyWeighers(it, symbol, expectedType) }
|
||||
?.let(completionResultSet::addElement)
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtAnalysisSession.applyWeighers(
|
||||
lookupElement: LookupElement,
|
||||
symbol: KtSymbol,
|
||||
expectedType: KtType?
|
||||
): LookupElement = lookupElement.apply {
|
||||
with(Weighers) { applyWeighsToLookupElement(lookupElement, symbol, expectedType) }
|
||||
}
|
||||
|
||||
fun KtAnalysisSession.addCompletions(
|
||||
positionContext: FirNameReferencePositionContext
|
||||
|
||||
+28
@@ -8,8 +8,16 @@ package org.jetbrains.kotlin.idea.completion.contributors
|
||||
import com.intellij.codeInsight.completion.CompletionParameters
|
||||
import com.intellij.codeInsight.completion.CompletionResultSet
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.completion.KotlinFirLookupElementFactory
|
||||
import org.jetbrains.kotlin.idea.completion.context.FirBasicCompletionContext
|
||||
import org.jetbrains.kotlin.idea.completion.weighers.Weighers
|
||||
import org.jetbrains.kotlin.idea.completion.weighers.Weighers.applyWeighsToLookupElement
|
||||
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtNamedSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
@@ -21,4 +29,24 @@ internal abstract class FirCompletionContributorBase(protected val basicContext:
|
||||
protected val fakeKtFile: KtFile get() = basicContext.fakeKtFile
|
||||
protected val project: Project get() = basicContext.project
|
||||
protected val targetPlatform: TargetPlatform get() = basicContext.targetPlatform
|
||||
|
||||
|
||||
protected val lookupElementFactory = KotlinFirLookupElementFactory()
|
||||
|
||||
protected fun KtAnalysisSession.addSymbolToCompletion(expectedType: KtType?, symbol: KtSymbol) {
|
||||
if (symbol !is KtNamedSymbol) return
|
||||
with(lookupElementFactory) {
|
||||
createLookupElement(symbol)
|
||||
?.let { applyWeighers(it, symbol, expectedType) }
|
||||
?.let(result::addElement)
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtAnalysisSession.applyWeighers(
|
||||
lookupElement: LookupElement,
|
||||
symbol: KtSymbol,
|
||||
expectedType: KtType?
|
||||
): LookupElement = lookupElement.apply {
|
||||
with(Weighers) { applyWeighsToLookupElement(lookupElement, symbol, expectedType) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user