Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 641a91f

Browse files
committed
feat(lsp): improve file system event handling
* Add support for rename operations in filesystem watcher * Extract path filtering logic into separate method * Handle more specific file modification events * Add new debouncer module structure
1 parent da2dd56 commit 641a91f

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

crates/echolysis-lsp/src/server/debouncer.rs

Whitespace-only changes.

crates/echolysis-lsp/src/server/fs_watcher.rs

+46-26
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use notify::{Config, Watcher};
33
use std::path::PathBuf;
44
use tower_lsp::lsp_types;
55

6-
use crate::server::utils::should_ignore;
6+
use crate::server::{
7+
on_event::{on_insert, on_remove},
8+
utils::should_ignore,
9+
};
710

811
use super::{
912
utils::{get_all_files_under_folder, git_root},
@@ -119,24 +122,9 @@ impl Server {
119122
}
120123
}
121124

122-
// Handle filesystem events for code duplication analysis
123-
async fn do_handle_fs_event(&self, event: notify::Event) {
124-
use notify::{event::*, EventKind};
125-
126-
// Early return for unsupported event types
127-
if !matches!(
128-
event.kind,
129-
EventKind::Create(_)
130-
| EventKind::Modify(ModifyKind::Data(_))
131-
| EventKind::Modify(ModifyKind::Metadata(MetadataKind::WriteTime))
132-
| EventKind::Remove(_)
133-
) {
134-
return;
135-
}
136-
125+
fn filter_map_fs_event_paths(&self, paths: &[PathBuf]) -> Vec<lsp_types::Url> {
137126
// Filter relevant paths (files that are not logs and tracked files)
138-
let uris: Vec<_> = event
139-
.paths
127+
paths
140128
.iter()
141129
.filter_map(|path| {
142130
if should_ignore(path) {
@@ -149,17 +137,25 @@ impl Server {
149137
None
150138
}
151139
})
152-
.collect();
140+
.collect()
141+
}
153142

154-
if uris.is_empty() {
155-
return;
156-
}
143+
// Handle filesystem events for code duplication analysis
144+
async fn do_handle_fs_event(&self, event: notify::Event) {
145+
use notify::{event::*, EventKind};
157146

158147
// Process the event based on its type
159148
match event.kind {
160149
EventKind::Create(_)
161-
| EventKind::Modify(ModifyKind::Data(_))
162-
| EventKind::Modify(ModifyKind::Metadata(MetadataKind::WriteTime)) => {
150+
| EventKind::Modify(
151+
ModifyKind::Data(_)
152+
| ModifyKind::Name(RenameMode::To)
153+
| ModifyKind::Metadata(MetadataKind::WriteTime),
154+
) => {
155+
let uris = self.filter_map_fs_event_paths(&event.paths);
156+
if uris.is_empty() {
157+
return;
158+
}
163159
self.on_insert(
164160
&uris
165161
.into_iter()
@@ -168,10 +164,34 @@ impl Server {
168164
)
169165
.await;
170166
}
171-
EventKind::Remove(_) => {
167+
EventKind::Remove(_) | EventKind::Modify(ModifyKind::Name(RenameMode::From)) => {
168+
let uris = self.filter_map_fs_event_paths(&event.paths);
169+
if uris.is_empty() {
170+
return;
171+
}
172172
self.on_remove(&uris).await;
173173
}
174-
_ => (),
174+
EventKind::Modify(ModifyKind::Name(RenameMode::Both)) => {
175+
if let [from, to] = event.paths.as_slice() {
176+
let from = self.filter_map_fs_event_paths(&[from.clone()]);
177+
let to = self.filter_map_fs_event_paths(&[to.clone()]).pop();
178+
if !from.is_empty() {
179+
self.on_remove(&from).await;
180+
}
181+
if let Some(to) = to {
182+
self.on_insert(&[(to, None)]).await;
183+
}
184+
}
185+
}
186+
EventKind::Any
187+
| EventKind::Access(_)
188+
| EventKind::Other
189+
| EventKind::Modify(
190+
ModifyKind::Any
191+
| ModifyKind::Other
192+
| ModifyKind::Name(RenameMode::Any | RenameMode::Other)
193+
| ModifyKind::Metadata(_),
194+
) => {}
175195
}
176196
}
177197
}

crates/echolysis-lsp/src/server/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use fs_watcher::FsWatcher;
55
use router::Router;
66
use tower_lsp::lsp_types::{self, MessageType};
77

8+
mod debouncer;
89
mod diagnostic;
910
mod fs_watcher;
1011
mod language_server;

0 commit comments

Comments
 (0)