@@ -3,7 +3,10 @@ use notify::{Config, Watcher};
3
3
use std:: path:: PathBuf ;
4
4
use tower_lsp:: lsp_types;
5
5
6
- use crate :: server:: utils:: should_ignore;
6
+ use crate :: server:: {
7
+ on_event:: { on_insert, on_remove} ,
8
+ utils:: should_ignore,
9
+ } ;
7
10
8
11
use super :: {
9
12
utils:: { get_all_files_under_folder, git_root} ,
@@ -119,24 +122,9 @@ impl Server {
119
122
}
120
123
}
121
124
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 > {
137
126
// Filter relevant paths (files that are not logs and tracked files)
138
- let uris: Vec < _ > = event
139
- . paths
127
+ paths
140
128
. iter ( )
141
129
. filter_map ( |path| {
142
130
if should_ignore ( path) {
@@ -149,17 +137,25 @@ impl Server {
149
137
None
150
138
}
151
139
} )
152
- . collect ( ) ;
140
+ . collect ( )
141
+ }
153
142
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 } ;
157
146
158
147
// Process the event based on its type
159
148
match event. kind {
160
149
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
+ }
163
159
self . on_insert (
164
160
& uris
165
161
. into_iter ( )
@@ -168,10 +164,34 @@ impl Server {
168
164
)
169
165
. await ;
170
166
}
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
+ }
172
172
self . on_remove ( & uris) . await ;
173
173
}
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
+ ) => { }
175
195
}
176
196
}
177
197
}
0 commit comments