Skip to content

Commit

Permalink
chore(kotlin): refactor and add UI components for improved LLM settin…
Browse files Browse the repository at this point in the history
…gs management.
  • Loading branch information
phodal committed May 11, 2024
1 parent d889c77 commit 0e83c76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -66,7 +68,6 @@ class LLMSettingComponent(private val settings: AutoDevSettingsState) {
}
) {
override fun createEditor(): EditorEx {

return super.createEditor().apply {
setShowPlaceholderWhenFocused(true)
setHorizontalScrollbarVisible(false)
Expand All @@ -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<AIEngines, List<LLMParam>>(
Expand Down Expand Up @@ -184,15 +187,15 @@ 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 <a>Open Log for Debug</a>") {
RevealFileAction.openFile(LoggerFactory.getLogFilePath())
}
}
})
.addLLMParams(currentLLMParams)
.addComponent(com.intellij.ui.dsl.builder.panel {
.addComponent(panel {
testLLMConnection(project)
})
.addVerticalGap(2)
Expand Down

0 comments on commit 0e83c76

Please sign in to comment.