From 73bf843d584179aaf7d35569436eb877721273fa Mon Sep 17 00:00:00 2001 From: Gabriel Gordon-Hall Date: Fri, 26 Jan 2024 12:24:00 +0000 Subject: [PATCH] fix clippy --- server/bleep/src/agent.rs | 19 ------------- server/bleep/src/indexes/doc.rs | 14 +++++---- server/bleep/src/lib.rs | 2 +- server/bleep/src/query/execute.rs | 5 ++-- server/bleep/src/webserver/answer.rs | 12 ++------ server/bleep/src/webserver/conversation.rs | 14 ++++----- server/bleep/src/webserver/project.rs | 6 +--- server/bleep/src/webserver/studio.rs | 33 ++++++---------------- 8 files changed, 29 insertions(+), 76 deletions(-) diff --git a/server/bleep/src/agent.rs b/server/bleep/src/agent.rs index 6c7d3778ca..1bf397843b 100644 --- a/server/bleep/src/agent.rs +++ b/server/bleep/src/agent.rs @@ -45,25 +45,6 @@ pub enum Error { Processing(anyhow::Error), } -/// A unified way to track a collection of repositories -#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] -pub struct Project(pub Vec); - -impl Project { - /// This is a temporary thing to keep backwards compatibility. - /// We should have a UUID here to track this stuff consistently. - pub fn id(&self) -> String { - self.0 - .get(0) - .map(ToString::to_string) - .expect("invalid project configuration") - } - - pub fn repos(&self) -> impl Iterator + '_ { - self.0.iter().map(|r| r.display_name()) - } -} - pub struct Agent { pub app: Application, pub conversation: Conversation, diff --git a/server/bleep/src/indexes/doc.rs b/server/bleep/src/indexes/doc.rs index 7ddbf3223b..ff0c0b1c12 100644 --- a/server/bleep/src/indexes/doc.rs +++ b/server/bleep/src/indexes/doc.rs @@ -23,6 +23,7 @@ use std::{collections::HashSet, sync::Arc}; #[derive(Clone)] pub struct Doc { sql: SqlDb, + #[allow(unused)] section_index: tantivy::Index, section_schema: schema::Section, index_writer: Arc>, @@ -363,12 +364,15 @@ impl Doc { let _ = tx.send(Progress::Err(error.to_string())); // send job status to error - self.index_queue + if let Some(job) = self + .index_queue .write() .await .iter_mut() .find(|job| job.id == id) - .map(|job| job.status = STATUS_ERROR); + { + job.status = STATUS_ERROR; + } // return error Err(error)?; @@ -452,7 +456,7 @@ impl Doc { // delete old docs from tantivy // // create a checkpoint before deletion, so we can revert to here if the job is cancelled - self.index_writer.lock().await.commit(); + let _ = self.index_writer.lock().await.commit(); self.index_writer .lock() .await @@ -588,9 +592,7 @@ impl Doc { modified_at: record.modified_at, }); - Ok(queued_item - .or(indexed_item) - .ok_or(Error::InvalidDocId(id))?) + queued_item.or(indexed_item).ok_or(Error::InvalidDocId(id)) } /// Search for doc source by title diff --git a/server/bleep/src/lib.rs b/server/bleep/src/lib.rs index 53e76d996e..dac3529e7a 100644 --- a/server/bleep/src/lib.rs +++ b/server/bleep/src/lib.rs @@ -8,7 +8,7 @@ unused_qualifications )] #![warn(unused_crate_dependencies)] -#![allow(elided_lifetimes_in_paths)] +#![allow(elided_lifetimes_in_paths, clippy::diverging_sub_expression)] #[cfg(all(feature = "onnx", feature = "metal"))] compile_error!("cannot enable `onnx` and `metal` at the same time"); diff --git a/server/bleep/src/query/execute.rs b/server/bleep/src/query/execute.rs index e1fcd715fe..4647c41da6 100644 --- a/server/bleep/src/query/execute.rs +++ b/server/bleep/src/query/execute.rs @@ -1,5 +1,4 @@ use std::{ - borrow::Cow, collections::{HashMap, HashSet}, sync::Arc, }; @@ -283,7 +282,7 @@ impl ApiQuery { for q in queries { if let Some(r) = q.repo_str() { // The branch that this project has loaded this repo with. - let project_branch = repo_branches.get(&r).map(Option::as_ref).flatten(); + let project_branch = repo_branches.get(&r).and_then(Option::as_ref); // If the branch doesn't match what we expect, drop the query. if q.branch_str().as_ref() == project_branch { @@ -293,7 +292,7 @@ impl ApiQuery { for (r, b) in &repo_branches { out.push(parser::Query { repo: Some(parser::Literal::from(r)), - branch: b.as_ref().map(|b| parser::Literal::from(b)), + branch: b.as_ref().map(parser::Literal::from), ..q.clone() }); } diff --git a/server/bleep/src/webserver/answer.rs b/server/bleep/src/webserver/answer.rs index 7a528a79ab..4fb5b2be06 100644 --- a/server/bleep/src/webserver/answer.rs +++ b/server/bleep/src/webserver/answer.rs @@ -11,23 +11,20 @@ use axum::{ }; use futures::{future::Either, stream, StreamExt}; use reqwest::StatusCode; -use serde_json::json; use tracing::{debug, error, info, warn}; -use super::conversation::ConversationId; - use super::middleware::User; use crate::{ agent::{ self, exchange::{CodeChunk, Exchange, FocusedChunk, RepoPath}, - Action, Agent, ExchangeState, Project, + Action, Agent, ExchangeState, }, analytics::{EventData, QueryEvent}, db::QueryLog, query::parser::{self, Literal}, repo::RepoRef, - webserver::conversation::{self, Conversation}, + webserver::conversation::Conversation, Application, }; @@ -76,10 +73,6 @@ pub struct Answer { pub conversation_id: Option, } -fn default_thread_id() -> uuid::Uuid { - uuid::Uuid::new_v4() -} - fn default_answer_model() -> agent::model::LLMModel { agent::model::GPT_4_TURBO_24K } @@ -166,6 +159,7 @@ struct AgentExecutor { action: Action, } +#[allow(clippy::large_enum_variant)] #[derive(serde::Serialize)] enum AnswerEvent { ChatEvent(Exchange), diff --git a/server/bleep/src/webserver/conversation.rs b/server/bleep/src/webserver/conversation.rs index f13d7e2023..47111d4c61 100644 --- a/server/bleep/src/webserver/conversation.rs +++ b/server/bleep/src/webserver/conversation.rs @@ -1,20 +1,16 @@ -use anyhow::{Context, Result}; +use anyhow::Result; use axum::{ - extract::{Path, Query, State}, - response::IntoResponse, + extract::{Path, State}, Extension, Json, }; -use chrono::NaiveDateTime; use reqwest::StatusCode; -use std::{fmt, mem}; -use tracing::info; +use std::mem; use uuid::Uuid; use crate::{ - agent::{exchange::Exchange, Project}, + agent::exchange::Exchange, db::SqlDb, - repo::RepoRef, - webserver::{self, middleware::User, Error, ErrorKind}, + webserver::{self, middleware::User, Error}, Application, }; diff --git a/server/bleep/src/webserver/project.rs b/server/bleep/src/webserver/project.rs index 382c4291ef..68dc06292b 100644 --- a/server/bleep/src/webserver/project.rs +++ b/server/bleep/src/webserver/project.rs @@ -1,12 +1,8 @@ use std::collections::HashMap; use crate::{webserver, Application}; -use axum::{ - extract::{Path, Query}, - Extension, Json, -}; +use axum::{extract::Path, Extension, Json}; use chrono::NaiveDateTime; -use futures::TryStreamExt; use super::{middleware::User, repos::Repo, Error}; diff --git a/server/bleep/src/webserver/studio.rs b/server/bleep/src/webserver/studio.rs index 7aace09bb5..90b2a617bb 100644 --- a/server/bleep/src/webserver/studio.rs +++ b/server/bleep/src/webserver/studio.rs @@ -70,7 +70,6 @@ pub struct Create { pub async fn create( app: Extension, - user: Extension, Path(project_id): Path, Json(params): Json, ) -> webserver::Result { @@ -811,7 +810,6 @@ pub async fn generate( Ok(Sse::new(Box::pin(stream))) } -#[allow(clippy::single_range_in_vec_init)] async fn generate_llm_context( app: Application, context: &[ContextFile], @@ -1087,7 +1085,7 @@ pub async fn diff( for chunk in valid_chunks { let path = chunk.src.as_deref().or(chunk.dst.as_deref()).unwrap(); - let (repo, path) = parse_diff_path(&path)?; + let (repo, path) = parse_diff_path(path)?; let lang = if let Some(l) = file_langs.get(path) { Some(l.clone()) } else { @@ -1149,21 +1147,6 @@ fn parse_diff_path(p: &str) -> Result<(RepoRef, &str)> { Ok((repo, path)) } -fn context_repo_branch(context: &[ContextFile]) -> Result<(RepoRef, Option)> { - let (repo, branch) = context - .first() - .map(|cf| (cf.repo.clone(), cf.branch.clone())) - // We make a hard assumption in the design of diffs that a studio can only contain files - // from one repository. This allows us to determine which repository to create new files - // or delete files in, without having to prefix file paths with repository names. - // - // If we can't find *any* files in the context to detect the current repository, - // creating/deleting a file like `index.js` is ambiguous, so we just return an error. - .context("could not determine studio repository, studio didn't contain any files")?; - - Ok((repo, branch)) -} - async fn rectify_hunks( app: &Application, llm_context: &str, @@ -1304,7 +1287,7 @@ pub async fn diff_apply( .map(|row| row.context) .ok_or_else(studio_not_found)?; - let context = + let _context = serde_json::from_str::>(&context_json).map_err(Error::internal)?; let diff_chunks = diff::relaxed_parse(&diff); @@ -1329,7 +1312,7 @@ pub async fn diff_apply( let mut file_content = if chunk.src.is_some() { app.indexes .file - .by_path(&repo, &path, None) + .by_path(&repo, path, None) .await? .context("path did not exist in the index")? .content @@ -1455,7 +1438,6 @@ pub struct Import { } /// Returns a new studio ID, or the `?studio_id=...` query param if present. -#[allow(clippy::single_range_in_vec_init)] pub async fn import( app: Extension, user: Extension, @@ -1709,9 +1691,12 @@ pub async fn list_snapshots( .and_then(|r| { let app = (*app).clone(); async move { - let context: Vec = serde_json::from_str(&r.context).context("failed to deserialize context")?; - let doc_context: Vec = serde_json::from_str(&r.doc_context).context("failed to deserialize doc context")?; - let messages: Vec = serde_json::from_str(&r.messages).context("failed to deserialize messages")?; + let context: Vec = + serde_json::from_str(&r.context).context("failed to deserialize context")?; + let doc_context: Vec = serde_json::from_str(&r.doc_context) + .context("failed to deserialize doc context")?; + let messages: Vec = + serde_json::from_str(&r.messages).context("failed to deserialize messages")?; let token_counts = token_counts(app, &messages, &context, &doc_context).await?;