genemichaels
genemichaels copied to clipboard
Commenting out code
The basic issue is // is ambiguous to whether what follows is for humans (markdown) or commenting out code (literal). So I chose the human one, since the former needs automatic formatting (and this project's all about formatting things automatically) and the latter is I feel probably rarer and kind of a WIP hack thing so I thought it was less important.
One option is to treat /* as verbatim, but editors that have a hotkey for commenting blocks of code vary in whether they do // or /* which reduces the effectiveness, and it's not like people can't use /* for human comments either.
My current solution is I introduced a new //. verbatim comment style, but another solution would be good. At the very least adding /*. for consistency would probably be a good move.
This issue is about coming up with a full solution though.
Interesting ideas. 99% of the time when I use /* it is for commenting out code or special text that I don't want formatted. Rustfmt doesn't do anything ever to /* and prints errors if /* comments exceed line length limits, which I feel is the best approach for them. One thing about commented out code in // is that it either has a lot of leading spaces for indentation or has a lot of trailing ;s.
What I do in VScode sometime is ctrl+/ which doubles up the // if I commented a comment.
e.x.
// // comment
// let mut file0 = std::fs::OpenOptions::new()
// .truncate(true)
// .write(true)
// .create(true);