aboutsummaryrefslogtreecommitdiff
path: root/helix-lsp
diff options
context:
space:
mode:
authorAndrii Grynenko2023-03-03 05:41:06 +0000
committerBlaž Hrastnik2023-03-08 01:48:35 +0000
commit8c2e447b16e4d11db411b18f2fbe3ac2bc031d89 (patch)
treeb0f8684648db275d9b97208fbea92264d776cb1d /helix-lsp
parent0d924255e4ea3d5d5c4be9b11a337f4316550e32 (diff)
Handle snippets for LSPs not providing offsets for completion
Diffstat (limited to 'helix-lsp')
-rw-r--r--helix-lsp/src/lib.rs33
1 files changed, 7 insertions, 26 deletions
diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs
index 5b4f7ee4..147b381c 100644
--- a/helix-lsp/src/lib.rs
+++ b/helix-lsp/src/lib.rs
@@ -252,26 +252,17 @@ pub mod util {
pub fn generate_transaction_from_completion_edit(
doc: &Rope,
selection: &Selection,
- edit: lsp::TextEdit,
- offset_encoding: OffsetEncoding,
+ start_offset: i128,
+ end_offset: i128,
+ new_text: String,
) -> Transaction {
- let replacement: Option<Tendril> = if edit.new_text.is_empty() {
+ let replacement: Option<Tendril> = if new_text.is_empty() {
None
} else {
- Some(edit.new_text.into())
+ Some(new_text.into())
};
let text = doc.slice(..);
- let primary_cursor = selection.primary().cursor(text);
-
- let start_offset = match lsp_pos_to_pos(doc, edit.range.start, offset_encoding) {
- Some(start) => start as i128 - primary_cursor as i128,
- None => return Transaction::new(doc),
- };
- let end_offset = match lsp_pos_to_pos(doc, edit.range.end, offset_encoding) {
- Some(end) => end as i128 - primary_cursor as i128,
- None => return Transaction::new(doc),
- };
Transaction::change_by_selection(doc, selection, |range| {
let cursor = range.cursor(text);
@@ -288,23 +279,13 @@ pub mod util {
pub fn generate_transaction_from_snippet(
doc: &Rope,
selection: &Selection,
- edit_range: &lsp::Range,
+ start_offset: i128,
+ end_offset: i128,
snippet: snippet::Snippet,
line_ending: &str,
include_placeholder: bool,
- offset_encoding: OffsetEncoding,
) -> Transaction {
let text = doc.slice(..);
- let primary_cursor = selection.primary().cursor(text);
-
- let start_offset = match lsp_pos_to_pos(doc, edit_range.start, offset_encoding) {
- Some(start) => start as i128 - primary_cursor as i128,
- None => return Transaction::new(doc),
- };
- let end_offset = match lsp_pos_to_pos(doc, edit_range.end, offset_encoding) {
- Some(end) => end as i128 - primary_cursor as i128,
- None => return Transaction::new(doc),
- };
// For each cursor store offsets for the first tabstop
let mut cursor_tabstop_offsets = Vec::<SmallVec<[(i128, i128); 1]>>::new();