@@ -82,7 +82,7 @@ impl DjangoLanguageServer {
8282 }
8383
8484 let path = self
85- . with_session ( |session| session . with_db ( |db| document. file ( ) . path ( db ) . to_owned ( ) ) )
85+ . with_session ( |session| document. path ( session . db ( ) ) . to_owned ( ) )
8686 . await ;
8787
8888 if FileKind :: from ( & path) != FileKind :: Template {
@@ -91,11 +91,10 @@ impl DjangoLanguageServer {
9191
9292 let diagnostics: Vec < lsp_types:: Diagnostic > = self
9393 . with_session_mut ( |session| {
94- session. with_db ( |db| {
95- let file = db. get_or_create_file ( & path) ;
96- let nodelist = djls_templates:: parse_template ( db, file) ;
97- djls_ide:: collect_diagnostics ( db, file, nodelist)
98- } )
94+ let db = session. db ( ) ;
95+ let file = db. get_or_create_file ( & path) ;
96+ let nodelist = djls_templates:: parse_template ( db, file) ;
97+ djls_ide:: collect_diagnostics ( db, file, nodelist)
9998 } )
10099 . await ;
101100
@@ -263,22 +262,21 @@ impl LanguageServer for DjangoLanguageServer {
263262 let position = params. text_document_position . position ;
264263 let encoding = session. client_capabilities ( ) . position_encoding ( ) ;
265264 let file_kind = FileKind :: from ( & path) ;
266- let template_tags = session. with_db ( |db| {
267- if let Some ( project) = db. project ( ) {
268- tracing:: debug!( "Fetching templatetags for project" ) ;
269- let tags = djls_project:: templatetags ( db, project) ;
270- if let Some ( ref t) = tags {
271- tracing:: debug!( "Got {} templatetags" , t. len( ) ) ;
272- } else {
273- tracing:: warn!( "No templatetags returned from project" ) ;
274- }
275- tags
265+ let db = session. db ( ) ;
266+ let template_tags = if let Some ( project) = db. project ( ) {
267+ tracing:: debug!( "Fetching templatetags for project" ) ;
268+ let tags = djls_project:: templatetags ( db, project) ;
269+ if let Some ( ref t) = tags {
270+ tracing:: debug!( "Got {} templatetags" , t. len( ) ) ;
276271 } else {
277- tracing:: warn!( "No project available for templatetags" ) ;
278- None
272+ tracing:: warn!( "No templatetags returned from project" ) ;
279273 }
280- } ) ;
281- let tag_specs = session. with_db ( SemanticDb :: tag_specs) ;
274+ tags
275+ } else {
276+ tracing:: warn!( "No project available for templatetags" ) ;
277+ None
278+ } ;
279+ let tag_specs = db. tag_specs ( ) ;
282280 let supports_snippets = session. client_capabilities ( ) . supports_snippets ( ) ;
283281
284282 let completions = djls_ide:: handle_completion (
@@ -314,11 +312,10 @@ impl LanguageServer for DjangoLanguageServer {
314312 let diagnostics = if let Some ( path) = params. text_document . uri . to_utf8_path_buf ( ) {
315313 if FileKind :: from ( & path) == FileKind :: Template {
316314 self . with_session_mut ( move |session| {
317- session. with_db_mut ( |db| {
318- let file = db. get_or_create_file ( & path) ;
319- let nodelist = djls_templates:: parse_template ( db, file) ;
320- djls_ide:: collect_diagnostics ( db, file, nodelist)
321- } )
315+ let db = session. db_mut ( ) ;
316+ let file = db. get_or_create_file ( & path) ;
317+ let nodelist = djls_templates:: parse_template ( db, file) ;
318+ djls_ide:: collect_diagnostics ( db, file, nodelist)
322319 } )
323320 . await
324321 } else {
@@ -353,21 +350,19 @@ impl LanguageServer for DjangoLanguageServer {
353350 let response = self
354351 . with_session_mut ( |session| {
355352 let encoding = session. client_capabilities ( ) . position_encoding ( ) ;
356-
357- session. with_db_mut ( |db| {
358- let file = params
359- . text_document_position_params
360- . text_document
361- . to_file ( db) ?;
362- let source = file. source ( db) ;
363- let line_index = file. line_index ( db) ;
364- let offset = params. text_document_position_params . position . to_offset (
365- source. as_str ( ) ,
366- line_index,
367- encoding,
368- ) ;
369- djls_ide:: goto_definition ( db, file, offset)
370- } )
353+ let db = session. db_mut ( ) ;
354+ let file = params
355+ . text_document_position_params
356+ . text_document
357+ . to_file ( db) ?;
358+ let source = file. source ( db) ;
359+ let line_index = file. line_index ( db) ;
360+ let offset = params. text_document_position_params . position . to_offset (
361+ source. as_str ( ) ,
362+ line_index,
363+ encoding,
364+ ) ;
365+ djls_ide:: goto_definition ( db, file, offset)
371366 } )
372367 . await ;
373368
@@ -381,18 +376,16 @@ impl LanguageServer for DjangoLanguageServer {
381376 let response = self
382377 . with_session_mut ( |session| {
383378 let encoding = session. client_capabilities ( ) . position_encoding ( ) ;
384-
385- session. with_db_mut ( |db| {
386- let file = params. text_document_position . text_document . to_file ( db) ?;
387- let source = file. source ( db) ;
388- let line_index = file. line_index ( db) ;
389- let offset = params. text_document_position . position . to_offset (
390- source. as_str ( ) ,
391- line_index,
392- encoding,
393- ) ;
394- djls_ide:: find_references ( db, file, offset)
395- } )
379+ let db = session. db_mut ( ) ;
380+ let file = params. text_document_position . text_document . to_file ( db) ?;
381+ let source = file. source ( db) ;
382+ let line_index = file. line_index ( db) ;
383+ let offset = params. text_document_position . position . to_offset (
384+ source. as_str ( ) ,
385+ line_index,
386+ encoding,
387+ ) ;
388+ djls_ide:: find_references ( db, file, offset)
396389 } )
397390 . await ;
398391
0 commit comments