Skip to content

Commit bbc691a

Browse files
committed
fix(refactor): add PsiErrorElement handling and collect syntax errors #129
This commit introduces the handling of `PsiErrorElement` and the collection of syntax errors in the `RefactorThisAction` class. The update ensures that the action is only enabled when the associated PSI file is writable, preventing the execution of the action on read-only files. Additionally, a new function `collectProblems` is introduced to handle highlighting issues.
1 parent 63b17b2 commit bbc691a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/main/kotlin/cc/unitmesh/devti/actions/chat/RefactorThisAction.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,35 @@ import cc.unitmesh.devti.gui.chat.ChatActionType
55
import com.intellij.openapi.actionSystem.AnActionEvent
66
import com.intellij.openapi.actionSystem.CommonDataKeys
77
import com.intellij.openapi.command.WriteCommandAction
8+
import com.intellij.openapi.editor.Editor
9+
import com.intellij.openapi.project.Project
10+
import com.intellij.psi.PsiElement
11+
import com.intellij.psi.PsiFile
812

913
class RefactorThisAction : ChatBaseAction() {
1014

1115
override fun getActionType(): ChatActionType = ChatActionType.REFACTOR
16+
override fun update(e: AnActionEvent) {
17+
val editor = e.getData(CommonDataKeys.EDITOR)
18+
val file = e.getData(CommonDataKeys.PSI_FILE)
19+
val project = e.getData(CommonDataKeys.PROJECT)
20+
21+
if (editor == null || file == null || project == null) {
22+
e.presentation.isEnabled = false
23+
return
24+
}
25+
26+
if (file.isWritable) {
27+
e.presentation.isEnabled = true
28+
return
29+
}
30+
31+
e.presentation.isEnabled = false
32+
}
33+
34+
fun collectProblems(element: PsiElement) {
35+
// Highlighters
36+
}
1237

1338
override fun getReplaceableAction(event: AnActionEvent): (response: String) -> Unit {
1439
val editor = event.getRequiredData(CommonDataKeys.EDITOR)

0 commit comments

Comments
 (0)