From 9fa5e1165cdc3b28519c2f13e56b6de505e16d0d Mon Sep 17 00:00:00 2001 From: reymondzzzz Date: Mon, 23 Oct 2023 17:42:32 +0300 Subject: [PATCH 1/2] add force completion --- src/call_validation.rs | 2 ++ src/http_server.rs | 18 ++++++++++-------- src/lsp.rs | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/call_validation.rs b/src/call_validation.rs index 44f86d94b..287a39f0f 100644 --- a/src/call_validation.rs +++ b/src/call_validation.rs @@ -37,6 +37,8 @@ pub struct CodeCompletionPost { pub scratchpad: String, #[serde(default)] pub stream: bool, + #[serde(default)] + pub no_cache: bool, } #[derive(Debug, Deserialize, Clone)] diff --git a/src/http_server.rs b/src/http_server.rs index d02c791ec..331f3a996 100644 --- a/src/http_server.rs +++ b/src/http_server.rs @@ -128,14 +128,16 @@ pub async fn handle_v1_code_completion( let cache_arc = global_context.read().await.completions_cache.clone(); let tele_storage = global_context.read().await.telemetry.clone(); - let cache_key = completion_cache::cache_key_from_post(&code_completion_post); - let cached_maybe = completion_cache::cache_get(cache_arc.clone(), cache_key.clone()); - if let Some(cached_json_value) = cached_maybe { - // info!("cache hit for key {:?}", cache_key.clone()); - if !code_completion_post.stream { - return crate::restream::cached_not_stream(&cached_json_value).await; - } else { - return crate::restream::cached_stream(&cached_json_value).await; + if (!code_completion_post.no_cache) { + let cache_key = completion_cache::cache_key_from_post(&code_completion_post); + let cached_maybe = completion_cache::cache_get(cache_arc.clone(), cache_key.clone()); + if let Some(cached_json_value) = cached_maybe { + // info!("cache hit for key {:?}", cache_key.clone()); + if !code_completion_post.stream { + return crate::restream::cached_not_stream(&cached_json_value).await; + } else { + return crate::restream::cached_stream(&cached_json_value).await; + } } } diff --git a/src/lsp.rs b/src/lsp.rs index 7bc4054ec..e28db816f 100644 --- a/src/lsp.rs +++ b/src/lsp.rs @@ -126,7 +126,8 @@ impl Backend { model: "".to_string(), scratchpad: "".to_string(), stream: false, - } + no_cache: false + }) } pub async fn get_completions(&self, params: CompletionParams1) -> Result { From 7394f0913cb8f5eb98a1d7f58c69f404ea3c64be Mon Sep 17 00:00:00 2001 From: reymondzzzz Date: Mon, 23 Oct 2023 17:52:55 +0300 Subject: [PATCH 2/2] typo --- src/lsp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lsp.rs b/src/lsp.rs index e28db816f..7898e8427 100644 --- a/src/lsp.rs +++ b/src/lsp.rs @@ -127,7 +127,7 @@ impl Backend { scratchpad: "".to_string(), stream: false, no_cache: false - }) + } } pub async fn get_completions(&self, params: CompletionParams1) -> Result {