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

Commit d6e72ad

Browse files
committed
Translate format_utf16_range
1 parent 6465541 commit d6e72ad

File tree

2 files changed

+44
-63
lines changed

2 files changed

+44
-63
lines changed

tests/client.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,3 +926,47 @@ fn client_handle_utf16_unit_text_edits() {
926926

927927
rls.shutdown();
928928
}
929+
930+
/// Ensures that wide characters do not prevent RLS from calculating correct
931+
/// 'whole file' LSP range.
932+
#[test]
933+
fn client_format_utf16_range() {
934+
let p = project("client_format_utf16_range")
935+
.file(
936+
"Cargo.toml",
937+
r#"[package]
938+
name = "client_format_utf16_range"
939+
version = "0.1.0"
940+
authors = ["example@example.com"]
941+
"#,
942+
)
943+
.file("src/main.rs", "/* 😢😢😢😢😢😢😢 */ fn main() { }")
944+
.build();
945+
let root_path = p.root();
946+
let mut rls = p.spawn_rls_async();
947+
948+
rls.request::<Initialize>(0, initialize_params(root_path));
949+
950+
rls.wait_for_indexing();
951+
952+
let result = rls.request::<Formatting>(66, DocumentFormattingParams {
953+
text_document: TextDocumentIdentifier {
954+
uri: Url::from_file_path(p.root().join("src/main.rs")).unwrap(),
955+
},
956+
options: FormattingOptions {
957+
tab_size: 4,
958+
insert_spaces: true,
959+
properties: Default::default(),
960+
}
961+
});
962+
963+
let new_text: Vec<_> = result.unwrap()
964+
.iter()
965+
.map(|edit| edit.new_text.as_str().replace('\r', ""))
966+
.collect();
967+
// Actual formatting isn't important - what is, is that the buffer isn't
968+
// malformed and code stays semantically equivalent.
969+
assert_eq!(new_text, vec!["/* 😢😢😢😢😢😢😢 */\nfn main() {}\n"]);
970+
971+
rls.shutdown();
972+
}

tests/tests.rs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,69 +12,6 @@ use self::support::{fixtures_dir, rls_timeout};
1212
#[allow(dead_code)]
1313
mod support;
1414

15-
/// Ensures that wide characters do not prevent RLS from calculating correct
16-
/// 'whole file' LSP range.
17-
#[test]
18-
fn cmd_format_utf16_range() {
19-
let project = project("cmd_format_utf16_range")
20-
.file(
21-
"Cargo.toml",
22-
r#"[package]
23-
name = "cmd_format_utf16_range"
24-
version = "0.1.0"
25-
authors = ["example@example.com"]
26-
"#,
27-
)
28-
.file("src/main.rs", "/* 😢😢😢😢😢😢😢 */ fn main() { }")
29-
.build();
30-
let root_path = project.root();
31-
let mut rls = project.spawn_rls();
32-
33-
rls.request(
34-
0,
35-
"initialize",
36-
Some(json!({
37-
"rootPath": root_path,
38-
"capabilities": {}
39-
})),
40-
)
41-
.unwrap();
42-
43-
rls.wait_until_done_indexing(rls_timeout());
44-
45-
let request_id = 66;
46-
rls.request(
47-
request_id,
48-
"textDocument/formatting",
49-
Some(json!(
50-
{
51-
"textDocument": {
52-
"uri": format!("file://{}/src/main.rs", root_path.display()),
53-
"version": 1
54-
},
55-
"options": {
56-
"tabSize": 4,
57-
"insertSpaces": true
58-
}
59-
}))
60-
).unwrap();
61-
62-
let json = rls.wait_until_json_id(request_id, rls_timeout());
63-
eprintln!("{:#?}", json);
64-
65-
let result = json["result"].as_array().unwrap();
66-
let new_text: Vec<_> = result
67-
.iter()
68-
.map(|o| o["newText"].as_str().unwrap())
69-
.map(|text| text.replace('\r', ""))
70-
.collect();
71-
// Actual formatting isn't important - what is, is that the buffer isn't
72-
// malformed and code stays semantically equivalent.
73-
assert_eq!(new_text, vec!["/* 😢😢😢😢😢😢😢 */\nfn main() {}\n"]);
74-
75-
rls.shutdown(rls_timeout());
76-
}
77-
7815
#[test]
7916
fn cmd_lens_run() {
8017
let p = ProjectBuilder::try_from_fixture(fixtures_dir().join("lens_run"))

0 commit comments

Comments
 (0)