@@ -19,6 +19,7 @@ use crate::ext::TextDocumentIdentifierExt;
1919use crate :: ext:: UriExt ;
2020use crate :: queue:: Queue ;
2121use crate :: session:: Session ;
22+ use crate :: session:: SessionSnapshot ;
2223
2324const SERVER_NAME : & str = "Django Language Server" ;
2425const SERVER_VERSION : & str = "0.1.0" ;
@@ -59,12 +60,15 @@ impl DjangoLanguageServer {
5960
6061 pub async fn with_session_task < F , Fut > ( & self , f : F )
6162 where
62- F : FnOnce ( Arc < Mutex < Session > > ) -> Fut + Send + ' static ,
63+ F : FnOnce ( SessionSnapshot ) -> Fut + Send + ' static ,
6364 Fut : Future < Output = anyhow:: Result < ( ) > > + Send + ' static ,
6465 {
65- let session_arc = Arc :: clone ( & self . session ) ;
66+ let snapshot = {
67+ let session = self . session . lock ( ) . await ;
68+ session. snapshot ( )
69+ } ;
6670
67- if let Err ( e) = self . queue . submit ( async move { f ( session_arc ) . await } ) . await {
71+ if let Err ( e) = self . queue . submit ( async move { f ( snapshot ) . await } ) . await {
6872 tracing:: error!( "Failed to submit task: {}" , e) ;
6973 } else {
7074 tracing:: info!( "Task submitted successfully" ) ;
@@ -174,10 +178,8 @@ impl LanguageServer for DjangoLanguageServer {
174178 async fn initialized ( & self , _params : lsp_types:: InitializedParams ) {
175179 tracing:: info!( "Server received initialized notification." ) ;
176180
177- self . with_session_task ( move |session_arc| async move {
178- let session = session_arc. lock ( ) . await ;
179-
180- if let Some ( project) = session. project ( ) {
181+ self . with_session_task ( move |session| async move {
182+ if let Some ( project) = session. db ( ) . project ( ) {
181183 let path = project. root ( session. db ( ) ) . clone ( ) ;
182184 tracing:: info!( "Task: Starting initialization for project at: {}" , path) ;
183185 project. initialize ( session. db ( ) ) ;
0 commit comments