Skip to content

Commit

Permalink
refactor(gui): remove Project dependency from EditorFragment
Browse files Browse the repository at this point in the history
Remove the `Project` parameter from the `EditorFragment` constructor and related usages to simplify the code structure and reduce unnecessary dependencies.
  • Loading branch information
phodal committed Dec 7, 2024
1 parent 809f6a1 commit 1c7429d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cc.unitmesh.devti.provider.devins.LanguagePromptProcessor
import cc.unitmesh.devti.provider.http.HttpClientProvider
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.util.NlsSafe
Expand All @@ -18,10 +19,8 @@ class AutoDevRunDevInsAction : DumbAwareAction() {
val document = editor.document
val file = FileDocumentManager.getInstance().getFile(document) ?: return

val language = try {
val language = runReadAction {
PsiManager.getInstance(project).findFile(file)?.language?.id
} catch (e: Exception) {
null
} ?: return

e.presentation.isEnabled = language == "HTTP Request" || (language == "DevIn" && hasDevInProcessor(language))
Expand All @@ -42,7 +41,6 @@ class AutoDevRunDevInsAction : DumbAwareAction() {

when (language) {
"HTTP Request" -> {
// call http request processor
HttpClientProvider.all().forEach { it.execute(project, file, text) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class CodeBlockView(
editor.scrollPane.setBorder(JBUI.Borders.empty())
editor.component.setBorder(JBUI.Borders.empty())

val editorFragment = EditorFragment(project, editor, message)
val editorFragment = EditorFragment(editor, message)
editorFragment.setCollapsed(forceFoldEditorByDefault)
editorFragment.updateExpandCollapseLabel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.event.CaretEvent
import com.intellij.openapi.editor.event.CaretListener
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.project.Project
import com.intellij.ui.JBColor
import com.intellij.ui.components.JBLabel
import com.intellij.util.ui.JBUI
Expand All @@ -18,7 +17,6 @@ import java.awt.Graphics
import java.awt.Insets
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.awt.event.MouseListener
import javax.swing.Box
import javax.swing.JComponent

Expand Down Expand Up @@ -52,7 +50,7 @@ class EditorPadding(private val editor: Editor, pad: Int) :
}


class EditorFragment(private val project: Project, private val editor: EditorEx, message: CompletableMessage) {
class EditorFragment(private val editor: EditorEx, message: CompletableMessage) {
private val editorLineThreshold = 6
private val expandCollapseTextLabel: AIAssistantFoldLabel = AIAssistantFoldLabel(message.getRole())
private val content: BorderLayoutPanel
Expand Down

0 comments on commit 1c7429d

Please sign in to comment.