Skip to content

Commit

Permalink
indent snippets to line indent instead of completion start (helix-edi…
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe authored and wes-adams committed Jul 3, 2023
1 parent dd9fbc6 commit 57640a8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
16 changes: 6 additions & 10 deletions helix-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ pub mod util {
line_ending: &str,
include_placeholder: bool,
tab_width: usize,
indent_width: usize,
) -> Transaction {
let text = doc.slice(..);

Expand Down Expand Up @@ -374,19 +375,14 @@ pub mod util {
let mapped_replacement_end = (replacement_end as i128 + off) as usize;

let line_idx = mapped_doc.char_to_line(mapped_replacement_start);
let pos_on_line = mapped_replacement_start - mapped_doc.line_to_char(line_idx);

// we only care about the actual offset here (not virtual text/softwrap)
// so it's ok to use the deprecated function here
#[allow(deprecated)]
let width = helix_core::visual_coords_at_pos(
let indent_level = helix_core::indent::indent_level_for_line(
mapped_doc.line(line_idx),
pos_on_line,
tab_width,
)
.col;
indent_width,
) * indent_width;

let newline_with_offset = format!(
"{line_ending}{blank:width$}",
"{line_ending}{blank:indent_level$}",
line_ending = line_ending,
blank = ""
);
Expand Down
1 change: 1 addition & 0 deletions helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ impl Completion {
doc.line_ending.as_str(),
include_placeholder,
doc.tab_width(),
doc.indent_width(),
),
Err(err) => {
log::error!(
Expand Down

0 comments on commit 57640a8

Please sign in to comment.