MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / trim_selection

Function trim_selection

src/code_actions/extract_function.rs:803–822  ·  view source on GitHub ↗

Trim the selection to exclude leading/trailing whitespace and ensure it starts/ends on statement boundaries. Returns `(trimmed_start, trimmed_end)` or `None` if the trimmed selection is empty.

(content: &str, start: usize, end: usize)

Source from the content-addressed store, hash-verified

801/// Returns `(trimmed_start, trimmed_end)` or `None` if the trimmed
802/// selection is empty.
803fn trim_selection(content: &str, start: usize, end: usize) -> Option<(usize, usize)> {
804 if start >= end || end > content.len() {
805 return None;
806 }
807
808 let selected = &content[start..end];
809 let trimmed = selected.trim();
810 if trimmed.is_empty() {
811 return None;
812 }
813
814 let trim_start = start + (selected.len() - selected.trim_start().len());
815 let trim_end = end - (selected.len() - selected.trim_end().len());
816
817 if trim_start >= trim_end {
818 return None;
819 }
820
821 Some((trim_start, trim_end))
822}
823
824// ─── Indentation helpers ────────────────────────────────────────────────────
825

Callers 3

trim_whitespaceFunction · 0.85

Calls 1

is_emptyMethod · 0.45

Tested by 1

trim_whitespaceFunction · 0.68