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

Function apply_text_edits

src/fix.rs:180–193  ·  view source on GitHub ↗

Apply a sorted (reverse order) list of non-overlapping `TextEdit`s to a string, returning the modified content.

(content: &str, edits: &[TextEdit])

Source from the content-addressed store, hash-verified

178/// Apply a sorted (reverse order) list of non-overlapping `TextEdit`s
179/// to a string, returning the modified content.
180fn apply_text_edits(content: &str, edits: &[TextEdit]) -> String {
181 let mut result = content.to_string();
182
183 for edit in edits {
184 let start = position_to_byte_offset(&result, edit.range.start);
185 let end = position_to_byte_offset(&result, edit.range.end);
186
187 if start <= end && end <= result.len() {
188 result.replace_range(start..end, &edit.new_text);
189 }
190 }
191
192 result
193}
194
195/// Run the fix command and return the process exit code.
196///

Calls 1

position_to_byte_offsetFunction · 0.85