Be slightly more context aware of what is a doc comment and what isn't #2196
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a QoL change which I hope will benefit more people besides just myself.
I often find myself commenting out lines beginning with a forward pipe, e.g. in a chained pipe expression such as this simple (but real) example:
which will give a parsing error because lines 5 and 6 will have been lexed as doc comments -- in this case, an "unexpected EOF" error because a declaration is expected after line 6, but the error message on unexpected doc comments can also be e.g. "unexpected token" or "Doc comments can only precede declarations" in other contexts (as a side-note, it would be cool to uniformize the error messages given on unexpected doc comment lines).
EDIT: if the next token is a declaration then no error is thrown, but the comment will parse as a doc comment to the succeeding declaration. This is perhaps the trickiest case.
I'd like to be able to quickly comment out such lines without having to change my code comment plugin rules (which is easier but not so portable) -- this PR imlements the easy solution, which is to not lex as a doc comment if the
|
is followed immediately by a>
. This is compatible withfuthark-doc
since that tool uses the same parser.This change does not cover other (more or less plausible) cases, such as a code line starting with a vertical bar (bitwise OR) -- a better solution is perhaps to parse as a doc comment only if the lookahead is a declaration (but I don't know how to implement that).