Skip to content

Commit

Permalink
fix: visibilty warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
McPatate committed Jun 26, 2024
1 parent 972071c commit 3b286d5
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 78 deletions.
51 changes: 26 additions & 25 deletions crates/lsp-ai/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

pub type Kwargs = HashMap<String, Value>;
pub(crate) type Kwargs = HashMap<String, Value>;

const fn max_requests_per_second_default() -> f32 {
1.
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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)]
Expand All @@ -149,18 +149,18 @@ pub struct PostgresMLEmbeddingModel {

#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PostgresML {
pub database_url: Option<String>,
pub crawl: Option<Crawl>,
pub(crate) struct PostgresML {
pub(crate) database_url: Option<String>,
pub(crate) crawl: Option<Crawl>,
#[serde(default)]
pub splitter: ValidSplitter,
pub embedding_model: Option<PostgresMLEmbeddingModel>,
pub(crate) splitter: ValidSplitter,
pub(crate) embedding_model: Option<PostgresMLEmbeddingModel>,
}

#[derive(Clone, Debug, Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct FileStore {
pub crawl: Option<Crawl>,
pub(crate) struct FileStore {
pub(crate) crawl: Option<Crawl>,
}

impl FileStore {
Expand Down Expand Up @@ -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<String>,
pub auth_token: Option<String>,
// The completions endpoint
#[allow(dead_code)]
pub completions_endpoint: Option<String>,
// The chat endpoint
pub chat_endpoint: Option<String>,
Expand All @@ -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<String, ValidModel>,
pub completion: Option<Completion>,
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/lsp-ai/src/crawl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions crates/lsp-ai/src/custom_requests/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions crates/lsp-ai/src/custom_requests/generation_stream.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/lsp-ai/src/custom_requests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod generation;
pub mod generation_stream;
pub(crate) mod generation;
pub(crate) mod generation_stream;
26 changes: 16 additions & 10 deletions crates/lsp-ai/src/memory_backends/file_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
Expand All @@ -47,15 +47,18 @@ impl File {
}
}

pub struct FileStore {
pub(crate) struct FileStore {
params: AdditionalFileStoreParams,
file_map: Mutex<HashMap<String, File>>,
accessed_files: Mutex<IndexSet<String>>,
crawl: Option<Mutex<Crawl>>,
}

impl FileStore {
pub fn new(mut file_store_config: config::FileStore, config: Config) -> anyhow::Result<Self> {
pub(crate) fn new(
mut file_store_config: config::FileStore,
config: Config,
) -> anyhow::Result<Self> {
let crawl = file_store_config
.crawl
.take()
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -272,15 +275,18 @@ impl FileStore {
})
}

pub fn file_map(&self) -> &Mutex<HashMap<String, File>> {
pub(crate) fn file_map(&self) -> &Mutex<HashMap<String, File>> {
&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<usize> {
pub(crate) fn position_to_byte(
&self,
position: &TextDocumentPositionParams,
) -> anyhow::Result<usize> {
let file_map = self.file_map.lock();
let uri = position.text_document.uri.to_string();
let file = file_map
Expand Down
8 changes: 4 additions & 4 deletions crates/lsp-ai/src/memory_backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 {
Expand Down
9 changes: 2 additions & 7 deletions crates/lsp-ai/src/memory_backends/postgresml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FileStore>,
Expand Down Expand Up @@ -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")
{
Expand Down
12 changes: 6 additions & 6 deletions crates/lsp-ai/src/memory_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use crate::{
};

#[derive(Debug)]
pub struct PromptRequest {
pub(crate) struct PromptRequest {
position: TextDocumentPositionParams,
prompt_type: PromptType,
params: Value,
tx: tokio::sync::oneshot::Sender<Prompt>,
}

impl PromptRequest {
pub fn new(
pub(crate) fn new(
position: TextDocumentPositionParams,
prompt_type: PromptType,
params: Value,
Expand All @@ -37,21 +37,21 @@ impl PromptRequest {
}

#[derive(Debug)]
pub struct FilterRequest {
pub(crate) struct FilterRequest {
position: TextDocumentPositionParams,
tx: tokio::sync::oneshot::Sender<String>,
}

impl FilterRequest {
pub fn new(
pub(crate) fn new(
position: TextDocumentPositionParams,
tx: tokio::sync::oneshot::Sender<String>,
) -> Self {
Self { position, tx }
}
}

pub enum WorkerRequest {
pub(crate) enum WorkerRequest {
FilterText(FilterRequest),
Prompt(PromptRequest),
DidOpenTextDocument(DidOpenTextDocumentParams),
Expand Down Expand Up @@ -115,7 +115,7 @@ fn do_run(
}
}

pub fn run(
pub(crate) fn run(
memory_backend: Box<dyn MemoryBackend + Send + Sync>,
rx: std::sync::mpsc::Receiver<WorkerRequest>,
) {
Expand Down
Loading

0 comments on commit 3b286d5

Please sign in to comment.