@@ -21,12 +21,14 @@ use lsp_types::{
2121 notification:: DidOpenTextDocument ,
2222 request:: {
2323 CodeActionRequest , Completion , Formatting , GotoTypeDefinition , HoverRequest ,
24- InlayHintRequest , InlayHintResolveRequest , WillRenameFiles , WorkspaceSymbolRequest ,
24+ InlayHintRequest , InlayHintResolveRequest , RangeFormatting , WillRenameFiles ,
25+ WorkspaceSymbolRequest ,
2526 } ,
2627 CodeActionContext , CodeActionParams , CompletionParams , DidOpenTextDocumentParams ,
27- DocumentFormattingParams , FileRename , FormattingOptions , GotoDefinitionParams , HoverParams ,
28- InlayHint , InlayHintLabel , InlayHintParams , PartialResultParams , Position , Range ,
29- RenameFilesParams , TextDocumentItem , TextDocumentPositionParams , WorkDoneProgressParams ,
28+ DocumentFormattingParams , DocumentRangeFormattingParams , FileRename , FormattingOptions ,
29+ GotoDefinitionParams , HoverParams , InlayHint , InlayHintLabel , InlayHintParams ,
30+ PartialResultParams , Position , Range , RenameFilesParams , TextDocumentItem ,
31+ TextDocumentPositionParams , WorkDoneProgressParams ,
3032} ;
3133use rust_analyzer:: lsp:: ext:: { OnEnter , Runnables , RunnablesParams } ;
3234use serde_json:: json;
@@ -660,6 +662,70 @@ fn main() {}
660662 ) ;
661663}
662664
665+ #[ test]
666+ fn test_format_document_range ( ) {
667+ if skip_slow_tests ( ) {
668+ return ;
669+ }
670+
671+ let server = Project :: with_fixture (
672+ r#"
673+ //- /Cargo.toml
674+ [package]
675+ name = "foo"
676+ version = "0.0.0"
677+
678+ //- /src/lib.rs
679+ fn main() {
680+ let unit_offsets_cache = collect(dwarf.units ()) ?;
681+ }
682+ "# ,
683+ )
684+ . with_config ( serde_json:: json!( {
685+ "rustfmt" : {
686+ "overrideCommand" : [ "rustfmt" , "+nightly" , ] ,
687+ "rangeFormatting" : { "enable" : true }
688+ } ,
689+ } ) )
690+ . server ( )
691+ . wait_until_workspace_is_loaded ( ) ;
692+
693+ server. request :: < RangeFormatting > (
694+ DocumentRangeFormattingParams {
695+ range : Range {
696+ end : Position { line : 1 , character : 0 } ,
697+ start : Position { line : 1 , character : 0 } ,
698+ } ,
699+ text_document : server. doc_id ( "src/lib.rs" ) ,
700+ options : FormattingOptions {
701+ tab_size : 4 ,
702+ insert_spaces : false ,
703+ insert_final_newline : None ,
704+ trim_final_newlines : None ,
705+ trim_trailing_whitespace : None ,
706+ properties : HashMap :: new ( ) ,
707+ } ,
708+ work_done_progress_params : WorkDoneProgressParams :: default ( ) ,
709+ } ,
710+ json ! ( [
711+ {
712+ "newText" : "" ,
713+ "range" : {
714+ "start" : { "character" : 48 , "line" : 1 } ,
715+ "end" : { "character" : 50 , "line" : 1 } ,
716+ } ,
717+ } ,
718+ {
719+ "newText" : "" ,
720+ "range" : {
721+ "start" : { "character" : 53 , "line" : 1 } ,
722+ "end" : { "character" : 55 , "line" : 1 } ,
723+ } ,
724+ }
725+ ] ) ,
726+ ) ;
727+ }
728+
663729#[ test]
664730fn test_missing_module_code_action ( ) {
665731 if skip_slow_tests ( ) {
0 commit comments