This repository was archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 252
Fix crashes when editing wide characters spanning 2 u16s (UTF-16)
#1112
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
260a2cd
Don't load file from VFS to calculate reformat range
Xanewok 5abd217
Add failing UTF-16 text edit test
Xanewok 2849553
Pull rls-vfs branch with UTF-16-compatible edits
Xanewok 21dd055
Fix whole-file LSP Range
Xanewok 5072570
Add whole-file LSP range regression test
Xanewok b672685
Take updated VFS span type into account
Xanewok 1ff3a38
Use rls-vfs 0.7 from crates.io
Xanewok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1033,3 +1033,124 @@ fn cmd_invalid_member_dependency_resolution() { | |
|
|
||
| rls.shutdown(rls_timeout()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn cmd_handle_utf16_unit_text_edits() { | ||
| let project = project("cmd_handle_utf16_unit_text_edits") | ||
| .file( | ||
| "Cargo.toml", | ||
| r#"[package] | ||
| name = "cmd_handle_utf16_unit_text_edits" | ||
| version = "0.1.0" | ||
| authors = ["[email protected]"] | ||
| "#, | ||
| ) | ||
| .file("src/main.rs", "fn main() {}") | ||
| .file("src/unrelated.rs", "😢") | ||
| .build(); | ||
| let root_path = project.root(); | ||
| let mut rls = project.spawn_rls(); | ||
|
|
||
| rls.request( | ||
| 0, | ||
| "initialize", | ||
| Some(json!({ | ||
| "rootPath": root_path, | ||
| "capabilities": {} | ||
| })), | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| rls.wait_until_done_indexing(rls_timeout()); | ||
|
|
||
| rls.notify( | ||
| "textDocument/didChange", | ||
| Some(json!( | ||
| {"textDocument": { | ||
| "uri": format!("file://{}/src/unrelated.rs", root_path.as_path().display()), | ||
| "version": 1 | ||
| }, | ||
| // "😢" -> "" | ||
| "contentChanges": [ | ||
| { | ||
| "range": { | ||
| "start": { | ||
| "line":0, | ||
| "character":0 | ||
| }, | ||
| "end":{ | ||
| "line":0, | ||
| "character":2 | ||
| } | ||
| }, | ||
| "rangeLength":2, | ||
| "text":"" | ||
| } | ||
| ] | ||
| })) | ||
| ).unwrap(); | ||
|
|
||
| rls.shutdown(rls_timeout()); | ||
| } | ||
|
|
||
| /// Ensures that wide characters do not prevent RLS from calculating correct | ||
| /// 'whole file' LSP range. | ||
| #[test] | ||
| fn cmd_format_utf16_range() { | ||
| let project = project("cmd_format_utf16_range") | ||
| .file( | ||
| "Cargo.toml", | ||
| r#"[package] | ||
| name = "cmd_format_utf16_range" | ||
| version = "0.1.0" | ||
| authors = ["[email protected]"] | ||
| "#, | ||
| ) | ||
| .file("src/main.rs", "/* 😢😢😢😢😢😢😢 */ fn main() { }") | ||
| .build(); | ||
| let root_path = project.root(); | ||
| let mut rls = project.spawn_rls(); | ||
|
|
||
| rls.request( | ||
| 0, | ||
| "initialize", | ||
| Some(json!({ | ||
| "rootPath": root_path, | ||
| "capabilities": {} | ||
| })), | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| rls.wait_until_done_indexing(rls_timeout()); | ||
|
|
||
| let request_id = 66; | ||
| rls.request( | ||
| request_id, | ||
| "textDocument/formatting", | ||
| Some(json!( | ||
| { | ||
| "textDocument": { | ||
| "uri": format!("file://{}/src/main.rs", root_path.as_path().display()), | ||
| "version": 1 | ||
| }, | ||
| "options": { | ||
| "tabSize": 4, | ||
| "insertSpaces": true | ||
| } | ||
| })) | ||
| ).unwrap(); | ||
|
|
||
| let json = rls.wait_until_json_id(request_id, rls_timeout()); | ||
| eprintln!("{:#?}", json); | ||
|
|
||
| let result = json["result"].as_array().unwrap(); | ||
| let new_text: Vec<_> = result | ||
| .into_iter() | ||
| .map(|o| o["newText"].as_str().unwrap()) | ||
| .collect(); | ||
| // Actual formatting isn't important - what is, is that the buffer isn't | ||
| // malformed and code stays semantically equivalent. | ||
| assert_eq!(new_text, vec!["/* 😢😢😢😢😢😢😢 */\nfn main() {}\n"]); | ||
|
|
||
| rls.shutdown(rls_timeout()); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.