Skip to content

Commit da2a03e

Browse files
committed
refactor: resolve backend warnings and clean up unused code
1 parent 8087d2a commit da2a03e

11 files changed

Lines changed: 20 additions & 93 deletions

File tree

anycode-backend/src/acp.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,16 +1641,6 @@ impl AcpAgent {
16411641
Ok(())
16421642
}
16431643

1644-
/// Get all available checkpoints
1645-
pub async fn get_checkpoints(&self) -> Vec<String> {
1646-
let manager = self.history_manager.read().await;
1647-
manager
1648-
.get_all_checkpoints()
1649-
.iter()
1650-
.map(|cp| cp.prompt.clone())
1651-
.collect()
1652-
}
1653-
16541644
pub async fn cancel_prompt(&self) -> Result<()> {
16551645
let cancel_sender_guard = self.cancel_sender.lock().await;
16561646
let cancel_tx = match cancel_sender_guard.as_ref() {
@@ -1846,14 +1836,4 @@ impl AcpManager {
18461836

18471837
agent.restore_to_checkpoint_id(checkpoint_id).await
18481838
}
1849-
1850-
/// Get all checkpoints for an agent. Returns Vec of prompts
1851-
pub async fn get_checkpoints(&self, agent_id: &str) -> Result<Vec<String>> {
1852-
let agent = self
1853-
.agents
1854-
.get(agent_id)
1855-
.ok_or_else(|| anyhow!("Agent {} not found", agent_id))?;
1856-
1857-
Ok(agent.get_checkpoints().await)
1858-
}
18591839
}

anycode-backend/src/acp_fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async fn handle_write(
139139
if !lsp_changes.is_empty() {
140140
let mut lsp = lsp_manager.lock().await;
141141
if let Some(lsp) = lsp.get(&lang).await {
142-
if let Err(e) = lsp.did_change_multi(&abs_path, lsp_changes).await {
142+
if let Err(e) = lsp.did_change(&abs_path, lsp_changes).await {
143143
error!(
144144
"ACP write: failed to notify LSP didChange for {}: {}",
145145
abs_path, e

anycode-backend/src/acp_history.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use tracing::{debug, info, warn};
88
pub struct Checkpoint {
99
pub commit_hash: String,
1010
pub prompt: String,
11-
pub created_at: chrono::DateTime<chrono::Utc>,
1211
}
1312

1413
/// AcpHistoryManager - manages undo/redo using a shadow git repository
@@ -221,8 +220,6 @@ impl AcpHistoryManager {
221220
checkpoints.push(Checkpoint {
222221
commit_hash: oid.to_string(),
223222
prompt: prompt.clone(),
224-
created_at: chrono::DateTime::from_timestamp(commit.time().seconds(), 0)
225-
.unwrap_or_else(chrono::Utc::now),
226223
});
227224
}
228225
}
@@ -287,7 +284,6 @@ impl AcpHistoryManager {
287284
let checkpoint = Checkpoint {
288285
commit_hash: hash.clone(),
289286
prompt: prompt.to_string(),
290-
created_at: chrono::Utc::now(),
291287
};
292288

293289
self.checkpoints.push(checkpoint);
@@ -335,6 +331,7 @@ impl AcpHistoryManager {
335331
}
336332

337333
/// Get all checkpoints
334+
#[allow(dead_code)]
338335
pub fn get_all_checkpoints(&self) -> &[Checkpoint] {
339336
&self.checkpoints
340337
}

anycode-backend/src/code.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl Code {
6666
self.text.to_string()
6767
}
6868

69+
#[allow(dead_code)]
6970
pub fn from_str(text: &str) -> Self {
7071
let mut code = Self::new();
7172
code.applying_history = false;
@@ -136,6 +137,7 @@ impl Code {
136137
self.file_name = file_name;
137138
}
138139

140+
#[allow(dead_code)]
139141
pub fn position(&self, offset: usize) -> (usize, usize) {
140142
let line_idx = self.text.char_to_line(offset);
141143
let line_char_index = self.text.line_to_char(line_idx);
@@ -146,6 +148,7 @@ impl Code {
146148
self.text.utf16_cu_to_char(utf16_offset)
147149
}
148150

151+
#[allow(dead_code)]
149152
pub fn char_to_utf16_offset(&self, char_offset: usize) -> usize {
150153
self.text.char_to_utf16_cu(char_offset)
151154
}

anycode-backend/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ pub struct Dist;
1818
pub struct Themes;
1919

2020
#[derive(Debug, Deserialize, Clone)]
21+
#[allow(dead_code)]
2122
pub struct Config {
2223
pub theme: String,
2324
pub language: Vec<Language>,
2425
pub terminal: Option<Terminal>,
2526
}
2627

2728
impl Config {
29+
#[allow(dead_code)]
2830
pub fn default() -> Self {
2931
Config {
3032
theme: "default".to_string(),
@@ -35,6 +37,7 @@ impl Config {
3537
}
3638

3739
#[derive(Debug, Deserialize, Clone)]
40+
#[allow(dead_code)]
3841
pub struct Language {
3942
pub name: String,
4043
pub types: Vec<String>,
@@ -47,11 +50,13 @@ pub struct Language {
4750
}
4851

4952
#[derive(Debug, Deserialize, Clone)]
53+
#[allow(dead_code)]
5054
pub struct IndentConfig {
5155
pub width: i32,
5256
pub unit: String,
5357
}
5458

59+
#[cfg(test)]
5560
pub fn get_config(conf_path: &str) -> Config {
5661
let error_message = format!("Unable to read config.toml file from path {}", conf_path);
5762
let toml_str = std::fs::read_to_string(conf_path).expect(&error_message);
@@ -97,6 +102,7 @@ pub fn read_assets_config() -> anyhow::Result<String> {
97102
}
98103

99104
#[derive(Debug, Deserialize, Clone)]
105+
#[allow(dead_code)]
100106
pub struct Terminal {
101107
pub command: String,
102108
}

anycode-backend/src/handlers/io_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub async fn handle_file_change(
370370
let mut lsp_manager = state.lsp_manager.lock().await;
371371
if let Some(lsp) = lsp_manager.get(&lang).await {
372372
if !lsp_changes.is_empty() {
373-
if let Err(e) = lsp.did_change_multi(&abs_path, lsp_changes).await {
373+
if let Err(e) = lsp.did_change(&abs_path, lsp_changes).await {
374374
error!("Failed to notify LSP didChange for {}: {:?}", abs_path, e);
375375
}
376376
}

anycode-backend/src/handlers/watch_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ async fn handle_file_modification(
365365
if sync_lsp && !lsp_changes.is_empty() {
366366
let mut lsp = lsp_manager.lock().await;
367367
if let Some(lsp) = lsp.get(&lang).await {
368-
if let Err(e) = lsp.did_change_multi(path_str, lsp_changes).await {
368+
if let Err(e) = lsp.did_change(path_str, lsp_changes).await {
369369
error!("Failed to notify LSP didChange for {}: {:?}", path_str, e);
370370
}
371371
if let Err(e) = lsp.did_save(path_str) {

anycode-backend/src/lsp.rs

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,6 @@ impl Lsp {
296296
self.ready.load(Ordering::SeqCst)
297297
}
298298

299-
pub fn lsp_name(&self) -> Option<&str> {
300-
self.lsp_name.as_deref()
301-
}
302-
303299
pub fn initialized(&mut self) {
304300
let params = InitializedParams {};
305301
self.send_notification::<Initialized>(params);
@@ -361,39 +357,14 @@ impl Lsp {
361357
}
362358

363359
pub async fn did_change(
364-
&mut self,
365-
start_line: usize,
366-
start_column: usize,
367-
end_line: usize,
368-
end_column: usize,
369-
path: &str,
370-
text: &str,
371-
) -> Result<()> {
372-
self.did_change_multi(
373-
path,
374-
vec![TextDocumentContentChangeEvent {
375-
range: Some(Range {
376-
start: Position::new(start_line as u32, start_column as u32),
377-
end: Position::new(end_line as u32, end_column as u32),
378-
}),
379-
range_length: None,
380-
text: text.to_string(),
381-
}],
382-
)
383-
.await
384-
}
385-
386-
pub async fn did_change_multi(
387360
&mut self,
388361
path: &str,
389362
content_changes: Vec<TextDocumentContentChangeEvent>,
390363
) -> Result<()> {
391364
let uri = path_to_uri(path)?;
365+
let version = self.get_next_version(path) as i32;
392366
let params = DidChangeTextDocumentParams {
393-
text_document: VersionedTextDocumentIdentifier {
394-
uri,
395-
version: self.get_next_version(path) as i32,
396-
},
367+
text_document: VersionedTextDocumentIdentifier { uri, version },
397368
content_changes,
398369
};
399370

@@ -576,7 +547,7 @@ mod tests {
576547
assert!(references_str.contains("fast.py"));
577548
assert!(references_str.contains("Position { line: 0, character: 30 }"));
578549

579-
lsp.stop().await;
550+
let _ = lsp.stop().await;
580551
Ok(())
581552
}
582553
}
@@ -589,8 +560,6 @@ pub mod lsp_messages {
589560

590561
#[derive(Deserialize)]
591562
pub struct LspRawResponse {
592-
pub jsonrpc: String,
593-
pub id: Value,
594563
pub result: Option<Value>,
595564
pub error: Option<Value>,
596565
}
@@ -723,6 +692,7 @@ pub mod lsp_messages {
723692
None
724693
};
725694

695+
#[allow(deprecated)]
726696
let params = InitializeParams {
727697
process_id: Some(std::process::id() as u32),
728698
root_path: Some(dir.to_string()),
@@ -813,26 +783,6 @@ impl LspManager {
813783
self.lang2lsp.insert(lang, lsp);
814784
}
815785

816-
pub fn notify_configuration_changed(&mut self, lang: &str, dir: &str) {
817-
if let Some(lsp) = self.lang2lsp.get_mut(lang) {
818-
if let Some(lsp_name) = lsp.lsp_name() {
819-
if let Some(settings) = lsp_messages::read_vscode_settings(lsp_name, dir) {
820-
lsp.did_change_configuration(settings);
821-
}
822-
}
823-
}
824-
}
825-
826-
pub fn notify_all_configuration_changed(&mut self, dir: &str) {
827-
for lsp in self.lang2lsp.values_mut() {
828-
if let Some(lsp_name) = lsp.lsp_name() {
829-
if let Some(settings) = lsp_messages::read_vscode_settings(lsp_name, dir) {
830-
lsp.did_change_configuration(settings);
831-
}
832-
}
833-
}
834-
}
835-
836786
pub async fn stop(&mut self, lang: &str) {
837787
if let Some(mut lsp) = self.lang2lsp.remove(lang) {
838788
let _ = lsp.stop().await;

anycode-backend/src/search.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ pub async fn global_search(
303303
Ok(())
304304
}
305305

306+
#[cfg(test)]
306307
pub mod search_exp {
307308
use super::*;
308309

anycode-backend/src/terminal.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ use std::path::{Path, PathBuf};
66
use tokio::sync::mpsc;
77

88
pub struct Terminal {
9-
name: String,
10-
session_id: String,
119
pty_input_tx: mpsc::Sender<String>,
1210
pty_resize_tx: mpsc::Sender<(u16, u16)>,
1311
kill_tx: mpsc::Sender<()>,
1412
}
1513

1614
impl Terminal {
1715
pub async fn new(
18-
name: String,
19-
session_id: String,
16+
_name: String,
17+
_session_id: String,
2018
rows: u16,
2119
cols: u16,
2220
cmd: Option<String>,
@@ -53,8 +51,6 @@ impl Terminal {
5351
Self::spawn_terminal_task(child, writer, pair, pty_input_rx, pty_resize_rx, kill_rx);
5452

5553
Ok(Self {
56-
name,
57-
session_id,
5854
pty_input_tx,
5955
pty_resize_tx,
6056
kill_tx,

0 commit comments

Comments
 (0)