[next edit] LLM-19305 Do not suggest rename action for symbols without usages

(cherry picked from commit d4fbc50b1225310c5be57777cc20868ed0af783c)

IJ-CR-183880

GitOrigin-RevId: 674e1ddc0bd215702a6272a570ec92faa34906e5
This commit is contained in:
Egor Lebedev
2025-10-20 15:19:12 +02:00
committed by intellij-monorepo-bot
parent fa6667926f
commit 67469ce3ae
4 changed files with 28 additions and 1 deletions

View File

@@ -31,7 +31,10 @@ import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.TestOnly
import javax.swing.Icon
class SuggestedRefactoringAvailabilityIndicator(private val project: Project) {
class SuggestedRefactoringAvailabilityIndicator(
@get:ApiStatus.Internal
val project: Project
) {
private class Data(
val document: Document,
val highlighterRangeMarker: RangeMarker,

View File

@@ -0,0 +1,19 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.refactoring.suggested
import com.intellij.util.messages.Topic
import org.jetbrains.annotations.ApiStatus
@ApiStatus.Internal
interface SuggestedRefactoringAvailabilityListener {
fun cleared() {}
fun disabled() {}
fun updated(state: SuggestedRefactoringState) {}
fun reset() {}
companion object {
@Topic.ProjectLevel
val TOPIC: Topic<SuggestedRefactoringAvailabilityListener> =
Topic(SuggestedRefactoringAvailabilityListener::class.java, Topic.BroadcastDirection.NONE)
}
}

View File

@@ -100,14 +100,17 @@ class SuggestedRefactoringChangeCollector(
private fun updateAvailabilityIndicator() {
val state = this.state
val publisher = availabilityIndicator.project.messageBus.syncPublisher(SuggestedRefactoringAvailabilityListener.TOPIC)
if (state == null || state.oldSignature == state.newSignature && state.errorLevel == ErrorLevel.NO_ERRORS) {
availabilityIndicator.clear()
publisher.cleared()
return
}
val refactoringSupport = state.refactoringSupport
if (!state.anchor.isValid || refactoringSupport.nameRange(state.anchor) == null) {
availabilityIndicator.disable()
publisher.disabled()
return
}
@@ -116,6 +119,7 @@ class SuggestedRefactoringChangeCollector(
else
null
availabilityIndicator.update(state.anchor, refactoringData, refactoringSupport)
publisher.updated(state)
}
@set:TestOnly

View File

@@ -47,6 +47,7 @@ class SuggestedRefactoringChangeListener(
}
fun reset(withNewIdentifiers: Boolean = false) {
project.messageBus.syncPublisher(SuggestedRefactoringAvailabilityListener.TOPIC).reset()
if (editingState != null) {
editingState!!.signatureRangeMarker.dispose()
editingState!!.importRangeMarker?.dispose()