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

Function text_range_to_source_range

crates/vm/src/stdlib/_ast.rs:144–176  ·  view source on GitHub ↗
(source_file: &SourceFile, text_range: TextRange)

Source from the content-addressed store, hash-verified

142}
143
144fn text_range_to_source_range(source_file: &SourceFile, text_range: TextRange) -> PySourceRange {
145 let index = LineIndex::from_source_text(source_file.clone().source_text());
146 let source = &source_file.source_text();
147
148 if source.is_empty() {
149 return PySourceRange {
150 start: PySourceLocation {
151 row: Row(OneIndexed::from_zero_indexed(0)),
152 column: Column(TextSize::new(0)),
153 },
154 end: PySourceLocation {
155 row: Row(OneIndexed::from_zero_indexed(0)),
156 column: Column(TextSize::new(0)),
157 },
158 };
159 }
160
161 let start_row = index.line_index(text_range.start());
162 let end_row = index.line_index(text_range.end());
163 let start_col = text_range.start() - index.line_start(start_row, source);
164 let end_col = text_range.end() - index.line_start(end_row, source);
165
166 PySourceRange {
167 start: PySourceLocation {
168 row: Row(start_row),
169 column: Column(start_col),
170 },
171 end: PySourceLocation {
172 row: Row(end_row),
173 column: Column(end_col),
174 },
175 }
176}
177
178fn get_opt_int_field(
179 vm: &VirtualMachine,

Callers 4

node_add_locationFunction · 0.85
parseFunction · 0.85
parse_func_typeFunction · 0.85
ast_to_objectMethod · 0.85

Calls 8

ColumnClass · 0.85
newFunction · 0.85
line_indexMethod · 0.80
RowClass · 0.70
cloneMethod · 0.45
is_emptyMethod · 0.45
startMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected