on master help sign in
fix(term): use existing implementation of edits_to_transaction
commit8da58fe44a040ad6219891251d3b86d6026d0260 authorgbaranski <root@gbaranski.com> dateSat 24 Jul 2021, 23:37 (5 years ago) parent41f62c3
1 file changed+9−18
helix-term/src/commands.rs+9−18
helix-term/src/commands.rs+9−18
@@ -9,8 +9,8 @@ use helix_core::{
99 object, pos_at_coords,
1010 regex::{self, Regex},
1111 register::Register,
12− search, selection, surround, textobject, Change, LineEnding, Position, Range, Rope,
13− RopeGraphemes, RopeSlice, Selection, SmallVec, Tendril, Transaction,
12+ search, selection, surround, textobject, LineEnding, Position, Range, Rope, RopeGraphemes,
13+ RopeSlice, Selection, SmallVec, Tendril, Transaction,
1414};
1515
1616use helix_view::{
@@ -2148,21 +2148,6 @@ fn apply_workspace_edit(
21482148 offset_encoding: OffsetEncoding,
21492149 workspace_edit: &lsp::WorkspaceEdit,
21502150) {
2151− let edits_to_transaction = |doc: &Rope, edits: &Vec<&lsp::TextEdit>| {
2152− let lsp_pos_to_pos = |lsp_pos| lsp_pos_to_pos(&doc, lsp_pos, offset_encoding).unwrap();
2153− let changes = edits.iter().map(|edit| -> Change {
2154− log::debug!("text edit: {:?}", edit);
2155− // This clone probably could be optimized if Picker::new would give T instead of &T
2156− let text_replacement = Tendril::from(edit.new_text.clone());
2157− (
2158− lsp_pos_to_pos(edit.range.start),
2159− lsp_pos_to_pos(edit.range.end),
2160− Some(text_replacement),
2161− )
2162− });
2163− Transaction::change(doc, changes)
2164− };
2165−
21662151 if let Some(ref changes) = workspace_edit.changes {
21672152 log::debug!("workspace changes: {:?}", changes);
21682153 editor.set_error(String::from("Handling workspace changesis not implemented yet, see https://github.com/helix-editor/helix/issues/183"));
@@ -2194,8 +2179,14 @@ fn apply_workspace_edit(
21942179 &annotated_text_edit.text_edit
21952180 }
21962181 })
2182+ .cloned()
21972183 .collect();
2198− let transaction = edits_to_transaction(doc.text(), &edits);
2184+
2185+ let transaction = helix_lsp::util::generate_transaction_from_edits(
2186+ doc.text(),
2187+ edits,
2188+ offset_encoding,
2189+ );
21992190 doc.apply(&transaction, view.id);
22002191 }
22012192 }