From 84992c2ca19b2545f22487854ab86bc90672c856 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Tue, 6 Nov 2018 19:30:46 +0100 Subject: [PATCH] Take updated VFS span type into account From commit: https://github.com/nrc/rls-vfs/pull/24/commits/62ee1b90b968bd3e24ae60db9fd6ed995fccb086. --- Cargo.lock | 2 +- src/actions/notifications.rs | 11 +++++------ tests/tests.rs | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a019fea0ef..286cb682f1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1212,7 +1212,7 @@ dependencies = [ [[package]] name = "rls-vfs" version = "0.7.0" -source = "git+https://github.com/Xanewok/rls-vfs?branch=handle-utf16-offset#a3fb5891e20c7bdcd0735b8a5c90d42782b6f05a" +source = "git+https://github.com/Xanewok/rls-vfs?branch=handle-utf16-offset#62ee1b90b968bd3e24ae60db9fd6ed995fccb086" dependencies = [ "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/actions/notifications.rs b/src/actions/notifications.rs index ed513762ce4..3b12a7587dd 100644 --- a/src/actions/notifications.rs +++ b/src/actions/notifications.rs @@ -14,7 +14,7 @@ use crate::actions::{FileWatch, InitActionContext, VersionOrdering}; use crate::config::Config; use crate::Span; use log::{debug, trace, warn}; -use rls_vfs::{Change, SpanAtom}; +use rls_vfs::{Change, Span as VfsSpan, SpanLength as VfsSpanLength, Utf16CodeUnit}; use serde::de::Error; use serde::Deserialize; use serde_json; @@ -106,17 +106,16 @@ impl BlockingNotificationAction for DidChangeTextDocument { } } - let changes: Vec = params + // LSP sends UTF-16 code units based offsets and length + let changes: Vec> = params .content_changes .iter() .map(|i| { if let Some(range) = i.range { let range = ls_util::range_to_rls(range); Change::ReplaceText { - // LSP uses UTF-16 code units based offsets and length - atom: SpanAtom::Utf16CodeUnit, - span: Span::from_range(range, file_path.clone()), - len: i.range_length, + span: VfsSpan::::from(Span::from_range(range, file_path.clone())), + len: i.range_length.map(VfsSpanLength::from), text: i.text.clone(), } } else { diff --git a/tests/tests.rs b/tests/tests.rs index 25a695bb3fb..a0ae0310627 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1144,13 +1144,13 @@ fn cmd_format_utf16_range() { eprintln!("{:#?}", json); let result = json["result"].as_array().unwrap(); - let newText: Vec<_> = result + 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!(newText, vec!["/* 😢😢😢😢😢😢😢 */\nfn main() {}\n"]); + assert_eq!(new_text, vec!["/* 😢😢😢😢😢😢😢 */\nfn main() {}\n"]); rls.shutdown(rls_timeout()); }