|
|
|
@ -28,19 +28,44 @@ pub enum Error {
|
|
|
|
|
|
|
|
|
|
pub mod util {
|
|
|
|
|
use super::*;
|
|
|
|
|
use helix_core::{RopeSlice, State, Transaction};
|
|
|
|
|
|
|
|
|
|
pub fn lsp_pos_to_pos(doc: &helix_core::RopeSlice, pos: lsp::Position) -> usize {
|
|
|
|
|
pub fn lsp_pos_to_pos(doc: &RopeSlice, pos: lsp::Position) -> usize {
|
|
|
|
|
let line = doc.line_to_char(pos.line as usize);
|
|
|
|
|
let line_start = doc.char_to_utf16_cu(line);
|
|
|
|
|
doc.utf16_cu_to_char(pos.character as usize + line_start)
|
|
|
|
|
}
|
|
|
|
|
pub fn pos_to_lsp_pos(doc: &helix_core::RopeSlice, pos: usize) -> lsp::Position {
|
|
|
|
|
pub fn pos_to_lsp_pos(doc: &RopeSlice, pos: usize) -> lsp::Position {
|
|
|
|
|
let line = doc.char_to_line(pos);
|
|
|
|
|
let line_start = doc.char_to_utf16_cu(line);
|
|
|
|
|
let col = doc.char_to_utf16_cu(pos) - line_start;
|
|
|
|
|
|
|
|
|
|
lsp::Position::new(line as u32, col as u32)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn generate_transaction_from_edits(
|
|
|
|
|
state: &State,
|
|
|
|
|
edits: Vec<lsp::TextEdit>,
|
|
|
|
|
) -> Transaction {
|
|
|
|
|
let doc = state.doc.slice(..);
|
|
|
|
|
Transaction::change(
|
|
|
|
|
state,
|
|
|
|
|
edits.into_iter().map(|edit| {
|
|
|
|
|
// simplify "" into None for cleaner changesets
|
|
|
|
|
let replacement = if !edit.new_text.is_empty() {
|
|
|
|
|
Some(edit.new_text.into())
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let start = lsp_pos_to_pos(&doc, edit.range.start);
|
|
|
|
|
let end = lsp_pos_to_pos(&doc, edit.range.end);
|
|
|
|
|
(start, end, replacement)
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// apply_insert_replace_edit
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Clone)]
|
|
|
|
|