Correctly indent function return types on new lines #4379
Closed
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.
There are two commits in this PR. The first fixes the incorrect return type indentation discussed in #4373. The second simplifies the logic of the code ambient to the fix to try lower the number of branches and amount of work needed to reason about what is happening. The biggest change w.r.t. the latter commit is that we can think about indentation of the return type only when the return type should be on its own newline; otherwise, there is no reason to indent it.
There is a blocker that need to be discussed before this could be landed:
To expand on this, visual indent styles would have the return type inline with the parameter indent:
I think this is a reasonable difference between visual and block indent, but we need to confirm this.
tangent: in the process, I discovered what I think is another bug w.r.t. fn signature indentation with the visual indent style. Under this mode, a code would format as
but I think the desired formatting is more like
However, this is a rather esoteric case that I don't think should be prioritized until more users begin submitting reports of it in real cases.
I think the function formatting function as a whole could use some refactoring for better reasoning and less branches; currently it is exceptionally large and difficult to understand.