Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 8ec1bc6

Browse files
committed
Add whole-file LSP range regression test
1 parent 94d4084 commit 8ec1bc6

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

tests/tests.rs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ fn cmd_handle_utf16_unit_text_edits() {
10401040
.file(
10411041
"Cargo.toml",
10421042
r#"[package]
1043-
name = "root_is_fine"
1043+
name = "cmd_handle_utf16_unit_text_edits"
10441044
version = "0.1.0"
10451045
authors = ["[email protected]"]
10461046
"#,
@@ -1092,3 +1092,65 @@ fn cmd_handle_utf16_unit_text_edits() {
10921092

10931093
rls.shutdown(rls_timeout());
10941094
}
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+
authors = ["[email protected]"]
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!["/* 😢😢😢😢😢😢😢 */\nfn main() {}\n"]);
1154+
1155+
rls.shutdown(rls_timeout());
1156+
}

0 commit comments

Comments
 (0)