diff --git a/src/main/java/ee/carlrobert/codegpt/settings/configuration/ConfigurationComponent.java b/src/main/java/ee/carlrobert/codegpt/settings/configuration/ConfigurationComponent.java index 3ff53886..b86c7c34 100644 --- a/src/main/java/ee/carlrobert/codegpt/settings/configuration/ConfigurationComponent.java +++ b/src/main/java/ee/carlrobert/codegpt/settings/configuration/ConfigurationComponent.java @@ -28,6 +28,7 @@ public class ConfigurationComponent { private final IntegerField maxTokensField; private final JBTextField temperatureField; private final CodeCompletionConfigurationForm codeCompletionForm; + private final ChatCompletionConfigurationForm chatCompletionForm; public ConfigurationComponent( Disposable parentDisposable, @@ -72,6 +73,7 @@ public class ConfigurationComponent { configuration.getAutoFormattingEnabled()); codeCompletionForm = new CodeCompletionConfigurationForm(); + chatCompletionForm = new ChatCompletionConfigurationForm(); mainPanel = FormBuilder.createFormBuilder() .addComponent(checkForPluginUpdatesCheckBox) @@ -85,6 +87,9 @@ public class ConfigurationComponent { .addComponent(new TitledSeparator( CodeGPTBundle.get("configurationConfigurable.section.codeCompletion.title"))) .addComponent(codeCompletionForm.createPanel()) + .addComponent(new TitledSeparator( + CodeGPTBundle.get("configurationConfigurable.section.chatCompletion.title"))) + .addComponent(chatCompletionForm.createPanel()) .addComponentFillVertically(new JPanel(), 0) .getPanel(); } @@ -102,6 +107,7 @@ public class ConfigurationComponent { state.setMethodNameGenerationEnabled(methodNameGenerationCheckBox.isSelected()); state.setAutoFormattingEnabled(autoFormattingCheckBox.isSelected()); state.setCodeCompletionSettings(codeCompletionForm.getFormState()); + state.setChatCompletionSettings(chatCompletionForm.getFormState()); return state; } @@ -114,6 +120,7 @@ public class ConfigurationComponent { methodNameGenerationCheckBox.setSelected(configuration.getMethodNameGenerationEnabled()); autoFormattingCheckBox.setSelected(configuration.getAutoFormattingEnabled()); codeCompletionForm.resetForm(configuration.getCodeCompletionSettings()); + chatCompletionForm.resetForm(configuration.getChatCompletionSettings()); } // Formatted keys are not referenced in the messages bundle file diff --git a/src/main/java/ee/carlrobert/codegpt/settings/configuration/ConfigurationConfigurable.java b/src/main/java/ee/carlrobert/codegpt/settings/configuration/ConfigurationConfigurable.java index f6125261..7d1fd9e3 100644 --- a/src/main/java/ee/carlrobert/codegpt/settings/configuration/ConfigurationConfigurable.java +++ b/src/main/java/ee/carlrobert/codegpt/settings/configuration/ConfigurationConfigurable.java @@ -5,7 +5,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.util.Disposer; import ee.carlrobert.codegpt.CodeGPTBundle; -import ee.carlrobert.codegpt.actions.editor.EditorActionsUtil; import javax.swing.JComponent; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nullable; @@ -39,8 +38,12 @@ public class ConfigurationConfigurable implements Configurable { @Override public void apply() { - ApplicationManager.getApplication().getService(ConfigurationSettings.class) - .loadState(component.getCurrentFormState()); + var application = ApplicationManager.getApplication(); + var state = component.getCurrentFormState(); + application.getService(ConfigurationSettings.class).loadState(state); + application.getMessageBus() + .syncPublisher(ConfigurationStateListener.Companion.getTOPIC()) + .onConfigurationChanged(state); } @Override diff --git a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/structure/data/PsiStructureRepository.kt b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/structure/data/PsiStructureRepository.kt index 50a897f7..4cd59169 100644 --- a/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/structure/data/PsiStructureRepository.kt +++ b/src/main/java/ee/carlrobert/codegpt/toolwindow/chat/structure/data/PsiStructureRepository.kt @@ -12,7 +12,7 @@ import com.intellij.psi.PsiFile import com.intellij.psi.PsiManager import com.intellij.util.io.await import ee.carlrobert.codegpt.psistructure.PsiStructureProvider -import ee.carlrobert.codegpt.settings.chat.ChatSettingsListener +import ee.carlrobert.codegpt.settings.configuration.ConfigurationStateListener import ee.carlrobert.codegpt.ui.textarea.header.tag.CurrentGitChangesTagDetails import ee.carlrobert.codegpt.ui.textarea.header.tag.DocumentationTagDetails import ee.carlrobert.codegpt.ui.textarea.header.tag.EditorSelectionTagDetails @@ -119,9 +119,9 @@ class PsiStructureRepository( .connect(parentDisposable) connection.subscribe( - ChatSettingsListener.TOPIC, - ChatSettingsListener { newState -> - if (newState.psiStructureEnabled) { + ConfigurationStateListener.TOPIC, + ConfigurationStateListener { newState -> + if (newState.chatCompletionSettings.psiStructureEnabled) { enable() } else { disable() diff --git a/src/main/kotlin/ee/carlrobert/codegpt/settings/chat/ChatConfigurationConfigurable.kt b/src/main/kotlin/ee/carlrobert/codegpt/settings/chat/ChatConfigurationConfigurable.kt deleted file mode 100644 index 00fbdb63..00000000 --- a/src/main/kotlin/ee/carlrobert/codegpt/settings/chat/ChatConfigurationConfigurable.kt +++ /dev/null @@ -1,62 +0,0 @@ -package ee.carlrobert.codegpt.settings.chat - -import com.intellij.openapi.components.service -import com.intellij.openapi.options.Configurable -import com.intellij.openapi.ui.DialogPanel -import com.intellij.ui.components.JBCheckBox -import com.intellij.ui.dsl.builder.panel -import ee.carlrobert.codegpt.CodeGPTBundle -import javax.swing.JComponent - -class ChatConfigurationConfigurable : Configurable { - - private val editorContextTagCheckBox = JBCheckBox( - CodeGPTBundle.get("chatConfigurationConfigurable.editorContextTag.title"), - service().state.editorContextTagEnabled - ) - - private val psiStructureCheckBox = JBCheckBox( - CodeGPTBundle.get("chatConfigurationConfigurable.psiStructure.title"), - service().state.psiStructureEnabled - ) - - fun createPanel(): DialogPanel { - return panel { - row { - cell(editorContextTagCheckBox) - .comment(CodeGPTBundle.get("chatConfigurationConfigurable.editorContextTag.description")) - } - row { - cell(psiStructureCheckBox) - .comment(CodeGPTBundle.get("chatConfigurationConfigurable.psiStructure.description")) - } - } - } - - fun resetForm(prevState: ChatSettingsState) { - editorContextTagCheckBox.isSelected = prevState.editorContextTagEnabled - psiStructureCheckBox.isSelected = prevState.psiStructureEnabled - } - - override fun createComponent(): JComponent = createPanel() - - override fun isModified(): Boolean { - return ChatSettingsState().apply { - editorContextTagEnabled = editorContextTagCheckBox.isSelected - psiStructureEnabled = psiStructureCheckBox.isSelected - } != service().state - } - - override fun apply() { - service().loadState( - ChatSettingsState().apply { - editorContextTagEnabled = editorContextTagCheckBox.isSelected - psiStructureEnabled = psiStructureCheckBox.isSelected - } - ) - } - - override fun getDisplayName(): String = - CodeGPTBundle.get("chatConfigurationConfigurable.displayName") - -} \ No newline at end of file diff --git a/src/main/kotlin/ee/carlrobert/codegpt/settings/chat/ChatSettings.kt b/src/main/kotlin/ee/carlrobert/codegpt/settings/chat/ChatSettings.kt deleted file mode 100644 index c608b6b3..00000000 --- a/src/main/kotlin/ee/carlrobert/codegpt/settings/chat/ChatSettings.kt +++ /dev/null @@ -1,29 +0,0 @@ -package ee.carlrobert.codegpt.settings.chat - -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.components.BaseState -import com.intellij.openapi.components.Service -import com.intellij.openapi.components.SimplePersistentStateComponent -import com.intellij.openapi.components.State -import com.intellij.openapi.components.Storage - -@Service -@State( - name = "ProxyAI_ChatSettings", - storages = [Storage("ProxyAI_ChatSettings.xml")] -) -class ChatSettings : - SimplePersistentStateComponent(ChatSettingsState()) { - - override fun loadState(state: ChatSettingsState) { - super.loadState(state) - ApplicationManager.getApplication().messageBus - .syncPublisher(ChatSettingsListener.TOPIC) - .onChatSettingsChanged(state) - } -} - -class ChatSettingsState : BaseState() { - var editorContextTagEnabled by property(true) - var psiStructureEnabled by property(true) -} diff --git a/src/main/kotlin/ee/carlrobert/codegpt/settings/chat/ChatSettingsListener.kt b/src/main/kotlin/ee/carlrobert/codegpt/settings/chat/ChatSettingsListener.kt deleted file mode 100644 index 2635d7f2..00000000 --- a/src/main/kotlin/ee/carlrobert/codegpt/settings/chat/ChatSettingsListener.kt +++ /dev/null @@ -1,11 +0,0 @@ -package ee.carlrobert.codegpt.settings.chat - -import com.intellij.util.messages.Topic - -fun interface ChatSettingsListener { - fun onChatSettingsChanged(newState: ChatSettingsState) - - companion object { - val TOPIC = Topic.create("Chat Settings Changed", ChatSettingsListener::class.java) - } -} \ No newline at end of file diff --git a/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/ChatCompletionConfigurationForm.kt b/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/ChatCompletionConfigurationForm.kt new file mode 100644 index 00000000..fe83a702 --- /dev/null +++ b/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/ChatCompletionConfigurationForm.kt @@ -0,0 +1,46 @@ +package ee.carlrobert.codegpt.settings.configuration + +import com.intellij.openapi.components.service +import com.intellij.openapi.ui.DialogPanel +import com.intellij.ui.components.JBCheckBox +import com.intellij.ui.dsl.builder.panel +import com.intellij.util.ui.JBUI +import ee.carlrobert.codegpt.CodeGPTBundle + +class ChatCompletionConfigurationForm { + + private val editorContextTagCheckBox = JBCheckBox( + CodeGPTBundle.get("configurationConfigurable.section.chatCompletion.editorContextTag.title"), + service().state.chatCompletionSettings.editorContextTagEnabled + ) + + private val psiStructureCheckBox = JBCheckBox( + CodeGPTBundle.get("configurationConfigurable.section.chatCompletion.psiStructure.title"), + service().state.chatCompletionSettings.psiStructureEnabled + ) + + fun createPanel(): DialogPanel { + return panel { + row { + cell(editorContextTagCheckBox) + .comment(CodeGPTBundle.get("configurationConfigurable.section.chatCompletion.editorContextTag.description")) + } + row { + cell(psiStructureCheckBox) + .comment(CodeGPTBundle.get("configurationConfigurable.section.chatCompletion.psiStructure.description")) + } + }.withBorder(JBUI.Borders.emptyLeft(16)) + } + + fun resetForm(prevState: ChatCompletionSettingsState) { + editorContextTagCheckBox.isSelected = prevState.editorContextTagEnabled + psiStructureCheckBox.isSelected = prevState.psiStructureEnabled + } + + fun getFormState(): ChatCompletionSettingsState { + return ChatCompletionSettingsState().apply { + this.editorContextTagEnabled = editorContextTagCheckBox.isSelected + this.psiStructureEnabled = psiStructureCheckBox.isSelected + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/CodeCompletionConfigurationForm.kt b/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/CodeCompletionConfigurationForm.kt index 4337d505..4c6e083f 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/CodeCompletionConfigurationForm.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/CodeCompletionConfigurationForm.kt @@ -4,6 +4,7 @@ import com.intellij.openapi.components.service import com.intellij.openapi.ui.DialogPanel import com.intellij.ui.components.JBCheckBox import com.intellij.ui.dsl.builder.panel +import com.intellij.util.ui.JBUI import ee.carlrobert.codegpt.CodeGPTBundle class CodeCompletionConfigurationForm { @@ -44,7 +45,7 @@ class CodeCompletionConfigurationForm { cell(collectDependencyStructureBox) .comment(CodeGPTBundle.get("configurationConfigurable.section.codeCompletion.collectDependencyStructure.description")) } - } + }.withBorder(JBUI.Borders.emptyLeft(16)) } fun resetForm(prevState: CodeCompletionSettingsState) { diff --git a/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/ConfigurationSettings.kt b/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/ConfigurationSettings.kt index 50533ca5..1e521f92 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/ConfigurationSettings.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/ConfigurationSettings.kt @@ -32,6 +32,7 @@ class ConfigurationSettingsState : BaseState() { var captureCompileErrors by property(true) var autoFormattingEnabled by property(true) var tableData by map() + var chatCompletionSettings by property(ChatCompletionSettingsState()) var codeCompletionSettings by property(CodeCompletionSettingsState()) init { @@ -39,6 +40,11 @@ class ConfigurationSettingsState : BaseState() { } } +class ChatCompletionSettingsState : BaseState() { + var editorContextTagEnabled by property(true) + var psiStructureEnabled by property(true) +} + class CodeCompletionSettingsState : BaseState() { var multiLineEnabled by property(true) var treeSitterProcessingEnabled by property(true) diff --git a/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/ConfigurationStateListener.kt b/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/ConfigurationStateListener.kt new file mode 100644 index 00000000..6f2b6110 --- /dev/null +++ b/src/main/kotlin/ee/carlrobert/codegpt/settings/configuration/ConfigurationStateListener.kt @@ -0,0 +1,12 @@ +package ee.carlrobert.codegpt.settings.configuration + +import com.intellij.util.messages.Topic + +fun interface ConfigurationStateListener { + fun onConfigurationChanged(newState: ConfigurationSettingsState) + + companion object { + val TOPIC: Topic = + Topic.create("Configuration Changed", ConfigurationStateListener::class.java) + } +} \ No newline at end of file diff --git a/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/header/tag/TagManager.kt b/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/header/tag/TagManager.kt index 73ce1c52..d8b50f62 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/header/tag/TagManager.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/ui/textarea/header/tag/TagManager.kt @@ -3,8 +3,8 @@ package ee.carlrobert.codegpt.ui.textarea.header.tag import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.service -import ee.carlrobert.codegpt.settings.chat.ChatSettings -import ee.carlrobert.codegpt.settings.chat.ChatSettingsListener +import ee.carlrobert.codegpt.settings.configuration.ConfigurationSettings +import ee.carlrobert.codegpt.settings.configuration.ConfigurationStateListener import java.util.concurrent.CopyOnWriteArraySet class TagManager(parentDisposable: Disposable) { @@ -17,9 +17,9 @@ class TagManager(parentDisposable: Disposable) { .connect(parentDisposable) connection.subscribe( - ChatSettingsListener.TOPIC, - ChatSettingsListener { newState -> - if (!newState.editorContextTagEnabled) { + ConfigurationStateListener.TOPIC, + ConfigurationStateListener { newState -> + if (!newState.chatCompletionSettings.editorContextTagEnabled) { clear() } }) @@ -37,7 +37,9 @@ class TagManager(parentDisposable: Disposable) { fun addTag(tagDetails: TagDetails) { val wasAdded = synchronized(this) { - if (!service().state.editorContextTagEnabled && isEditorTag(tagDetails)) return + if (!service().state.chatCompletionSettings.editorContextTagEnabled + && isEditorTag(tagDetails) + ) return if (tagDetails is EditorSelectionTagDetails) { tags.remove(tagDetails) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 14fed618..ea10c53c 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -54,8 +54,6 @@ instance="ee.carlrobert.codegpt.settings.documentation.DocumentationsConfigurable"/> -