FIR IDE: Add simple shortening completion handler for properties
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
package some
|
package some
|
||||||
|
|
||||||
fun other() {
|
fun other() {
|
||||||
|
|||||||
+1
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_COMPARISON
|
||||||
package some
|
package some
|
||||||
|
|
||||||
import other.someProp
|
import other.someProp
|
||||||
|
|||||||
+18
-1
@@ -115,7 +115,9 @@ private class VariableLookupElementFactory {
|
|||||||
if (setterName != null) "$getterName()/$setterName()" else "$getterName()"
|
if (setterName != null) "$getterName()/$setterName()" else "$getterName()"
|
||||||
|
|
||||||
private fun createInsertHandler(symbol: KtVariableLikeSymbol): InsertHandler<LookupElement> {
|
private fun createInsertHandler(symbol: KtVariableLikeSymbol): InsertHandler<LookupElement> {
|
||||||
return QuotedNamesAwareInsertionHandler(symbol.name)
|
val callableId = symbol.callableIdIfExists ?: return QuotedNamesAwareInsertionHandler(symbol.name)
|
||||||
|
|
||||||
|
return ShorteningVariableInsertionHandler(callableId)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val KtVariableLikeSymbol.callableIdIfExists: FqName?
|
private val KtVariableLikeSymbol.callableIdIfExists: FqName?
|
||||||
@@ -320,6 +322,21 @@ private class ShorteningFunctionInsertionHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ShorteningVariableInsertionHandler(private val name: FqName) : InsertHandler<LookupElement> {
|
||||||
|
override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
||||||
|
val targetFile = context.file as? KtFile ?: return
|
||||||
|
|
||||||
|
context.document.replaceString(
|
||||||
|
context.startOffset,
|
||||||
|
context.tailOffset,
|
||||||
|
name.withRootPrefixIfNeeded().render()
|
||||||
|
)
|
||||||
|
context.commitDocument()
|
||||||
|
|
||||||
|
shortenReferences(targetFile, TextRange(context.startOffset, context.tailOffset))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private open class QuotedNamesAwareInsertionHandler(private val name: Name) : InsertHandler<LookupElement> {
|
private open class QuotedNamesAwareInsertionHandler(private val name: Name) : InsertHandler<LookupElement> {
|
||||||
override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
||||||
val startOffset = context.startOffset
|
val startOffset = context.startOffset
|
||||||
|
|||||||
Reference in New Issue
Block a user