From 0e83c76a04d2b4df2ba2b414b08e9581af057acb Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sat, 11 May 2024 09:29:39 +0800 Subject: [PATCH] chore(kotlin): refactor and add UI components for improved LLM settings management. --- gradle.properties | 2 +- .../devti/settings/LLMSettingComponent.kt | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 622175c031..0ef064f8c6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html propertiesPluginEnvironmentNameProperty=platformVersion # Supported platforms: 222, 233, 241 -platformVersion=233 +platformVersion=241 pluginGroup = com.phodal.autodev pluginName = AutoDev diff --git a/src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt b/src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt index 75fd9f7875..63656140ae 100644 --- a/src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt +++ b/src/main/kotlin/cc/unitmesh/devti/settings/LLMSettingComponent.kt @@ -12,8 +12,10 @@ import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.project.Project import com.intellij.openapi.project.ProjectManager import com.intellij.psi.PsiFile +import com.intellij.ui.EditorTextField import com.intellij.ui.LanguageTextField import com.intellij.ui.components.JBLabel +import com.intellij.ui.dsl.builder.panel import com.intellij.util.ui.FormBuilder import java.awt.Dimension import java.awt.FontMetrics @@ -53,8 +55,8 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) { val project = ProjectManager.getInstance().openProjects.firstOrNull() - private val customEnginePrompt by lazy { - object : LanguageTextField(JsonLanguage.INSTANCE, project, settings.customPrompts, + private val customEnginePrompt: EditorTextField by lazy { + class SettingJsonField : LanguageTextField(JsonLanguage.INSTANCE, project, settings.customPrompts, object : SimpleDocumentCreator() { override fun createDocument(value: String?, language: Language?, project: Project?): Document { return createDocument(value, language, project, this) @@ -66,7 +68,6 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) { } ) { override fun createEditor(): EditorEx { - return super.createEditor().apply { setShowPlaceholderWhenFocused(true) setHorizontalScrollbarVisible(false) @@ -78,11 +79,13 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) { val metrics: FontMetrics = getFontMetrics(font) val columnWidth = metrics.charWidth('m') - setOneLineMode(false) + isOneLineMode = false preferredSize = Dimension(25 * columnWidth, 25 * metrics.height) } } } + + SettingJsonField() } private val llmGroups = mapOf>( @@ -184,7 +187,7 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) { .addLLMParam(gitLabUrlParam) .addLLMParam(gitLabTokenParam) .addSeparator() - .addComponent(com.intellij.ui.dsl.builder.panel { + .addComponent(panel { row { comment("For OpenAI LLM, config OpenAI Key & OpenAI Model & Custom OpenAI Host Open Log for Debug") { RevealFileAction.openFile(LoggerFactory.getLogFilePath()) @@ -192,7 +195,7 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) { } }) .addLLMParams(currentLLMParams) - .addComponent(com.intellij.ui.dsl.builder.panel { + .addComponent(panel { testLLMConnection(project) }) .addVerticalGap(2)