FIR IDE: Use single TextRange as selection instead of two ints
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
package org.jetbrains.kotlin.shortenRefs
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.AbstractImportsTest
|
||||
import org.jetbrains.kotlin.idea.frontend.api.analyze
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
@@ -19,12 +20,12 @@ abstract class AbstractFirShortenRefsTest : AbstractImportsTest() {
|
||||
val selectionModel = myFixture.editor.selectionModel
|
||||
if (!selectionModel.hasSelection()) error("No selection in input file")
|
||||
|
||||
val (startOffset, endOffset) = runReadAction { selectionModel.selectionStart to selectionModel.selectionEnd }
|
||||
val selection = runReadAction { TextRange(selectionModel.selectionStart, selectionModel.selectionEnd) }
|
||||
|
||||
val shortenings = executeOnPooledThread {
|
||||
runReadAction {
|
||||
analyze(file) {
|
||||
collectPossibleReferenceShortenings(file, startOffset, endOffset)
|
||||
collectPossibleReferenceShortenings(file, selection)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.frontend.api
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.idea.frontend.api.calls.KtCall
|
||||
import org.jetbrains.kotlin.idea.frontend.api.components.*
|
||||
@@ -179,5 +180,6 @@ abstract class KtAnalysisSession(final override val token: ValidityToken) : Vali
|
||||
fun KtReturnExpression.getReturnTargetSymbol(): KtCallableSymbol? =
|
||||
expressionHandlingComponent.getReturnExpressionTargetSymbol(this)
|
||||
|
||||
fun collectPossibleReferenceShortenings(file: KtFile, from: Int, to: Int) = referenceShortener.collectShortenings(file, from, to)
|
||||
fun collectPossibleReferenceShortenings(file: KtFile, selection: TextRange): ShortenCommand =
|
||||
referenceShortener.collectShortenings(file, selection)
|
||||
}
|
||||
|
||||
+2
-1
@@ -5,10 +5,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.frontend.api.components
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
abstract class KtReferenceShortener : KtAnalysisSessionComponent() {
|
||||
abstract fun collectShortenings(file: KtFile, from: Int, to: Int): ShortenCommand
|
||||
abstract fun collectShortenings(file: KtFile, selection: TextRange): ShortenCommand
|
||||
}
|
||||
|
||||
interface ShortenCommand {
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.idea.frontend.api.fir.components
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.SmartPsiElementPointer
|
||||
import com.intellij.util.containers.addIfNotNull
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
@@ -59,7 +60,7 @@ internal class KtFirReferenceShortener(
|
||||
override val token: ValidityToken,
|
||||
override val firResolveState: FirModuleResolveState,
|
||||
) : KtReferenceShortener(), KtFirAnalysisSessionComponent {
|
||||
override fun collectShortenings(file: KtFile, from: Int, to: Int): ShortenCommand {
|
||||
override fun collectShortenings(file: KtFile, selection: TextRange): ShortenCommand {
|
||||
resolveFileToBodyResolve(file)
|
||||
val firFile = file.getOrBuildFirOfType<FirFile>(firResolveState)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user