rust-lang / rustlings

:crab: Small exercises to get you used to reading and writing Rust code!
https://rustlings.cool
MIT License
52.69k stars 10.02k forks source link

Option to show solution after completing an exercise. #2064

Closed KotUW closed 3 weeks ago

KotUW commented 1 month ago

Is it OK, to add an option to show solution after completing an exercise. I will be interested in implementing it. If acceptable.

mo8it commented 1 month ago

You mean show it in the terminal instead of just showing the path as a link?

I am not sure if I like that option, especially because of long files. Maybe in a pager?

KotUW commented 4 weeks ago

Pager works

mo8it commented 3 weeks ago

I considered this feature, but unfortunately, it would mean adding a huge library like syntect for syntax highlighting. It also hides the advantages of having a language server for reading the docs of used items in the solution. "Go to definition" is also very useful if someone wants to take a deeper look at how an std function works.

That being said, I tried to highlight the solution in https://github.com/rust-lang/rustlings/commit/e7ba88f90594962795bd028a8537efd6b1eedf6e. Note that the shown path to the solution file is a terminal link. So you can click on it to open the solution file in your favorite editor :)