Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common::Ranged provides method to convert to line/col from byte index #29

Open
kitsonk opened this issue Jul 29, 2022 · 2 comments
Open

Comments

@kitsonk
Copy link
Contributor

kitsonk commented Jul 29, 2022

Like Ranged::text(), taking the original text, it would be great to be able to return a (usize, usize) that returns a line and column variant, which is more used when displaying positions to users or editors.

@dsherret
Copy link
Member

That sounds good! Probably would just do a simple iteration of all the chars leading up to the position each time to compute this.

By the way, another possibility might be to use text_lines for this. It’s already in the CLI https://github.com/dsherret/text_lines

@kitsonk
Copy link
Contributor Author

kitsonk commented Jul 29, 2022

The ParseResult could contain the line index (as an parse option) which would make it easy to coerce into a line/col.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants