Skip to content

Commit

Permalink
allow LSP insert text to replace non-matching prefixes (#5469)
Browse files Browse the repository at this point in the history
Most LSPs will complete case-insensitive matches, particularly from
lowercase to uppercase.  In some cases, notably Pyright, this is given
as a simple insert text instead of TextEdit.  When this happens, the
prefix text was left unedited.
  • Loading branch information
Taylor C. Richberger authored and pascalkuthe committed Feb 16, 2023
1 parent ce0837d commit 8b4cf75
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ impl Completion {
)
} else {
let text = item.insert_text.as_ref().unwrap_or(&item.label);
// Some LSPs just give you an insertText with no offset ¯\_(ツ)_/¯
// in these cases we need to check for a common prefix and remove it
let prefix = Cow::from(doc.text().slice(start_offset..trigger_offset));
let text = text.trim_start_matches::<&str>(&prefix);

// TODO: this needs to be true for the numbers to work out correctly
// in the closure below. It's passed in to a callback as this same
Expand All @@ -152,10 +148,8 @@ impl Completion {
== trigger_offset
);

Transaction::change_by_selection(doc.text(), doc.selection(view_id), |range| {
let cursor = range.cursor(doc.text().slice(..));

(cursor, cursor, Some(text.into()))
Transaction::change_by_selection(doc.text(), doc.selection(view_id), |_| {
(start_offset, trigger_offset, Some(text.into()))
})
};

Expand Down

0 comments on commit 8b4cf75

Please sign in to comment.