diff --git a/crates/lsp-ai/src/config.rs b/crates/lsp-ai/src/config.rs index ea9631f..b89fdd3 100644 --- a/crates/lsp-ai/src/config.rs +++ b/crates/lsp-ai/src/config.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use std::collections::HashMap; -pub type Kwargs = HashMap; +pub(crate) type Kwargs = HashMap; const fn max_requests_per_second_default() -> f32 { 1. @@ -79,7 +79,7 @@ pub enum ValidMemoryBackend { #[derive(Debug, Clone, Deserialize)] #[serde(tag = "type")] -pub enum ValidModel { +pub(crate) enum ValidModel { #[cfg(feature = "llama_cpp")] #[serde(rename = "llama_cpp")] LLaMACPP(LLaMACPP), @@ -97,13 +97,13 @@ pub enum ValidModel { #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(deny_unknown_fields)] -pub struct ChatMessage { - pub role: String, - pub content: String, +pub(crate) struct ChatMessage { + pub(crate) role: String, + pub(crate) content: String, } impl ChatMessage { - pub fn new(role: String, content: String) -> Self { + pub(crate) fn new(role: String, content: String) -> Self { Self { role, content, @@ -115,10 +115,10 @@ impl ChatMessage { #[derive(Clone, Debug, Deserialize)] #[allow(clippy::upper_case_acronyms)] #[serde(deny_unknown_fields)] -pub struct FIM { - pub start: String, - pub middle: String, - pub end: String, +pub(crate) struct FIM { + pub(crate) start: String, + pub(crate) middle: String, + pub(crate) end: String, } const fn max_crawl_memory_default() -> u64 { @@ -131,13 +131,13 @@ const fn max_crawl_file_size_default() -> u64 { #[derive(Clone, Debug, Deserialize)] #[serde(deny_unknown_fields)] -pub struct Crawl { +pub(crate) struct Crawl { #[serde(default = "max_crawl_file_size_default")] - pub max_file_size: u64, + pub(crate) max_file_size: u64, #[serde(default = "max_crawl_memory_default")] - pub max_crawl_memory: u64, + pub(crate) max_crawl_memory: u64, #[serde(default)] - pub all_files: bool, + pub(crate) all_files: bool, } #[derive(Clone, Debug, Deserialize)] @@ -149,18 +149,18 @@ pub struct PostgresMLEmbeddingModel { #[derive(Clone, Debug, Deserialize)] #[serde(deny_unknown_fields)] -pub struct PostgresML { - pub database_url: Option, - pub crawl: Option, +pub(crate) struct PostgresML { + pub(crate) database_url: Option, + pub(crate) crawl: Option, #[serde(default)] - pub splitter: ValidSplitter, - pub embedding_model: Option, + pub(crate) splitter: ValidSplitter, + pub(crate) embedding_model: Option, } #[derive(Clone, Debug, Deserialize, Default)] #[serde(deny_unknown_fields)] -pub struct FileStore { - pub crawl: Option, +pub(crate) struct FileStore { + pub(crate) crawl: Option, } impl FileStore { @@ -265,11 +265,12 @@ pub struct Gemini { #[derive(Clone, Debug, Deserialize)] #[serde(deny_unknown_fields)] -pub struct Anthropic { +pub(crate) struct Anthropic { // The auth token env var name pub auth_token_env_var_name: Option, pub auth_token: Option, // The completions endpoint + #[allow(dead_code)] pub completions_endpoint: Option, // The chat endpoint pub chat_endpoint: Option, @@ -295,7 +296,7 @@ pub struct Completion { #[derive(Clone, Debug, Deserialize)] #[serde(deny_unknown_fields)] pub struct ValidConfig { - pub memory: ValidMemoryBackend, + pub(crate) memory: ValidMemoryBackend, pub models: HashMap, pub completion: Option, } @@ -308,8 +309,8 @@ pub struct ValidClientParams { #[derive(Clone, Debug)] pub struct Config { - pub config: ValidConfig, - pub client_params: ValidClientParams, + pub(crate) config: ValidConfig, + pub(crate) client_params: ValidClientParams, } impl Config { diff --git a/crates/lsp-ai/src/crawl.rs b/crates/lsp-ai/src/crawl.rs index 2dc1721..4546d2c 100644 --- a/crates/lsp-ai/src/crawl.rs +++ b/crates/lsp-ai/src/crawl.rs @@ -12,7 +12,7 @@ pub struct Crawl { } impl Crawl { - pub fn new(crawl_config: config::Crawl, config: Config) -> Self { + pub(crate) fn new(crawl_config: config::Crawl, config: Config) -> Self { Self { crawl_config, config, diff --git a/crates/lsp-ai/src/custom_requests/generation.rs b/crates/lsp-ai/src/custom_requests/generation.rs index 725cccb..48923c1 100644 --- a/crates/lsp-ai/src/custom_requests/generation.rs +++ b/crates/lsp-ai/src/custom_requests/generation.rs @@ -4,28 +4,28 @@ use serde_json::Value; use crate::config; -pub enum Generation {} +pub(crate) enum Generation {} #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] -pub struct GenerationParams { +pub(crate) struct GenerationParams { // This field was "mixed-in" from TextDocumentPositionParams #[serde(flatten)] - pub text_document_position: TextDocumentPositionParams, + pub(crate) text_document_position: TextDocumentPositionParams, // The model key to use - pub model: String, + pub(crate) model: String, #[serde(default)] // Args are deserialized by the backend using them - pub parameters: Value, + pub(crate) parameters: Value, // Parameters for post processing #[serde(default)] - pub post_process: config::PostProcess, + pub(crate) post_process: config::PostProcess, } #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] -pub struct GenerateResult { - pub generated_text: String, +pub(crate) struct GenerateResult { + pub(crate) generated_text: String, } impl lsp_types::request::Request for Generation { diff --git a/crates/lsp-ai/src/custom_requests/generation_stream.rs b/crates/lsp-ai/src/custom_requests/generation_stream.rs index 1c19a55..a09ed30 100644 --- a/crates/lsp-ai/src/custom_requests/generation_stream.rs +++ b/crates/lsp-ai/src/custom_requests/generation_stream.rs @@ -1,7 +1,7 @@ use lsp_types::{ProgressToken, TextDocumentPositionParams}; use serde::{Deserialize, Serialize}; -pub enum GenerationStream {} +pub(crate) enum GenerationStream {} #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] @@ -15,9 +15,9 @@ pub struct GenerationStreamParams { #[derive(Debug, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] -pub struct GenerationStreamResult { - pub generated_text: String, - pub partial_result_token: ProgressToken, +pub(crate) struct GenerationStreamResult { + pub(crate) generated_text: String, + pub(crate) partial_result_token: ProgressToken, } impl lsp_types::request::Request for GenerationStream { diff --git a/crates/lsp-ai/src/custom_requests/mod.rs b/crates/lsp-ai/src/custom_requests/mod.rs index a62b6e4..e4e0041 100644 --- a/crates/lsp-ai/src/custom_requests/mod.rs +++ b/crates/lsp-ai/src/custom_requests/mod.rs @@ -1,2 +1,2 @@ -pub mod generation; -pub mod generation_stream; +pub(crate) mod generation; +pub(crate) mod generation_stream; diff --git a/crates/lsp-ai/src/memory_backends/file_store.rs b/crates/lsp-ai/src/memory_backends/file_store.rs index 45abb7e..f37ff58 100644 --- a/crates/lsp-ai/src/memory_backends/file_store.rs +++ b/crates/lsp-ai/src/memory_backends/file_store.rs @@ -17,12 +17,12 @@ use crate::{ use super::{ContextAndCodePrompt, FIMPrompt, MemoryBackend, MemoryRunParams, Prompt, PromptType}; #[derive(Default)] -pub struct AdditionalFileStoreParams { +pub(crate) struct AdditionalFileStoreParams { build_tree: bool, } impl AdditionalFileStoreParams { - pub fn new(build_tree: bool) -> Self { + pub(crate) fn new(build_tree: bool) -> Self { Self { build_tree } } } @@ -47,7 +47,7 @@ impl File { } } -pub struct FileStore { +pub(crate) struct FileStore { params: AdditionalFileStoreParams, file_map: Mutex>, accessed_files: Mutex>, @@ -55,7 +55,10 @@ pub struct FileStore { } impl FileStore { - pub fn new(mut file_store_config: config::FileStore, config: Config) -> anyhow::Result { + pub(crate) fn new( + mut file_store_config: config::FileStore, + config: Config, + ) -> anyhow::Result { let crawl = file_store_config .crawl .take() @@ -72,7 +75,7 @@ impl FileStore { Ok(s) } - pub fn new_with_params( + pub(crate) fn new_with_params( mut file_store_config: config::FileStore, config: Config, params: AdditionalFileStoreParams, @@ -192,7 +195,7 @@ impl FileStore { Ok((rope, cursor_index)) } - pub fn get_characters_around_position( + pub(crate) fn get_characters_around_position( &self, position: &TextDocumentPositionParams, characters: usize, @@ -216,7 +219,7 @@ impl FileStore { Ok(rope_slice.to_string()) } - pub fn build_code( + pub(crate) fn build_code( &self, position: &TextDocumentPositionParams, prompt_type: PromptType, @@ -272,15 +275,18 @@ impl FileStore { }) } - pub fn file_map(&self) -> &Mutex> { + pub(crate) fn file_map(&self) -> &Mutex> { &self.file_map } - pub fn contains_file(&self, uri: &str) -> bool { + pub(crate) fn contains_file(&self, uri: &str) -> bool { self.file_map.lock().contains_key(uri) } - pub fn position_to_byte(&self, position: &TextDocumentPositionParams) -> anyhow::Result { + pub(crate) fn position_to_byte( + &self, + position: &TextDocumentPositionParams, + ) -> anyhow::Result { let file_map = self.file_map.lock(); let uri = position.text_document.uri.to_string(); let file = file_map diff --git a/crates/lsp-ai/src/memory_backends/mod.rs b/crates/lsp-ai/src/memory_backends/mod.rs index 9d6fcc5..8fa5914 100644 --- a/crates/lsp-ai/src/memory_backends/mod.rs +++ b/crates/lsp-ai/src/memory_backends/mod.rs @@ -6,7 +6,7 @@ use serde_json::Value; use crate::config::{Config, ValidMemoryBackend}; -pub mod file_store; +pub(crate) mod file_store; mod postgresml; #[derive(Clone, Debug)] @@ -16,9 +16,9 @@ pub enum PromptType { } #[derive(Clone)] -pub struct MemoryRunParams { - pub is_for_chat: bool, - pub max_context: usize, +pub(crate) struct MemoryRunParams { + pub(crate) is_for_chat: bool, + pub(crate) max_context: usize, } impl From<&Value> for MemoryRunParams { diff --git a/crates/lsp-ai/src/memory_backends/postgresml/mod.rs b/crates/lsp-ai/src/memory_backends/postgresml/mod.rs index 2c08065..255350d 100644 --- a/crates/lsp-ai/src/memory_backends/postgresml/mod.rs +++ b/crates/lsp-ai/src/memory_backends/postgresml/mod.rs @@ -84,7 +84,7 @@ async fn split_and_upsert_file( } #[derive(Clone)] -pub struct PostgresML { +pub(crate) struct PostgresML { config: Config, postgresml_config: config::PostgresML, file_store: Arc, @@ -240,12 +240,7 @@ impl PostgresML { }) .collect(); if let Err(e) = task_collection - .delete_documents( - json!({ - "$or": delete_or_statements - }) - .into(), - ) + .delete_documents(json!({ "$or": delete_or_statements }).into()) .await .context("PGML - error deleting documents") { diff --git a/crates/lsp-ai/src/memory_worker.rs b/crates/lsp-ai/src/memory_worker.rs index 1b7a481..38b6127 100644 --- a/crates/lsp-ai/src/memory_worker.rs +++ b/crates/lsp-ai/src/memory_worker.rs @@ -13,7 +13,7 @@ use crate::{ }; #[derive(Debug)] -pub struct PromptRequest { +pub(crate) struct PromptRequest { position: TextDocumentPositionParams, prompt_type: PromptType, params: Value, @@ -21,7 +21,7 @@ pub struct PromptRequest { } impl PromptRequest { - pub fn new( + pub(crate) fn new( position: TextDocumentPositionParams, prompt_type: PromptType, params: Value, @@ -37,13 +37,13 @@ impl PromptRequest { } #[derive(Debug)] -pub struct FilterRequest { +pub(crate) struct FilterRequest { position: TextDocumentPositionParams, tx: tokio::sync::oneshot::Sender, } impl FilterRequest { - pub fn new( + pub(crate) fn new( position: TextDocumentPositionParams, tx: tokio::sync::oneshot::Sender, ) -> Self { @@ -51,7 +51,7 @@ impl FilterRequest { } } -pub enum WorkerRequest { +pub(crate) enum WorkerRequest { FilterText(FilterRequest), Prompt(PromptRequest), DidOpenTextDocument(DidOpenTextDocumentParams), @@ -115,7 +115,7 @@ fn do_run( } } -pub fn run( +pub(crate) fn run( memory_backend: Box, rx: std::sync::mpsc::Receiver, ) { diff --git a/crates/lsp-ai/src/splitters/text_splitter.rs b/crates/lsp-ai/src/splitters/text_splitter.rs index 9b280a1..ba52e04 100644 --- a/crates/lsp-ai/src/splitters/text_splitter.rs +++ b/crates/lsp-ai/src/splitters/text_splitter.rs @@ -8,14 +8,14 @@ pub struct TextSplitter { } impl TextSplitter { - pub fn new(config: config::TextSplitter) -> Self { + pub(crate) fn new(config: config::TextSplitter) -> Self { Self { chunk_size: config.chunk_size, splitter: text_splitter::TextSplitter::new(config.chunk_size), } } - pub fn new_with_chunk_size(chunk_size: usize) -> Self { + pub(crate) fn new_with_chunk_size(chunk_size: usize) -> Self { Self { chunk_size, splitter: text_splitter::TextSplitter::new(chunk_size), diff --git a/crates/lsp-ai/src/splitters/tree_sitter.rs b/crates/lsp-ai/src/splitters/tree_sitter.rs index dbbb9ce..7cda4d8 100644 --- a/crates/lsp-ai/src/splitters/tree_sitter.rs +++ b/crates/lsp-ai/src/splitters/tree_sitter.rs @@ -6,14 +6,14 @@ use crate::{config, memory_backends::file_store::File, utils::parse_tree}; use super::{text_splitter::TextSplitter, ByteRange, Chunk, Splitter}; -pub struct TreeSitter { +pub(crate) struct TreeSitter { chunk_size: usize, splitter: TreeSitterCodeSplitter, text_splitter: TextSplitter, } impl TreeSitter { - pub fn new(config: config::TreeSitter) -> anyhow::Result { + pub(crate) fn new(config: config::TreeSitter) -> anyhow::Result { let text_splitter = TextSplitter::new_with_chunk_size(config.chunk_size); Ok(Self { chunk_size: config.chunk_size, diff --git a/crates/lsp-ai/src/transformer_backends/anthropic.rs b/crates/lsp-ai/src/transformer_backends/anthropic.rs index 58f9ffb..cb07a03 100644 --- a/crates/lsp-ai/src/transformer_backends/anthropic.rs +++ b/crates/lsp-ai/src/transformer_backends/anthropic.rs @@ -30,15 +30,15 @@ const fn temperature_default() -> f32 { // NOTE: We cannot deny unknown fields as the provided parameters may contain other fields relevant to other processes #[derive(Debug, Deserialize)] -pub struct AnthropicRunParams { +pub(crate) struct AnthropicRunParams { system: String, messages: Vec, #[serde(default = "max_tokens_default")] - pub max_tokens: usize, + pub(crate) max_tokens: usize, #[serde(default = "top_p_default")] - pub top_p: f32, + pub(crate) top_p: f32, #[serde(default = "temperature_default")] - pub temperature: f32, + pub(crate) temperature: f32, } pub struct Anthropic { @@ -56,11 +56,11 @@ struct AnthropicChatResponse { error: Option, #[serde(default)] #[serde(flatten)] - pub other: HashMap, + pub(crate) other: HashMap, } impl Anthropic { - pub fn new(config: config::Anthropic) -> Self { + pub(crate) fn new(config: config::Anthropic) -> Self { Self { config } } diff --git a/crates/lsp-ai/src/transformer_backends/gemini.rs b/crates/lsp-ai/src/transformer_backends/gemini.rs index 3203c48..5b0c696 100644 --- a/crates/lsp-ai/src/transformer_backends/gemini.rs +++ b/crates/lsp-ai/src/transformer_backends/gemini.rs @@ -39,7 +39,7 @@ const fn max_tokens_default() -> usize { #[derive(Debug, Serialize, Deserialize, Clone)] struct Part { - pub text: String, + pub(crate) text: String, } #[derive(Debug, Serialize, Deserialize, Clone)]