@@ -432,13 +432,13 @@ mod tests {
432432}
433433
434434#[ cfg( test) ]
435- mod test_init_watchers {
435+ mod test_watchers {
436436 use tower_lsp_server:: {
437437 UriExt ,
438- lsp_types:: { GlobPattern , OneOf , RelativePattern , Uri } ,
438+ lsp_types:: { FileSystemWatcher , Uri } ,
439439 } ;
440440
441- use crate :: { linter :: options :: LintOptions , options:: Options , worker:: WorkspaceWorker } ;
441+ use crate :: { options:: Options , worker:: WorkspaceWorker } ;
442442
443443 struct Tester {
444444 pub worker : WorkspaceWorker ,
@@ -465,107 +465,172 @@ mod test_init_watchers {
465465 worker
466466 }
467467
468- fn init_watchers ( & self ) -> Vec < tower_lsp_server :: lsp_types :: FileSystemWatcher > {
468+ fn init_watchers ( & self ) -> Vec < FileSystemWatcher > {
469469 tokio:: runtime:: Runtime :: new ( )
470470 . unwrap ( )
471471 . block_on ( async { self . worker . init_watchers ( ) . await } )
472472 }
473- }
474473
475- #[ test]
476- fn test_default_options ( ) {
477- let tester = Tester :: new ( "fixtures/watcher/default" , & Options :: default ( ) ) ;
478- let watchers = tester. init_watchers ( ) ;
479-
480- assert_eq ! ( watchers. len( ) , 1 ) ;
481- assert_eq ! (
482- watchers[ 0 ] . glob_pattern,
483- GlobPattern :: Relative ( RelativePattern {
484- base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
485- pattern: "**/.oxlintrc.json" . to_string( ) ,
486- } )
487- ) ;
474+ fn did_change_configuration ( & self , options : & Options ) -> Option < FileSystemWatcher > {
475+ let ( _, watchers, _) = tokio:: runtime:: Runtime :: new ( )
476+ . unwrap ( )
477+ . block_on ( async { self . worker . did_change_configuration ( options) . await } ) ;
478+ watchers
479+ }
488480 }
489481
490- #[ test]
491- fn test_custom_config_path ( ) {
492- let tester = Tester :: new (
493- "fixtures/watcher/default" ,
494- & Options {
495- lint : LintOptions {
496- config_path : Some ( "configs/lint.json" . to_string ( ) ) ,
482+ mod init_watchers {
483+ use tower_lsp_server:: lsp_types:: { GlobPattern , OneOf , RelativePattern } ;
484+
485+ use crate :: {
486+ linter:: options:: LintOptions , options:: Options , worker:: test_watchers:: Tester ,
487+ } ;
488+
489+ #[ test]
490+ fn test_default_options ( ) {
491+ let tester = Tester :: new ( "fixtures/watcher/default" , & Options :: default ( ) ) ;
492+ let watchers = tester. init_watchers ( ) ;
493+
494+ assert_eq ! ( watchers. len( ) , 1 ) ;
495+ assert_eq ! (
496+ watchers[ 0 ] . glob_pattern,
497+ GlobPattern :: Relative ( RelativePattern {
498+ base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
499+ pattern: "**/.oxlintrc.json" . to_string( ) ,
500+ } )
501+ ) ;
502+ }
503+
504+ #[ test]
505+ fn test_custom_config_path ( ) {
506+ let tester = Tester :: new (
507+ "fixtures/watcher/default" ,
508+ & Options {
509+ lint : LintOptions {
510+ config_path : Some ( "configs/lint.json" . to_string ( ) ) ,
511+ ..Default :: default ( )
512+ } ,
497513 ..Default :: default ( )
498514 } ,
499- ..Default :: default ( )
500- } ,
501- ) ;
502- let watchers = tester. init_watchers ( ) ;
503-
504- assert_eq ! ( watchers. len( ) , 1 ) ;
505- assert_eq ! (
506- watchers[ 0 ] . glob_pattern,
507- GlobPattern :: Relative ( RelativePattern {
508- base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
509- pattern: "configs/lint.json" . to_string( ) ,
510- } )
511- ) ;
512- }
515+ ) ;
516+ let watchers = tester. init_watchers ( ) ;
517+
518+ assert_eq ! ( watchers. len( ) , 1 ) ;
519+ assert_eq ! (
520+ watchers[ 0 ] . glob_pattern,
521+ GlobPattern :: Relative ( RelativePattern {
522+ base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
523+ pattern: "configs/lint.json" . to_string( ) ,
524+ } )
525+ ) ;
526+ }
513527
514- #[ test]
515- fn test_linter_extends_configs ( ) {
516- let tester = Tester :: new ( "fixtures/watcher/linter_extends" , & Options :: default ( ) ) ;
517- let watchers = tester. init_watchers ( ) ;
518-
519- // The `.oxlintrc.json` extends `./lint.json -> 2 watchers
520- assert_eq ! ( watchers. len( ) , 2 ) ;
521-
522- // nested configs pattern
523- assert_eq ! (
524- watchers[ 0 ] . glob_pattern,
525- GlobPattern :: Relative ( RelativePattern {
526- base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
527- pattern: "**/.oxlintrc.json" . to_string( ) ,
528- } )
529- ) ;
528+ #[ test]
529+ fn test_linter_extends_configs ( ) {
530+ let tester = Tester :: new ( "fixtures/watcher/linter_extends" , & Options :: default ( ) ) ;
531+ let watchers = tester. init_watchers ( ) ;
532+
533+ // The `.oxlintrc.json` extends `./lint.json -> 2 watchers
534+ assert_eq ! ( watchers. len( ) , 2 ) ;
535+
536+ // nested configs pattern
537+ assert_eq ! (
538+ watchers[ 0 ] . glob_pattern,
539+ GlobPattern :: Relative ( RelativePattern {
540+ base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
541+ pattern: "**/.oxlintrc.json" . to_string( ) ,
542+ } )
543+ ) ;
544+
545+ // extends of root config
546+ assert_eq ! (
547+ watchers[ 1 ] . glob_pattern,
548+ GlobPattern :: Relative ( RelativePattern {
549+ base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
550+ pattern: "lint.json" . to_string( ) ,
551+ } )
552+ ) ;
553+ }
530554
531- // extends of root config
532- assert_eq ! (
533- watchers[ 1 ] . glob_pattern,
534- GlobPattern :: Relative ( RelativePattern {
535- base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
536- pattern: "lint.json" . to_string( ) ,
537- } )
538- ) ;
555+ #[ test]
556+ fn test_linter_extends_custom_config_path ( ) {
557+ let tester = Tester :: new (
558+ "fixtures/watcher/linter_extends" ,
559+ & Options {
560+ lint : LintOptions {
561+ config_path : Some ( ".oxlintrc.json" . to_string ( ) ) ,
562+ ..Default :: default ( )
563+ } ,
564+ ..Default :: default ( )
565+ } ,
566+ ) ;
567+ let watchers = tester. init_watchers ( ) ;
568+
569+ assert_eq ! ( watchers. len( ) , 2 ) ;
570+ assert_eq ! (
571+ watchers[ 0 ] . glob_pattern,
572+ GlobPattern :: Relative ( RelativePattern {
573+ base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
574+ pattern: ".oxlintrc.json" . to_string( ) ,
575+ } )
576+ ) ;
577+ assert_eq ! (
578+ watchers[ 1 ] . glob_pattern,
579+ GlobPattern :: Relative ( RelativePattern {
580+ base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
581+ pattern: "lint.json" . to_string( ) ,
582+ } )
583+ ) ;
584+ }
539585 }
540586
541- #[ test]
542- fn test_linter_extends_custom_config_path ( ) {
543- let tester = Tester :: new (
544- "fixtures/watcher/linter_extends" ,
545- & Options {
546- lint : LintOptions {
547- config_path : Some ( ".oxlintrc.json" . to_string ( ) ) ,
587+ mod did_change_configuration {
588+ use tower_lsp_server:: lsp_types:: { GlobPattern , OneOf , RelativePattern } ;
589+
590+ use crate :: {
591+ linter:: options:: { LintOptions , Run } ,
592+ options:: Options ,
593+ worker:: test_watchers:: Tester ,
594+ } ;
595+
596+ #[ test]
597+ fn test_no_change ( ) {
598+ let tester = Tester :: new ( "fixtures/watcher/default" , & Options :: default ( ) ) ;
599+ let watchers = tester. did_change_configuration ( & Options :: default ( ) ) ;
600+ assert ! ( watchers. is_none( ) ) ;
601+ }
602+
603+ #[ test]
604+ fn test_lint_config_path_change ( ) {
605+ let tester = Tester :: new ( "fixtures/watcher/default" , & Options :: default ( ) ) ;
606+ let watchers = tester
607+ . did_change_configuration ( & Options {
608+ lint : LintOptions {
609+ config_path : Some ( "configs/lint.json" . to_string ( ) ) ,
610+ ..Default :: default ( )
611+ } ,
548612 ..Default :: default ( )
549- } ,
613+ } )
614+ . unwrap ( ) ;
615+
616+ assert_eq ! (
617+ watchers. glob_pattern,
618+ GlobPattern :: Relative ( RelativePattern {
619+ base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
620+ pattern: "configs/lint.json" . to_string( ) ,
621+ } )
622+ ) ;
623+ }
624+
625+ #[ test]
626+ fn test_lint_other_option_change ( ) {
627+ let tester = Tester :: new ( "fixtures/watcher/default" , & Options :: default ( ) ) ;
628+ let watchers = tester. did_change_configuration ( & Options {
629+ // run is the only option that does not require a restart
630+ lint : LintOptions { run : Run :: OnSave , ..Default :: default ( ) } ,
550631 ..Default :: default ( )
551- } ,
552- ) ;
553- let watchers = tester. init_watchers ( ) ;
554-
555- assert_eq ! ( watchers. len( ) , 2 ) ;
556- assert_eq ! (
557- watchers[ 0 ] . glob_pattern,
558- GlobPattern :: Relative ( RelativePattern {
559- base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
560- pattern: ".oxlintrc.json" . to_string( ) ,
561- } )
562- ) ;
563- assert_eq ! (
564- watchers[ 1 ] . glob_pattern,
565- GlobPattern :: Relative ( RelativePattern {
566- base_uri: OneOf :: Right ( tester. worker. get_root_uri( ) . clone( ) ) ,
567- pattern: "lint.json" . to_string( ) ,
568- } )
569- ) ;
632+ } ) ;
633+ assert ! ( watchers. is_none( ) ) ;
634+ }
570635 }
571636}
0 commit comments