@@ -18,6 +18,7 @@ import com.intellij.psi.PsiNameIdentifierOwner
18
18
import com.intellij.psi.PsiWhiteSpace
19
19
import com.intellij.psi.impl.source.tree.LeafPsiElement
20
20
import com.intellij.psi.util.PsiEditorUtil
21
+ import kotlinx.coroutines.cancel
21
22
import kotlinx.coroutines.flow.*
22
23
import kotlinx.coroutines.launch
23
24
@@ -31,21 +32,7 @@ class RenameLookupManagerListener(val project: Project) : LookupManagerListener
31
32
val lookupImpl = newLookup as ? LookupImpl ? : return
32
33
val editor = lookupImpl.editor as ? EditorEx ? : return
33
34
34
- val startOffset = lookupImpl.lookupOriginalStart
35
- val psiFile = PsiEditorUtil .getPsiFile(editor)
36
-
37
- var targetElement: PsiElement ? = null
38
- if (startOffset >= 0 ) {
39
- targetElement = psiFile.findElementAt(startOffset)
40
- }
41
-
42
- if (targetElement == null ) {
43
- targetElement = psiFile.findElementAt(editor.caretModel.offset)
44
- }
45
-
46
- if (targetElement is LeafPsiElement || targetElement is PsiWhiteSpace ) {
47
- targetElement = targetElement.parent
48
- }
35
+ val targetElement: PsiElement ? = lookupElement(lookupImpl, editor)
49
36
50
37
// maybe user just typing, we should handle for this
51
38
val element = targetElement ? : return
@@ -98,6 +85,28 @@ class RenameLookupManagerListener(val project: Project) : LookupManagerListener
98
85
stringJob.start()
99
86
}
100
87
88
+ private fun lookupElement (
89
+ lookupImpl : LookupImpl ,
90
+ editor : EditorEx
91
+ ): PsiElement ? {
92
+ val startOffset = lookupImpl.lookupOriginalStart
93
+ val psiFile = PsiEditorUtil .getPsiFile(editor)
94
+
95
+ var targetElement: PsiElement ? = null
96
+ if (startOffset >= 0 ) {
97
+ targetElement = psiFile.findElementAt(startOffset)
98
+ }
99
+
100
+ if (targetElement == null ) {
101
+ targetElement = psiFile.findElementAt(editor.caretModel.offset)
102
+ }
103
+
104
+ if (targetElement is LeafPsiElement || targetElement is PsiWhiteSpace ) {
105
+ targetElement = targetElement.parent
106
+ }
107
+ return targetElement
108
+ }
109
+
101
110
private fun extractSuggestionsFromString (result : String ) = result.split(" \n " ).map {
102
111
it.replace(Regex (" ^\\ d+\\ ." ), " " )
103
112
.trim()
0 commit comments