-
Notifications
You must be signed in to change notification settings - Fork 30
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
Multiline comments in Ocaml are badly indented #111
Comments
This sounds like something that the engine should be doing transparently. |
Here is a minimal reproducer: let _ = fun _ ->
(* foo
*)
() gets formatted as: let _ = fun _ ->
(* foo
*)
() |
Would it be correct to say that if the first line of a multi-line comment is indented n times, then all lines of the comment must be indented n times? Does this apply to all multi-line leaves? I suppose not, because the code may contain literal strings that can't be indented, like this:
|
A few possible approaches:
|
Idempotency is complicating things a bit. We don't want to indent twice. So I am taking all lines that may or may not begin with the correct indent level of spacing, and replacing that with the correct indent level of spacing. Which means that this:
will all get indented as such:
|
Another example: enum ExpandTwoLevels {
Leaf {
/*
* Multi-line
* comment
*/
content: String,
},
} Consider lines 2-4 of that comment. They all begin with 5 spaces. How do we treat them? We know they are not put there as indentation by Topiary, because that would have been 8 spaces. So they are one of these:
We don't know which it is, so the best we can do is to keep it. Which means that after indentation they get 8 + 5 spaces: enum ExpandTwoLevels {
Leaf {
/*
* Multi-line
* comment
*/
content: String,
},
} |
Should I instead decide that since the comment starts on column 4, I should clean out up to 4 spaces from the beginning of all following lines, before indenting? |
Yes, I think that this is the best solution, if the comments starts after
|
Hi, @GuillaumeGen 🙂 Looks like what we really need is to compare which column the comment originally starts on ( But we don't know This will work well with idempotency, because once the comment is formatted, |
I'm pretty happy with the above PR. I think it solves all the cases. |
When an Ocaml file contains multiline comments, those are badly displayed because the first line is the only indented one.
So
can be turned into
The reason for it, is that topiary evaluated that the function body should be indented by 2 levels whereas I indented it by only one, hence it indented the beginning of the comment with the function body, but since the whole comment is a leaf, the other lines kept the number of spaces I originally put in it.
Describe the solution you'd like
Ideally, I would love the text in the comment to be indented consistently.
If not, possible, turning multiline comments into single line ones, for which this problem does not occur, could be a workaround.
If both are not possible (and modifying a leaf is not the purpose of tree-sitter queries, so both are probably not possible), then keeping the indentation the user gave to comments would probably be less ugly than the current result.
The text was updated successfully, but these errors were encountered: