@@ -35,7 +35,6 @@ mod change;
3535mod document;
3636mod pg_query;
3737mod tree_sitter;
38- mod typecheck;
3938
4039/// Simple helper to manage the db connection and the associated connection string
4140#[ derive( Default ) ]
@@ -342,50 +341,52 @@ impl Workspace for WorkspaceServer {
342341 let mut diagnostics: Vec < SDiagnostic > = vec ! [ ] ;
343342
344343 // run diagnostics for each statement in parallel if its mostly i/o work
345- if let Some ( pool) = self . connection . read ( ) . unwrap ( ) . get_pool ( ) {
346- let typecheck_params: Vec < _ > = doc
347- . iter_statements_with_text_and_range ( )
348- . map ( |( stmt, range, text) | {
349- let ast = self . pg_query . get_ast ( & stmt) ;
350- let tree = self . tree_sitter . get_parse_tree ( & stmt) ;
351- ( text. to_string ( ) , ast, tree, * range)
352- } )
353- . collect ( ) ;
354-
355- let pool_clone = pool. clone ( ) ;
356- let path_clone = params. path . clone ( ) ;
357- let async_results = run_async ( async move {
358- stream:: iter ( typecheck_params)
359- . map ( |( text, ast, tree, range) | {
360- let pool = pool_clone. clone ( ) ;
361- let path = path_clone. clone ( ) ;
362- async move {
363- if let Some ( ast) = ast {
364- pg_typecheck:: check_sql ( TypecheckParams {
365- conn : & pool,
366- sql : & text,
367- ast : & ast,
368- tree : tree. as_deref ( ) ,
369- } )
370- . await
371- . map ( |d| {
372- let r = d. location ( ) . span . map ( |span| span + range. start ( ) ) ;
373-
374- d. with_file_path ( path. as_path ( ) . display ( ) . to_string ( ) )
375- . with_file_span ( r. unwrap_or ( range) )
376- } )
377- } else {
378- None
379- }
380- }
344+ if let Ok ( connection) = self . connection . read ( ) {
345+ if let Some ( pool) = connection. get_pool ( ) {
346+ let typecheck_params: Vec < _ > = doc
347+ . iter_statements_with_text_and_range ( )
348+ . map ( |( stmt, range, text) | {
349+ let ast = self . pg_query . get_ast ( & stmt) ;
350+ let tree = self . tree_sitter . get_parse_tree ( & stmt) ;
351+ ( text. to_string ( ) , ast, tree, * range)
381352 } )
382- . buffer_unordered ( 10 )
383- . collect :: < Vec < _ > > ( )
384- . await
385- } ) ?;
386-
387- for result in async_results. into_iter ( ) . flatten ( ) {
388- diagnostics. push ( SDiagnostic :: new ( result) ) ;
353+ . collect ( ) ;
354+
355+ let pool_clone = pool. clone ( ) ;
356+ let path_clone = params. path . clone ( ) ;
357+ let async_results = run_async ( async move {
358+ stream:: iter ( typecheck_params)
359+ . map ( |( text, ast, tree, range) | {
360+ let pool = pool_clone. clone ( ) ;
361+ let path = path_clone. clone ( ) ;
362+ async move {
363+ if let Some ( ast) = ast {
364+ pg_typecheck:: check_sql ( TypecheckParams {
365+ conn : & pool,
366+ sql : & text,
367+ ast : & ast,
368+ tree : tree. as_deref ( ) ,
369+ } )
370+ . await
371+ . map ( |d| {
372+ let r = d. location ( ) . span . map ( |span| span + range. start ( ) ) ;
373+
374+ d. with_file_path ( path. as_path ( ) . display ( ) . to_string ( ) )
375+ . with_file_span ( r. unwrap_or ( range) )
376+ } )
377+ } else {
378+ None
379+ }
380+ }
381+ } )
382+ . buffer_unordered ( 10 )
383+ . collect :: < Vec < _ > > ( )
384+ . await
385+ } ) ?;
386+
387+ for result in async_results. into_iter ( ) . flatten ( ) {
388+ diagnostics. push ( SDiagnostic :: new ( result) ) ;
389+ }
389390 }
390391 }
391392
0 commit comments