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

Provide a way to 'anonymize' line numbers when building a Snippet #2

Closed
phansch opened this issue May 30, 2019 · 2 comments · Fixed by #3
Closed

Provide a way to 'anonymize' line numbers when building a Snippet #2

phansch opened this issue May 30, 2019 · 2 comments · Fixed by #3
Labels
E-help-wanted Call for participation: Help is requested to fix this issue

Comments

@phansch
Copy link
Member

phansch commented May 30, 2019

In the rust test suite there's the option to replace line numbers in the diagnostics output with letters, so that changes in the output produce less noisy diffs.

With that flag enabled, the following

error: cannot concatenate a byte string literal
  --> $DIR/concat.rs:2:13
   |
 2 |     concat!(b'f');
   |             ^^^^

is turned into

error: cannot concatenate a byte string literal
  --> $DIR/concat.rs:2:13
   |
LL |     concat!(b'f');
   |             ^^^^

Any line number is replaced by LL, no matter the digits of that number.

AFAICT, rustc would currently have to implement its own Snippet -> DisplayList conversion, which would duplicate a lot of the conversion code just to anonymize the line numbers.

I think this would be nice to have inside annotate-snippets too, maybe as an option when constructing a Snippet? I believe other users of this library could also benefit from this option.

@zbraniecki
Copy link
Contributor

What happens if there are multiple lines? Are all of them LL or is it LM and so on? If it's all LL then it should be trivial to implement.

First, you need to adjust the lineno_width algo to recognize this option and hardcode it to 2 here - https://github.com/rust-lang/annotate-snippets-rs/blob/master/src/formatter/mod.rs#L74

Second, you need to branch in format_line to use LL here: https://github.com/rust-lang/annotate-snippets-rs/blob/master/src/formatter/mod.rs#L288

Done! :)

@zbraniecki zbraniecki added good first issue E-help-wanted Call for participation: Help is requested to fix this issue labels Jun 3, 2019
@Manishearth
Copy link
Member

All of them are LL.

The idea is that the line number shows up on the top with the filename and nowhere else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-help-wanted Call for participation: Help is requested to fix this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants