mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-12 05:51:28 +00:00
63 lines
2.4 KiB
Kotlin
63 lines
2.4 KiB
Kotlin
package ee.carlrobert.codegpt.actions
|
|
|
|
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
|
import com.intellij.openapi.actionSystem.AnActionEvent
|
|
import com.intellij.openapi.components.service
|
|
import com.intellij.openapi.project.DumbAwareAction
|
|
import ee.carlrobert.codegpt.codecompletions.CodeCompletionService
|
|
import ee.carlrobert.codegpt.settings.GeneralSettings
|
|
import ee.carlrobert.codegpt.settings.service.ServiceType.*
|
|
import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTServiceSettings
|
|
import ee.carlrobert.codegpt.settings.service.custom.CustomServiceSettings
|
|
import ee.carlrobert.codegpt.settings.service.llama.LlamaSettings
|
|
import ee.carlrobert.codegpt.settings.service.ollama.OllamaSettings
|
|
import ee.carlrobert.codegpt.settings.service.openai.OpenAISettings
|
|
|
|
abstract class CodeCompletionFeatureToggleActions(
|
|
private val enableFeatureAction: Boolean
|
|
) : DumbAwareAction() {
|
|
|
|
override fun actionPerformed(e: AnActionEvent) = when (GeneralSettings.getSelectedService()) {
|
|
CODEGPT -> service<CodeGPTServiceSettings>().state.codeCompletionSettings::codeCompletionsEnabled::set
|
|
|
|
OPENAI -> OpenAISettings.getCurrentState()::setCodeCompletionsEnabled
|
|
|
|
LLAMA_CPP -> LlamaSettings.getCurrentState()::setCodeCompletionsEnabled
|
|
|
|
OLLAMA -> service<OllamaSettings>().state::codeCompletionsEnabled::set
|
|
|
|
CUSTOM_OPENAI -> service<CustomServiceSettings>().state.codeCompletionSettings::codeCompletionsEnabled::set
|
|
|
|
ANTHROPIC,
|
|
AZURE,
|
|
GOOGLE,
|
|
null -> { _: Boolean -> Unit } // no-op for these services
|
|
}(enableFeatureAction)
|
|
|
|
override fun update(e: AnActionEvent) {
|
|
val selectedService = GeneralSettings.getSelectedService()
|
|
val codeCompletionEnabled =
|
|
e.project?.service<CodeCompletionService>()?.isCodeCompletionsEnabled(selectedService) ?: false
|
|
e.presentation.isVisible = codeCompletionEnabled != enableFeatureAction
|
|
e.presentation.isEnabled = when (selectedService) {
|
|
CODEGPT,
|
|
OPENAI,
|
|
CUSTOM_OPENAI,
|
|
LLAMA_CPP,
|
|
OLLAMA -> true
|
|
|
|
ANTHROPIC,
|
|
AZURE,
|
|
GOOGLE,
|
|
null -> false
|
|
}
|
|
}
|
|
|
|
override fun getActionUpdateThread(): ActionUpdateThread {
|
|
return ActionUpdateThread.BGT
|
|
}
|
|
}
|
|
|
|
class EnableCompletionsAction : CodeCompletionFeatureToggleActions(true)
|
|
|
|
class DisableCompletionsAction : CodeCompletionFeatureToggleActions(false)
|