@@ -21,12 +21,14 @@ use lsp_types::{
21
21
notification:: DidOpenTextDocument ,
22
22
request:: {
23
23
CodeActionRequest , Completion , Formatting , GotoTypeDefinition , HoverRequest ,
24
- InlayHintRequest , InlayHintResolveRequest , WillRenameFiles , WorkspaceSymbolRequest ,
24
+ InlayHintRequest , InlayHintResolveRequest , RangeFormatting , WillRenameFiles ,
25
+ WorkspaceSymbolRequest ,
25
26
} ,
26
27
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 ,
30
32
} ;
31
33
use rust_analyzer:: lsp:: ext:: { OnEnter , Runnables , RunnablesParams } ;
32
34
use serde_json:: json;
@@ -660,6 +662,67 @@ fn main() {}
660
662
) ;
661
663
}
662
664
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" : { "rangeFormatting" : { "enable" : true } } ,
686
+ } ) )
687
+ . server ( )
688
+ . wait_until_workspace_is_loaded ( ) ;
689
+
690
+ server. request :: < RangeFormatting > (
691
+ DocumentRangeFormattingParams {
692
+ range : Range {
693
+ end : Position { line : 1 , character : 0 } ,
694
+ start : Position { line : 1 , character : 0 } ,
695
+ } ,
696
+ text_document : server. doc_id ( "src/lib.rs" ) ,
697
+ options : FormattingOptions {
698
+ tab_size : 4 ,
699
+ insert_spaces : false ,
700
+ insert_final_newline : None ,
701
+ trim_final_newlines : None ,
702
+ trim_trailing_whitespace : None ,
703
+ properties : HashMap :: new ( ) ,
704
+ } ,
705
+ work_done_progress_params : WorkDoneProgressParams :: default ( ) ,
706
+ } ,
707
+ json ! ( [
708
+ {
709
+ "newText" : "" ,
710
+ "range" : {
711
+ "start" : { "character" : 48 , "line" : 1 } ,
712
+ "end" : { "character" : 50 , "line" : 1 } ,
713
+ } ,
714
+ } ,
715
+ {
716
+ "newText" : "" ,
717
+ "range" : {
718
+ "start" : { "character" : 53 , "line" : 1 } ,
719
+ "end" : { "character" : 55 , "line" : 1 } ,
720
+ } ,
721
+ }
722
+ ] ) ,
723
+ ) ;
724
+ }
725
+
663
726
#[ test]
664
727
fn test_missing_module_code_action ( ) {
665
728
if skip_slow_tests ( ) {
0 commit comments