A method to get the textual line containing the (start of) a LocatedSpan would be nice.
I want to present parse errors in a user-friendly way, like this:
,
2 | div.selector { property: } /* No value */
| ^ Parse error: Expected value.
'
As LocatedSpan has methods get_column, get_utf8_column and location_line to get line-relative information, and fragment to get the source text from the span, I think it would be reasonable to also provide a method line_fragment (or some better name) to get the line text.
I currently do this with the following unsafe and abstraction-level-breaking code, adapted from the private get_columns_and_bytes_before method.
https://github.com/kaj/rsass/blob/580121abdf1367384109afaa0c18b88b99e4c959/src/error.rs#L125-L143
A method to get the textual line containing the (start of) a
LocatedSpanwould be nice.I want to present parse errors in a user-friendly way, like this:
As
LocatedSpanhas methodsget_column,get_utf8_columnandlocation_lineto get line-relative information, andfragmentto get the source text from the span, I think it would be reasonable to also provide a methodline_fragment(or some better name) to get the line text.I currently do this with the following unsafe and abstraction-level-breaking code, adapted from the private
get_columns_and_bytes_beforemethod.https://github.com/kaj/rsass/blob/580121abdf1367384109afaa0c18b88b99e4c959/src/error.rs#L125-L143