@@ -793,6 +793,72 @@ async fn document_no_extension() -> Result<()> {
793793 Ok ( ( ) )
794794}
795795
796+ #[ tokio:: test]
797+ async fn document_range_formatting ( ) -> Result < ( ) > {
798+ let factory = ServerFactory :: default ( ) ;
799+ let ( service, client) = factory. create ( ) . into_inner ( ) ;
800+ let ( stream, sink) = client. split ( ) ;
801+ let mut server = Server :: new ( service) ;
802+
803+ let ( sender, _) = channel ( CHANNEL_BUFFER_SIZE ) ;
804+ let reader = tokio:: spawn ( client_handler ( stream, sink, sender) ) ;
805+
806+ server. initialize ( ) . await ?;
807+ server. initialized ( ) . await ?;
808+
809+ server
810+ . notify (
811+ "textDocument/didOpen" ,
812+ DidOpenTextDocumentParams {
813+ text_document : TextDocumentItem {
814+ uri : uri ! ( "document.js" ) ,
815+ language_id : String :: from ( "javascript" ) ,
816+ version : 0 ,
817+ text : String :: from ( "doNotFormatHere()\n formatHere()\n doNotFormatHere()\n " ) ,
818+ } ,
819+ } ,
820+ )
821+ . await ?;
822+
823+ let res: Option < Vec < TextEdit > > = server
824+ . request (
825+ "textDocument/rangeFormatting" ,
826+ "formatting" ,
827+ DocumentRangeFormattingParams {
828+ text_document : TextDocumentIdentifier {
829+ uri : uri ! ( "document.js" ) ,
830+ } ,
831+ range : Range :: new ( Position :: new ( 1 , 0 ) , Position :: new ( 2 , 0 ) ) ,
832+ options : FormattingOptions {
833+ tab_size : 4 ,
834+ insert_spaces : false ,
835+ properties : HashMap :: default ( ) ,
836+ trim_trailing_whitespace : None ,
837+ insert_final_newline : None ,
838+ trim_final_newlines : None ,
839+ } ,
840+ work_done_progress_params : WorkDoneProgressParams {
841+ work_done_token : None ,
842+ } ,
843+ } ,
844+ )
845+ . await ?
846+ . context ( "formatting returned None" ) ?;
847+
848+ assert_eq ! (
849+ res. context( "formatting did not return an edit list" ) ?,
850+ vec![ TextEdit :: new(
851+ Range :: new( Position :: new( 1 , 12 ) , Position :: new( 1 , 12 ) ) ,
852+ ";" . to_string( )
853+ ) ]
854+ ) ;
855+
856+ server. shutdown ( ) . await ?;
857+ reader. abort ( ) ;
858+
859+ Ok ( ( ) )
860+ }
861+
796862#[ tokio:: test]
797863async fn pull_diagnostics ( ) -> Result < ( ) > {
798864 let factory = ServerFactory :: default ( ) ;
0 commit comments