@@ -8,15 +8,15 @@ use smart_diff_parser::{
88} ;
99use std:: collections:: HashMap ;
1010use std:: path:: Path ;
11- use std:: sync:: { Arc , RwLock } ;
11+ use std:: sync:: { Arc , Mutex , RwLock } ;
1212use tracing:: { debug, info, warn} ;
1313use walkdir:: WalkDir ;
1414
1515/// Manages multiple comparison contexts
1616pub struct ComparisonManager {
1717 contexts : Arc < RwLock < HashMap < ComparisonId , ComparisonContext > > > ,
18- parser : TreeSitterParser ,
19- smart_matcher : SmartMatcher ,
18+ parser : Arc < Mutex < TreeSitterParser > > ,
19+ smart_matcher : Arc < Mutex < SmartMatcher > > ,
2020}
2121
2222impl ComparisonManager {
@@ -41,8 +41,8 @@ impl ComparisonManager {
4141
4242 Self {
4343 contexts : Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ,
44- parser,
45- smart_matcher : SmartMatcher :: new ( config) ,
44+ parser : Arc :: new ( Mutex :: new ( parser ) ) ,
45+ smart_matcher : Arc :: new ( Mutex :: new ( SmartMatcher :: new ( config) ) ) ,
4646 }
4747 }
4848
@@ -75,6 +75,8 @@ impl ComparisonManager {
7575 // Perform comparison using smart matcher
7676 let match_result = self
7777 . smart_matcher
78+ . lock ( )
79+ . map_err ( |e| anyhow:: anyhow!( "Lock poisoned: {}" , e) ) ?
7880 . match_functions ( & context. source_functions , & context. target_functions ) ;
7981
8082 // Extract function changes from match result
@@ -128,6 +130,7 @@ impl ComparisonManager {
128130 }
129131
130132 /// Delete a comparison
133+ #[ allow( dead_code) ]
131134 pub fn delete_comparison ( & self , id : ComparisonId ) -> Result < ( ) > {
132135 self . contexts
133136 . write ( )
@@ -141,7 +144,7 @@ impl ComparisonManager {
141144 async fn parse_location (
142145 & self ,
143146 path : & str ,
144- params : & ComparisonParams ,
147+ _params : & ComparisonParams ,
145148 base_path : & Path ,
146149 ) -> Result < Vec < Function > > {
147150 let path = Path :: new ( path) ;
@@ -200,7 +203,11 @@ impl ComparisonManager {
200203 }
201204
202205 // Parse the file
203- let parse_result = self . parser . parse ( & content, language) ?;
206+ let parse_result = self
207+ . parser
208+ . lock ( )
209+ . map_err ( |e| anyhow:: anyhow!( "Lock poisoned: {}" , e) ) ?
210+ . parse ( & content, language) ?;
204211
205212 // Extract functions from AST
206213 let functions = self . extract_functions_from_ast ( & parse_result. ast , path, base_path) ?;
0 commit comments