@@ -451,93 +451,111 @@ impl Workspace for WorkspaceServer {
451
451
/*
452
452
* Type-checking against database connection
453
453
*/
454
- if let Some ( pool) = self . get_current_connection ( ) {
455
- let path_clone = params. path . clone ( ) ;
456
- let schema_cache = self . schema_cache . load ( pool. clone ( ) ) ?;
457
- let input = doc. iter ( TypecheckDiagnosticsMapper ) . collect :: < Vec < _ > > ( ) ;
458
- let search_path_patterns = settings. typecheck . search_path . clone ( ) ;
459
-
460
- // Combined async context for both typecheck and plpgsql_check
461
- let async_results = run_async ( async move {
462
- stream:: iter ( input)
463
- . map ( |( id, range, ast, cst, sign) | {
464
- let pool = pool. clone ( ) ;
465
- let path = path_clone. clone ( ) ;
466
- let schema_cache = Arc :: clone ( & schema_cache) ;
467
- let search_path_patterns = search_path_patterns. clone ( ) ;
468
-
469
- async move {
470
- let mut diagnostics = Vec :: new ( ) ;
471
-
472
- if let Some ( ast) = ast {
473
- // Type checking
474
- let typecheck_result = pgt_typecheck:: check_sql ( TypecheckParams {
475
- conn : & pool,
476
- sql : convert_to_positional_params ( id. content ( ) ) . as_str ( ) ,
477
- ast : & ast,
478
- tree : & cst,
479
- schema_cache : schema_cache. as_ref ( ) ,
480
- search_path_patterns,
481
- identifiers : sign
482
- . map ( |s| {
483
- s. args
484
- . iter ( )
485
- . map ( |a| TypedIdentifier {
486
- path : s. name . clone ( ) ,
487
- name : a. name . clone ( ) ,
488
- type_ : IdentifierType {
489
- schema : a. type_ . schema . clone ( ) ,
490
- name : a. type_ . name . clone ( ) ,
491
- is_array : a. type_ . is_array ,
492
- } ,
493
- } )
494
- . collect :: < Vec < _ > > ( )
495
- } )
496
- . unwrap_or_default ( ) ,
497
- } )
498
- . await ;
499
-
500
- if let Ok ( Some ( diag) ) = typecheck_result {
501
- let r = diag. location ( ) . span . map ( |span| span + range. start ( ) ) ;
502
- diagnostics. push (
503
- diag. with_file_path ( path. as_path ( ) . display ( ) . to_string ( ) )
504
- . with_file_span ( r. unwrap_or ( range) ) ,
505
- ) ;
454
+ let typecheck_enabled = settings. typecheck . enabled ;
455
+ let plpgsql_check_enabled = settings. plpgsql_check . enabled ;
456
+ if typecheck_enabled || plpgsql_check_enabled {
457
+ if let Some ( pool) = self . get_current_connection ( ) {
458
+ let path_clone = params. path . clone ( ) ;
459
+ let schema_cache = self . schema_cache . load ( pool. clone ( ) ) ?;
460
+ let input = doc. iter ( TypecheckDiagnosticsMapper ) . collect :: < Vec < _ > > ( ) ;
461
+ let search_path_patterns = settings. typecheck . search_path . clone ( ) ;
462
+
463
+ // Combined async context for both typecheck and plpgsql_check
464
+ let async_results = run_async ( async move {
465
+ stream:: iter ( input)
466
+ . map ( |( id, range, ast, cst, sign) | {
467
+ let pool = pool. clone ( ) ;
468
+ let path = path_clone. clone ( ) ;
469
+ let schema_cache = Arc :: clone ( & schema_cache) ;
470
+ let search_path_patterns = search_path_patterns. clone ( ) ;
471
+
472
+ async move {
473
+ let mut diagnostics = Vec :: new ( ) ;
474
+
475
+ if let Some ( ast) = ast {
476
+ // Type checking
477
+ if typecheck_enabled {
478
+ let typecheck_result =
479
+ pgt_typecheck:: check_sql ( TypecheckParams {
480
+ conn : & pool,
481
+ sql : convert_to_positional_params ( id. content ( ) )
482
+ . as_str ( ) ,
483
+ ast : & ast,
484
+ tree : & cst,
485
+ schema_cache : schema_cache. as_ref ( ) ,
486
+ search_path_patterns,
487
+ identifiers : sign
488
+ . map ( |s| {
489
+ s. args
490
+ . iter ( )
491
+ . map ( |a| TypedIdentifier {
492
+ path : s. name . clone ( ) ,
493
+ name : a. name . clone ( ) ,
494
+ type_ : IdentifierType {
495
+ schema : a. type_ . schema . clone ( ) ,
496
+ name : a. type_ . name . clone ( ) ,
497
+ is_array : a. type_ . is_array ,
498
+ } ,
499
+ } )
500
+ . collect :: < Vec < _ > > ( )
501
+ } )
502
+ . unwrap_or_default ( ) ,
503
+ } )
504
+ . await ;
505
+
506
+ if let Ok ( Some ( diag) ) = typecheck_result {
507
+ let r = diag
508
+ . location ( )
509
+ . span
510
+ . map ( |span| span + range. start ( ) ) ;
511
+ diagnostics. push (
512
+ diag. with_file_path (
513
+ path. as_path ( ) . display ( ) . to_string ( ) ,
514
+ )
515
+ . with_file_span ( r. unwrap_or ( range) ) ,
516
+ ) ;
517
+ }
518
+ }
519
+
520
+ // plpgsql_check
521
+ if plpgsql_check_enabled {
522
+ let plpgsql_check_results =
523
+ pgt_plpgsql_check:: check_plpgsql (
524
+ pgt_plpgsql_check:: PlPgSqlCheckParams {
525
+ conn : & pool,
526
+ sql : id. content ( ) ,
527
+ ast : & ast,
528
+ schema_cache : schema_cache. as_ref ( ) ,
529
+ } ,
530
+ )
531
+ . await
532
+ . unwrap_or_else ( |_| vec ! [ ] ) ;
533
+
534
+ for d in plpgsql_check_results {
535
+ let r = d. span . map ( |span| span + range. start ( ) ) ;
536
+ diagnostics. push (
537
+ d. with_file_path (
538
+ path. as_path ( ) . display ( ) . to_string ( ) ,
539
+ )
540
+ . with_file_span ( r. unwrap_or ( range) ) ,
541
+ ) ;
542
+ }
543
+ }
506
544
}
507
545
508
- // plpgsql_check
509
- let plpgsql_check_results = pgt_plpgsql_check:: check_plpgsql (
510
- pgt_plpgsql_check:: PlPgSqlCheckParams {
511
- conn : & pool,
512
- sql : id. content ( ) ,
513
- ast : & ast,
514
- schema_cache : schema_cache. as_ref ( ) ,
515
- } ,
516
- )
517
- . await
518
- . unwrap_or_else ( |_| vec ! [ ] ) ;
519
-
520
- for d in plpgsql_check_results {
521
- let r = d. span . map ( |span| span + range. start ( ) ) ;
522
- diagnostics. push (
523
- d. with_file_path ( path. as_path ( ) . display ( ) . to_string ( ) )
524
- . with_file_span ( r. unwrap_or ( range) ) ,
525
- ) ;
526
- }
546
+ Ok :: < Vec < pgt_diagnostics:: Error > , sqlx:: Error > ( diagnostics)
527
547
}
528
-
529
- Ok :: < Vec < pgt_diagnostics:: Error > , sqlx:: Error > ( diagnostics)
530
- }
531
- } )
532
- . buffer_unordered ( 10 )
533
- . collect :: < Vec < _ > > ( )
534
- . await
535
- } ) ?;
536
-
537
- for result in async_results. into_iter ( ) {
538
- let diagnostics_batch = result?;
539
- for diag in diagnostics_batch {
540
- diagnostics. push ( SDiagnostic :: new ( diag) ) ;
548
+ } )
549
+ . buffer_unordered ( 10 )
550
+ . collect :: < Vec < _ > > ( )
551
+ . await
552
+ } ) ?;
553
+
554
+ for result in async_results. into_iter ( ) {
555
+ let diagnostics_batch = result?;
556
+ for diag in diagnostics_batch {
557
+ diagnostics. push ( SDiagnostic :: new ( diag) ) ;
558
+ }
541
559
}
542
560
}
543
561
}
0 commit comments