MCPcopy Index your code
hub / github.com/RustPython/RustPython / source_range_to_text_range

Function source_range_to_text_range

crates/vm/src/stdlib/_ast.rs:256–276  ·  view source on GitHub ↗
(source_file: &SourceFile, location: PySourceRange)

Source from the content-addressed store, hash-verified

254}
255
256fn source_range_to_text_range(source_file: &SourceFile, location: PySourceRange) -> TextRange {
257 let index = LineIndex::from_source_text(source_file.clone().source_text());
258 let source = &source_file.source_text();
259
260 if source.is_empty() {
261 return TextRange::new(TextSize::new(0), TextSize::new(0));
262 }
263
264 let start = index.offset(
265 location.start.to_source_location(),
266 source,
267 PositionEncoding::Utf8,
268 );
269 let end = index.offset(
270 location.end.to_source_location(),
271 source,
272 PositionEncoding::Utf8,
273 );
274
275 TextRange::new(start, end)
276}
277
278fn node_add_location(
279 dict: &Py<PyDict>,

Callers 1

range_from_objectFunction · 0.85

Calls 5

newFunction · 0.85
to_source_locationMethod · 0.80
cloneMethod · 0.45
is_emptyMethod · 0.45
offsetMethod · 0.45

Tested by

no test coverage detected