FIR IDE: Do not show hint from ImportQuickFix if the PSI have changed
Without this check, the import hint will be available even after the quickfix is applied; this happens because the element to which the quickfix is attached is not invalidated by the quickfix execution Since the quickfix is still considered as available some time after the import have been added, the hint is also generated. And the hint stays even after the quickfix itself is discarded `isOutdated` function prevents this
This commit is contained in:
committed by
TeamCityServer
parent
8991ce53f4
commit
9504488acb
@@ -16,6 +16,7 @@ import com.intellij.openapi.ui.popup.JBPopupFactory
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.util.PsiModificationTracker
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.caches.project.getModuleInfo
|
||||
import org.jetbrains.kotlin.idea.fir.api.fixes.diagnosticFixFactory
|
||||
@@ -79,6 +80,21 @@ internal class ImportQuickFix(
|
||||
return true
|
||||
}
|
||||
|
||||
private val modificationCountOnCreate: Long = PsiModificationTracker.SERVICE.getInstance(element.project).modificationCount
|
||||
|
||||
/**
|
||||
* This is a safe-guard against showing hint after the quickfix have been applied.
|
||||
*
|
||||
* Inspired by the org.jetbrains.kotlin.idea.quickfix.ImportFixBase.isOutdated
|
||||
*/
|
||||
private fun isOutdated(project: Project): Boolean {
|
||||
return modificationCountOnCreate != PsiModificationTracker.SERVICE.getInstance(project).modificationCount
|
||||
}
|
||||
|
||||
override fun isAvailableImpl(project: Project, editor: Editor?, file: PsiFile): Boolean {
|
||||
return super.isAvailableImpl(project, editor, file) && !isOutdated(project)
|
||||
}
|
||||
|
||||
private class ImportQuestionAction(
|
||||
private val project: Project,
|
||||
private val editor: Editor,
|
||||
|
||||
Reference in New Issue
Block a user