on master help sign in
fix(term): use existing implementation of edits_to_transaction
8da58fegbaranski
helix-term/src/commands.rs+9−18
@@ -9,8 +9,8 @@ use helix_core::{
9 object, pos_at_coords,
9 object, pos_at_coords,
10 regex::{self, Regex},
10 regex::{self, Regex},
11 register::Register,
11 register::Register,
12− search, selection, surround, textobject, Change, LineEnding, Position, Range, Rope,
12+ search, selection, surround, textobject, LineEnding, Position, Range, Rope, RopeGraphemes,
13− RopeGraphemes, RopeSlice, Selection, SmallVec, Tendril, Transaction,
13+ RopeSlice, Selection, SmallVec, Tendril, Transaction,
14};
14};
15
15
16use helix_view::{
16use helix_view::{
@@ -2148,21 +2148,6 @@ fn apply_workspace_edit(
2148 offset_encoding: OffsetEncoding,
2148 offset_encoding: OffsetEncoding,
2149 workspace_edit: &lsp::WorkspaceEdit,
2149 workspace_edit: &lsp::WorkspaceEdit,
2150) {
2150) {
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−
2166 if let Some(ref changes) = workspace_edit.changes {
2151 if let Some(ref changes) = workspace_edit.changes {
2167 log::debug!("workspace changes: {:?}", changes);
2152 log::debug!("workspace changes: {:?}", changes);
2168 editor.set_error(String::from("Handling workspace changesis not implemented yet, see https://github.com/helix-editor/helix/issues/183"));
2153 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(
2194 &annotated_text_edit.text_edit
2179 &annotated_text_edit.text_edit
2195 }
2180 }
2196 })
2181 })
2182+ .cloned()
2197 .collect();
2183 .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+ );
2199 doc.apply(&transaction, view.id);
2190 doc.apply(&transaction, view.id);
2200 }
2191 }
2201 }
2192 }