Skip to content

Get line containing the point of an span. #53

Description

@kaj

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions