Only use snippet_text_edit to make snippet SnippetTextEdits

The eventual LSP representation looks like it will diverge from RA's representation of `SnippetTextEdit`s, so this'll make it easier to transition to the LSP representation later.
This commit is contained in:
DropDemBits 2024-02-15 23:37:54 -05:00
parent e4a3cc34d5
commit 1aeec93412
No known key found for this signature in database
GPG Key ID: 7FE02A6C1EDFA075

View File

@ -971,15 +971,11 @@ fn merge_text_and_snippet_edits(
snippet_range snippet_range
}; };
let range = range(line_index, snippet_range); edits.push(snippet_text_edit(
let new_text = format!("${snippet_index}"); line_index,
true,
edits.push(SnippetTextEdit { Indel { insert: format!("${snippet_index}"), delete: snippet_range },
range, ))
new_text,
insert_text_format: Some(lsp_types::InsertTextFormat::SNIPPET),
annotation_id: None,
})
} }
if snippets.peek().is_some_and(|(_, range)| { if snippets.peek().is_some_and(|(_, range)| {
@ -1002,11 +998,11 @@ fn merge_text_and_snippet_edits(
) )
}); });
let mut text_edit = text_edit(line_index, current_indel); let mut new_text = current_indel.insert;
// escape out snippet text // escape out snippet text
stdx::replace(&mut text_edit.new_text, '\\', r"\\"); stdx::replace(&mut new_text, '\\', r"\\");
stdx::replace(&mut text_edit.new_text, '$', r"\$"); stdx::replace(&mut new_text, '$', r"\$");
// ...and apply! // ...and apply!
for (index, range) in all_snippets.iter().rev() { for (index, range) in all_snippets.iter().rev() {
@ -1014,19 +1010,18 @@ fn merge_text_and_snippet_edits(
let end = (range.end() - new_range.start()).into(); let end = (range.end() - new_range.start()).into();
if range.is_empty() { if range.is_empty() {
text_edit.new_text.insert_str(start, &format!("${index}")); new_text.insert_str(start, &format!("${index}"));
} else { } else {
text_edit.new_text.insert(end, '}'); new_text.insert(end, '}');
text_edit.new_text.insert_str(start, &format!("${{{index}:")); new_text.insert_str(start, &format!("${{{index}:"));
} }
} }
edits.push(SnippetTextEdit { edits.push(snippet_text_edit(
range: text_edit.range, line_index,
new_text: text_edit.new_text, true,
insert_text_format: Some(lsp_types::InsertTextFormat::SNIPPET), Indel { insert: new_text, delete: current_indel.delete },
annotation_id: None, ))
})
} else { } else {
// snippet edit was beyond the current one // snippet edit was beyond the current one
// since it wasn't consumed, it's available for the next pass // since it wasn't consumed, it's available for the next pass
@ -1052,15 +1047,11 @@ fn merge_text_and_snippet_edits(
snippet_range snippet_range
}; };
let range = range(line_index, snippet_range); snippet_text_edit(
let new_text = format!("${snippet_index}"); line_index,
true,
SnippetTextEdit { Indel { insert: format!("${snippet_index}"), delete: snippet_range },
range, )
new_text,
insert_text_format: Some(lsp_types::InsertTextFormat::SNIPPET),
annotation_id: None,
}
})); }));
edits edits