FIR IDE: remove error handling from function completion

This commit is contained in:
Ilya Kirillov
2021-06-02 00:36:12 +02:00
committed by TeamCityServer
parent a1fcc34bbc
commit ae7a6dc742
3 changed files with 10 additions and 21 deletions
@@ -50,8 +50,8 @@ internal abstract class FirCompletionContributorBase<C : FirRawPositionCompletio
if (symbol !is KtNamedSymbol) return if (symbol !is KtNamedSymbol) return
with(lookupElementFactory) { with(lookupElementFactory) {
createLookupElement(symbol) createLookupElement(symbol)
?.let { applyWeighers(it, symbol, expectedType) } .let { applyWeighers(it, symbol, expectedType) }
?.let(sink::addElement) .let(sink::addElement)
} }
} }
@@ -40,7 +40,7 @@ internal class FunctionLookupElementFactory {
symbol: KtFunctionSymbol, symbol: KtFunctionSymbol,
importStrategy: CallableImportStrategy, importStrategy: CallableImportStrategy,
insertionStrategy: CallableInsertionStrategy insertionStrategy: CallableInsertionStrategy
): LookupElementBuilder? { ): LookupElementBuilder {
val lookupObject = FunctionLookupObject( val lookupObject = FunctionLookupObject(
symbol.name, symbol.name,
importStrategy = importStrategy, importStrategy = importStrategy,
@@ -55,22 +55,11 @@ internal class FunctionLookupElementFactory {
CallableInsertionStrategy.AS_IDENTIFIER -> QuotedNamesAwareInsertionHandler() CallableInsertionStrategy.AS_IDENTIFIER -> QuotedNamesAwareInsertionHandler()
} }
return try { return LookupElementBuilder.create(lookupObject, symbol.name.asString())
LookupElementBuilder.create(lookupObject, symbol.name.asString()) .withTailText(getTailText(symbol), true)
.withTailText(getTailText(symbol), true) .withTypeText(symbol.annotatedType.type.render(CompletionShortNamesRenderer.TYPE_RENDERING_OPTIONS))
.withTypeText(symbol.annotatedType.type.render(CompletionShortNamesRenderer.TYPE_RENDERING_OPTIONS)) .withInsertHandler(insertionHandler)
.withInsertHandler(insertionHandler) .let { withSymbolInfo(symbol, it) }
.let { withSymbolInfo(symbol, it) }
} catch (e: Throwable) {
if (e is ControlFlowException) throw e
LOG.error(e)
null
}
}
companion object {
private val LOG = logger<FunctionLookupElementFactory>()
} }
} }
@@ -22,7 +22,7 @@ internal class KotlinFirLookupElementFactory {
private val typeParameterLookupElementFactory = TypeParameterLookupElementFactory() private val typeParameterLookupElementFactory = TypeParameterLookupElementFactory()
private val packagePartLookupElementFactory = PackagePartLookupElementFactory() private val packagePartLookupElementFactory = PackagePartLookupElementFactory()
fun KtAnalysisSession.createLookupElement(symbol: KtNamedSymbol): LookupElement? { fun KtAnalysisSession.createLookupElement(symbol: KtNamedSymbol): LookupElement {
return when (symbol) { return when (symbol) {
is KtCallableSymbol -> createCallableLookupElement( is KtCallableSymbol -> createCallableLookupElement(
symbol, symbol,
@@ -39,7 +39,7 @@ internal class KotlinFirLookupElementFactory {
symbol: KtCallableSymbol, symbol: KtCallableSymbol,
importingStrategy: CallableImportStrategy, importingStrategy: CallableImportStrategy,
insertionStrategy: CallableInsertionStrategy, insertionStrategy: CallableInsertionStrategy,
): LookupElementBuilder? { ): LookupElementBuilder {
return when (symbol) { return when (symbol) {
is KtFunctionSymbol -> with(functionLookupElementFactory) { createLookup(symbol, importingStrategy, insertionStrategy) } is KtFunctionSymbol -> with(functionLookupElementFactory) { createLookup(symbol, importingStrategy, insertionStrategy) }
is KtVariableLikeSymbol -> with(variableLookupElementFactory) { createLookup(symbol, importingStrategy) } is KtVariableLikeSymbol -> with(variableLookupElementFactory) { createLookup(symbol, importingStrategy) }