Skip to content

Commit

Permalink
feat(refactor): add RenameLookupElement to improve ui support and cod…
Browse files Browse the repository at this point in the history
…e completion #132 #129

This commit introduces a new class, `RenameLookupManagerListener`, which enhances refactoring support by adding post-action support and code completion functionality. The listener is designed to work with `LookupImpl` and `TemplateManagerImpl` to provide a more robust refactoring experience. It includes a list of suggestions (`suggestion1`, `suggestion2`, `suggestion3`) and adds them to the lookup with a custom `RenameLookupElement` that renders with the `AutoDevIcons.Idea` icon. This change improves the usability and functionality of the refactoring process.
  • Loading branch information
phodal committed Apr 2, 2024
1 parent 3eec886 commit 5caa4c8
Showing 1 changed file with 19 additions and 4 deletions.
@@ -1,9 +1,12 @@
package cc.unitmesh.devti.practise

import com.intellij.codeInsight.lookup.Lookup
import com.intellij.codeInsight.lookup.LookupListener
import com.intellij.codeInsight.lookup.LookupManagerListener
import cc.unitmesh.devti.AutoDevIcons
import com.intellij.codeInsight.completion.InsertionContext
import com.intellij.codeInsight.completion.PrefixMatcher
import com.intellij.codeInsight.lookup.*
import com.intellij.codeInsight.lookup.impl.LookupImpl
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project

class RenameLookupManagerListener(val project: Project) : LookupManagerListener {
Expand All @@ -18,7 +21,19 @@ class RenameLookupManagerListener(val project: Project) : LookupManagerListener
val psiElement = lookupImpl.psiFile?.findElementAt(startOffset)
val element = psiElement ?: lookupImpl.psiElement

lookupImpl.addLookupListener(RenameLookupListener())
// lookupImpl.addLookupListener(RenameLookupListener())
val suggestionNames = listOf("suggestion1", "suggestion2", "suggestion3")
suggestionNames.map {
lookupImpl.addItem(RenameLookupElement(it), PrefixMatcher.ALWAYS_TRUE)
}
}
}

class RenameLookupElement(val name: String) : LookupElement() {
override fun getLookupString(): String = name
override fun renderElement(presentation: LookupElementPresentation) {
presentation.icon = AutoDevIcons.Idea
super.renderElement(presentation)
}
}

Expand Down

0 comments on commit 5caa4c8

Please sign in to comment.