style(lsp): apply rustfmt to commands.rs
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1176,27 +1176,30 @@ fn workspace_find_orphans(backend: &Backend, args: Vec<Value>) -> Result<Option<
|
|||||||
})?))
|
})?))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the end-of-file `LspPosition` (1-based lines; 0-based
|
/// Return the end-of-file `LspPosition` (1-based lines; 0-based
|
||||||
/// character column) for the given text, suitable for appending.
|
/// character column) for the given text, suitable for appending.
|
||||||
fn eof_position(text: &str) -> LspPosition {
|
fn eof_position(text: &str) -> LspPosition {
|
||||||
let mut line = 0u32;
|
let mut line = 0u32;
|
||||||
let mut last_nl_col = 0u32;
|
let mut last_nl_col = 0u32;
|
||||||
let mut col = 0u32;
|
let mut col = 0u32;
|
||||||
for (i, b) in text.as_bytes().iter().copied().enumerate() {
|
for (i, b) in text.as_bytes().iter().copied().enumerate() {
|
||||||
if b == b'\n' {
|
if b == b'\n' {
|
||||||
line += 1;
|
line += 1;
|
||||||
last_nl_col = (i + 1) as u32;
|
last_nl_col = (i + 1) as u32;
|
||||||
col = 0;
|
col = 0;
|
||||||
} else {
|
} else {
|
||||||
col = (i + 1 - last_nl_col as usize) as u32;
|
col = (i + 1 - last_nl_col as usize) as u32;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
LspPosition { line, character: col }
|
|
||||||
}
|
}
|
||||||
|
LspPosition {
|
||||||
|
line,
|
||||||
|
character: col,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ===== Pure operations =====
|
// ===== Pure operations =====
|
||||||
|
|
||||||
pub mod ops {
|
pub mod ops {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::edits::text_edit_replace;
|
use crate::edits::text_edit_replace;
|
||||||
use nuwiki_core::ast::{
|
use nuwiki_core::ast::{
|
||||||
@@ -1718,24 +1721,24 @@ fn workspace_find_orphans(backend: &Backend, args: Vec<Value>) -> Result<Option<
|
|||||||
) -> Option<(AstPosition, AstPosition)> {
|
) -> Option<(AstPosition, AstPosition)> {
|
||||||
let needle = heading_name.to_ascii_lowercase();
|
let needle = heading_name.to_ascii_lowercase();
|
||||||
for (i, block) in ast.children.iter().enumerate() {
|
for (i, block) in ast.children.iter().enumerate() {
|
||||||
let BlockNode::Heading(h) = block else {
|
let BlockNode::Heading(h) = block else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
// Accept any heading level for section replacement. Previously only
|
// Accept any heading level for section replacement. Previously only
|
||||||
// level‑1 headings were considered, which caused `VimwikiGenerateTagLinks`
|
// level‑1 headings were considered, which caused `VimwikiGenerateTagLinks`
|
||||||
// to miss existing tag sections if they were not level‑1 (e.g. `== Tag:`).
|
// to miss existing tag sections if they were not level‑1 (e.g. `== Tag:`).
|
||||||
// Removing the level check makes the edit idempotent across heading
|
// Removing the level check makes the edit idempotent across heading
|
||||||
// levels.
|
// levels.
|
||||||
// NOTE: All callers (TOC, Links, Tag links) expect a top‑level heading,
|
// NOTE: All callers (TOC, Links, Tag links) expect a top‑level heading,
|
||||||
// but supporting any level is safe because headings are unique by name
|
// but supporting any level is safe because headings are unique by name
|
||||||
// within a page and the operation replaces the whole section.
|
// within a page and the operation replaces the whole section.
|
||||||
// If multiple headings share the same title at different levels, the
|
// If multiple headings share the same title at different levels, the
|
||||||
// first encountered will be replaced – this matches prior behaviour for
|
// first encountered will be replaced – this matches prior behaviour for
|
||||||
// level‑1.
|
// level‑1.
|
||||||
// The level check is therefore removed.
|
// The level check is therefore removed.
|
||||||
// if h.level != 1 {
|
// if h.level != 1 {
|
||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let title = heading_title(h).to_ascii_lowercase();
|
let title = heading_title(h).to_ascii_lowercase();
|
||||||
if title != needle {
|
if title != needle {
|
||||||
@@ -1877,10 +1880,7 @@ fn workspace_find_orphans(backend: &Backend, args: Vec<Value>) -> Result<Option<
|
|||||||
None => {
|
None => {
|
||||||
let with_sep = format!("{new_text}\n");
|
let with_sep = format!("{new_text}\n");
|
||||||
let insert_pos = eof_position(text);
|
let insert_pos = eof_position(text);
|
||||||
b.edit(
|
b.edit(uri.clone(), text_edit_insert(insert_pos, with_sep));
|
||||||
uri.clone(),
|
|
||||||
text_edit_insert(insert_pos, with_sep),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(b.build())
|
Some(b.build())
|
||||||
@@ -2947,10 +2947,7 @@ fn workspace_find_orphans(backend: &Backend, args: Vec<Value>) -> Result<Option<
|
|||||||
None => {
|
None => {
|
||||||
let with_sep = format!("{body}\n");
|
let with_sep = format!("{body}\n");
|
||||||
let insert_pos = eof_position(text);
|
let insert_pos = eof_position(text);
|
||||||
b.edit(
|
b.edit(uri.clone(), text_edit_insert(insert_pos, with_sep));
|
||||||
uri.clone(),
|
|
||||||
text_edit_insert(insert_pos, with_sep),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(b.build())
|
Some(b.build())
|
||||||
|
|||||||
Reference in New Issue
Block a user