@@ -17,6 +17,7 @@ use crate::view::session::SessionView;
1717use crate :: view:: session:: SessionViewMode ;
1818use crate :: view:: session:: SessionViewState ;
1919use crate :: view:: View ;
20+ use crate :: workspace:: Workspace ;
2021use anyhow:: Result ;
2122use crossterm:: event:: KeyCode ;
2223use log:: info;
@@ -186,6 +187,7 @@ pub struct App {
186187 pub command_input : Input ,
187188 pub command_response : Option < String > ,
188189 pub client : Arc < Mutex < DbgpClient > > ,
190+ pub workspace : Workspace ,
189191
190192 pub history : History ,
191193
@@ -206,7 +208,7 @@ pub struct App {
206208
207209impl App {
208210 pub fn new ( config : Config , receiver : Receiver < AppEvent > , sender : Sender < AppEvent > ) -> App {
209- let client = DbgpClient :: new ( None ) ;
211+ let client = Arc :: new ( Mutex :: new ( DbgpClient :: new ( None ) ) ) ;
210212 App {
211213 is_connected : false ,
212214 config,
@@ -216,7 +218,9 @@ impl App {
216218 sender : sender. clone ( ) ,
217219 quit : false ,
218220 history : History :: default ( ) ,
219- client : Arc :: new ( Mutex :: new ( client) ) ,
221+ client : Arc :: clone ( & client) ,
222+ workspace : Workspace :: new ( Arc :: clone ( & client) ) ,
223+
220224 counter : 0 ,
221225 context_depth : 4 ,
222226 stack_max_context_fetch : 1 ,
@@ -347,24 +351,27 @@ impl App {
347351 }
348352 }
349353 AppEvent :: ClientConnected ( s) => {
350- let mut client = self . client . lock ( ) . await ;
351- let response = client. deref_mut ( ) . connect ( s) . await ?;
352- for ( feature, value) in [
353- ( "max_depth" , self . context_depth . to_string ( ) . as_str ( ) ) ,
354- ( "extended_properties" , "1" ) ,
355- ] {
356- info ! ( "setting feature {} to {:?}" , feature, value) ;
357- client. feature_set ( feature, value) . await ?;
358- }
354+ let filepath = {
355+ let mut client = self . client . lock ( ) . await ;
356+ let response = client. deref_mut ( ) . connect ( s) . await ?;
357+ for ( feature, value) in [
358+ ( "max_depth" , self . context_depth . to_string ( ) . as_str ( ) ) ,
359+ ( "extended_properties" , "1" ) ,
360+ ] {
361+ info ! ( "setting feature {} to {:?}" , feature, value) ;
362+ client. feature_set ( feature, value) . await ?;
363+ }
364+ response. fileuri . clone ( )
365+ } ;
359366 self . is_connected = true ;
360367 self . server_status = None ;
361368 self . view_current = CurrentView :: Session ;
362369 self . session_view . mode = SessionViewMode :: Current ;
363- let source = client. source ( response. fileuri . clone ( ) ) . await . unwrap ( ) ;
364370
371+ let source = self . workspace . open ( filepath. clone ( ) ) . await ;
365372 self . history = History :: default ( ) ;
366373 self . history
367- . push ( HistoryEntry :: initial ( response . fileuri . clone ( ) , source) ) ;
374+ . push ( HistoryEntry :: initial ( filepath . clone ( ) , source. text . clone ( ) ) ) ;
368375 }
369376 AppEvent :: Snapshot ( ) => {
370377 self . snapshot ( ) . await ?;
@@ -537,25 +544,24 @@ impl App {
537544
538545 /// capture the current status and push it onto the history stack
539546 pub async fn snapshot ( & mut self ) -> Result < ( ) > {
540- let mut client = self . client . lock ( ) . await ;
541- let stack = client. deref_mut ( ) . get_stack ( ) . await ?;
547+ let stack = {
548+ self . client . lock ( ) . await . deref_mut ( ) . get_stack ( ) . await ?
549+ } ;
542550 let mut entry = HistoryEntry :: new ( ) ;
543551 for ( level, frame) in stack. entries . iter ( ) . enumerate ( ) {
544552 let filename = & frame. filename ;
545553 let line_no = frame. line ;
546- let context = match ( level as u16 ) < self . stack_max_context_fetch {
547- true => Some ( client. deref_mut ( ) . context_get ( level as u16 ) . await . unwrap ( ) ) ,
548- false => None ,
554+ let context = {
555+ match ( level as u16 ) < self . stack_max_context_fetch {
556+ true => Some ( self . client . lock ( ) . await . deref_mut ( ) . context_get ( level as u16 ) . await . unwrap ( ) ) ,
557+ false => None ,
558+ }
549559 } ;
550- let source_code = client
551- . deref_mut ( )
552- . source ( filename. to_string ( ) )
553- . await
554- . unwrap ( ) ;
555560
561+ let document = self . workspace . open ( filename. to_string ( ) ) . await ;
556562 let source = SourceContext {
557- source : source_code ,
558- filename : filename. to_string ( ) ,
563+ source : document . text . to_string ( ) ,
564+ filename : document . filename . to_string ( ) ,
559565 line_no,
560566 } ;
561567
0 commit comments