@@ -1040,7 +1040,7 @@ fn cmd_handle_utf16_unit_text_edits() {
1040
1040
. file (
1041
1041
"Cargo.toml" ,
1042
1042
r#"[package]
1043
- name = "root_is_fine "
1043
+ name = "cmd_handle_utf16_unit_text_edits "
1044
1044
version = "0.1.0"
1045
1045
1046
1046
"# ,
@@ -1092,3 +1092,65 @@ fn cmd_handle_utf16_unit_text_edits() {
1092
1092
1093
1093
rls. shutdown ( rls_timeout ( ) ) ;
1094
1094
}
1095
+
1096
+ /// Ensures that wide characters do not prevent RLS from calculating correct
1097
+ /// 'whole file' LSP range.
1098
+ #[ test]
1099
+ fn cmd_format_utf16_range ( ) {
1100
+ let project = project ( "cmd_format_utf16_range" )
1101
+ . file (
1102
+ "Cargo.toml" ,
1103
+ r#"[package]
1104
+ name = "cmd_format_utf16_range"
1105
+ version = "0.1.0"
1106
+
1107
+ "# ,
1108
+ )
1109
+ . file ( "src/main.rs" , "/* 😢😢😢😢😢😢😢 */ fn main() { }" )
1110
+ . build ( ) ;
1111
+ let root_path = project. root ( ) ;
1112
+ let mut rls = project. spawn_rls ( ) ;
1113
+
1114
+ rls. request (
1115
+ 0 ,
1116
+ "initialize" ,
1117
+ Some ( json ! ( {
1118
+ "rootPath" : root_path,
1119
+ "capabilities" : { }
1120
+ } ) ) ,
1121
+ )
1122
+ . unwrap ( ) ;
1123
+
1124
+ rls. wait_until_done_indexing ( rls_timeout ( ) ) ;
1125
+
1126
+ let request_id = 66 ;
1127
+ rls. request (
1128
+ request_id,
1129
+ "textDocument/formatting" ,
1130
+ Some ( json ! (
1131
+ {
1132
+ "textDocument" : {
1133
+ "uri" : format!( "file://{}/src/main.rs" , root_path. as_path( ) . display( ) ) ,
1134
+ "version" : 1
1135
+ } ,
1136
+ "options" : {
1137
+ "tabSize" : 4 ,
1138
+ "insertSpaces" : true
1139
+ }
1140
+ } ) )
1141
+ ) . unwrap ( ) ;
1142
+
1143
+ let json = rls. wait_until_json_id ( request_id, rls_timeout ( ) ) ;
1144
+ eprintln ! ( "{:#?}" , json) ;
1145
+
1146
+ let result = json[ "result" ] . as_array ( ) . unwrap ( ) ;
1147
+ let newText: Vec < _ > = result
1148
+ . into_iter ( )
1149
+ . map ( |o| o[ "newText" ] . as_str ( ) . unwrap ( ) )
1150
+ . collect ( ) ;
1151
+ // Actual formatting isn't important - what is, is that the buffer isn't
1152
+ // malformed and code stays semantically equivalent.
1153
+ assert_eq ! ( newText, vec![ "/* 😢😢😢😢😢😢😢 */\n fn main() {}\n " ] ) ;
1154
+
1155
+ rls. shutdown ( rls_timeout ( ) ) ;
1156
+ }
0 commit comments