Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import co.huggingface.llmintellij.lsp.LlmLsServerSupportProvider
import co.huggingface.llmintellij.lsp.Position
import com.intellij.codeInsight.inline.completion.InlineCompletionElement
import com.intellij.codeInsight.inline.completion.InlineCompletionEvent
import com.intellij.codeInsight.inline.completion.InlineCompletionProvider
import com.intellij.codeInsight.inline.completion.DebouncedInlineCompletionProvider
import com.intellij.codeInsight.inline.completion.InlineCompletionRequest
import com.intellij.openapi.diagnostic.Logger
import com.intellij.platform.lsp.api.LspServerManager
Expand All @@ -16,17 +16,25 @@ import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.launch
import kotlin.time.Duration
import kotlin.time.DurationUnit
import kotlin.time.toDuration

class LlmLsCompletionProvider: InlineCompletionProvider {
class LlmLsCompletionProvider : DebouncedInlineCompletionProvider() {
override var delay: Duration = 500.toDuration(DurationUnit.MILLISECONDS)
private val logger = Logger.getInstance("inlineCompletion")
override fun force(request: InlineCompletionRequest): Boolean {
return false
}

override suspend fun getProposals(request: InlineCompletionRequest): Flow<InlineCompletionElement> =
override suspend fun getProposalsDebounced(request: InlineCompletionRequest): Flow<InlineCompletionElement> =
channelFlow {
val project = request.editor.project
if (project == null) {
logger.error("could not find project")
} else {
val settings = LlmSettingsState.instance
delay = settings.debounceDelay
val secrets = SecretsService.instance
val lspServer = LspServerManager.getInstance(project).getServersForProvider(LlmLsServerSupportProvider::class.java).firstOrNull()
if (lspServer != null) {
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/co/huggingface/llmintellij/LlmSettingsComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.event.DocumentEvent
import javax.swing.event.DocumentListener
import kotlin.time.Duration
import kotlin.time.DurationUnit
import kotlin.time.toDuration

class LlmSettingsComponent {
val rootPanel: JPanel = JPanel()
Expand All @@ -41,6 +44,8 @@ class LlmSettingsComponent {
private val fimSuffixLabel: JBLabel
private val fimSuffix: JBTextField
private val tlsSkipVerifyInsecure: JBCheckBox
private val debounceDelayLabel: JBLabel
private val debounceDelay: JBTextField
private val lspBinaryPath: TextFieldWithBrowseButton
private val lspVersionLabel: JBLabel
private val lspVersion: JBTextField
Expand Down Expand Up @@ -218,6 +223,11 @@ class LlmSettingsComponent {
llmLsSubsectionPanel.add(lspLogLevelLabel)
llmLsSubsectionPanel.add(lspLogLevel)

val pluginSettingsPanel = createSectionPanel("Plugin settings", rootPanel)
debounceDelayLabel = JBLabel("Debounce delay in milliseconds")
debounceDelay = JBTextField("500")
pluginSettingsPanel.add(debounceDelayLabel)
pluginSettingsPanel.add(debounceDelay)
}

val preferredFocusedComponent: JComponent
Expand Down Expand Up @@ -353,6 +363,14 @@ class LlmSettingsComponent {
lspLogLevel.text = value
}

fun getDebounceDelay(): Duration {
return debounceDelay.text.toInt().toDuration(DurationUnit.MILLISECONDS)
}

fun setDebounceDelay(value: Duration) {
debounceDelay.text = value.inWholeMilliseconds.toString()
}

fun getLspBinaryPath(): String? {
val binaryPath = lspBinaryPath.text
return if (binaryPath == "") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package co.huggingface.llmintellij
import com.intellij.openapi.options.Configurable
import org.jetbrains.annotations.Nls
import javax.swing.JComponent
import kotlin.time.DurationUnit
import kotlin.time.toDuration


class LlmSettingsConfigurable : Configurable {
Expand Down Expand Up @@ -38,6 +40,7 @@ class LlmSettingsConfigurable : Configurable {
modified = modified or (settingsComponent?.getFimMiddle() != settings.fim.middle)
modified = modified or (settingsComponent?.getFimSuffix() != settings.fim.suffix)
modified = modified or (settingsComponent?.isTlsSkipVerifyInsecureEnabled() != settings.tlsSkipVerifyInsecure)
modified = modified or (settingsComponent?.getDebounceDelay() != settings.debounceDelay)
modified = modified or (settingsComponent?.getLspBinaryPath() != settings.lsp.binaryPath)
modified = modified or (settingsComponent?.getLspVersion() != settings.lsp.version)
modified = modified or (settingsComponent?.getLspLogLevel() != settings.lsp.logLevel)
Expand All @@ -60,6 +63,7 @@ class LlmSettingsConfigurable : Configurable {
settings.fim.middle = settingsComponent?.getFimMiddle() ?: ""
settings.fim.suffix = settingsComponent?.getFimSuffix() ?: ""
settings.tlsSkipVerifyInsecure = settingsComponent?.isTlsSkipVerifyInsecureEnabled() ?: false
settings.debounceDelay = settingsComponent?.getDebounceDelay() ?: 500.toDuration(DurationUnit.MILLISECONDS)
settings.lsp.binaryPath = settingsComponent?.getLspBinaryPath()
settings.lsp.version = settingsComponent?.getLspVersion() ?: ""
settings.lsp.logLevel = settingsComponent?.getLspLogLevel() ?: ""
Expand All @@ -81,6 +85,7 @@ class LlmSettingsConfigurable : Configurable {
settingsComponent?.setFimMiddle(settings.fim.middle)
settingsComponent?.setFimSuffix(settings.fim.suffix)
settingsComponent?.setTlsSkipVerifyInsecureStatus(settings.tlsSkipVerifyInsecure)
settingsComponent?.setDebounceDelay(settings.debounceDelay)
settingsComponent?.setLspBinaryPath(settings.lsp.binaryPath ?: "")
settingsComponent?.setLspVersion(settings.lsp.version)
settingsComponent?.setLspLogLevel(settings.lsp.logLevel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import com.intellij.util.xmlb.XmlSerializerUtil
import kotlin.time.DurationUnit
import kotlin.time.toDuration


class LspSettings {
Expand Down Expand Up @@ -45,6 +47,7 @@ class LlmSettingsState: PersistentStateComponent<LlmSettingsState?> {
var queryParams = QueryParams()
var fim = FimParams()
var tlsSkipVerifyInsecure = false
var debounceDelay = 500.toDuration(DurationUnit.MILLISECONDS)
var lsp = LspSettings()
var tokenizer: TokenizerConfig? = TokenizerConfig.HuggingFace("bigcode/starcoder")
var contextWindow = 8192u
Expand Down