Folding for functions with parameters over multiple lines #84
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.
The default configuration fails to fold functions if the parameters are defined over multiple lines. Due to typing, this is more likely to happen these days than it used to be.
Three things here:
The existing expression only matches when the final : is on the same line as the 'def'. We don't want to lose that requirement for the other keywords that start a block, so I added a totally separate expression that matches only functions definitions with a open-parenthesis as the final non-whitespace non-comment character on the line.
^\s*def\b.*\(\s*(#.*)?$
This is needed so that the closing parenthesis of the parameter declaration can be on a lower indent level, like black likes to do. It should match a closing parenthesis and colon with optional return type.
^\s*\)(\s*->\s*\w.*)?:\s*(#.*)?$
Still not done, because Textmate also matches
def foo(\n
as the start of marker-based folding due to the parenthesis, and then it gets confused. The new foldingStartMarkerexpression uses a negative-lookahead to match
(
only if it's not preceded by a def statement.^(?!\s*def\s+\w+\s*).*\(\s*(#.*)?$
With those three changes in place, Textmate can now fold all functions, not just those with
def
and):
on the same line!The exact expressions can probably be fine-tuned a little further - I didn't fuss with them too much. I'm creating this MR more so anyone with the same issue might find it than in any expectation it'll get merged.