Never fail to indent #21
Merged
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.
A proper indentation engine should never look past the previous line. This is because a user frequently wants custom indentation, in all programming languages. A PureScript example:
So the proper behavior is: "take previous-line indentation, then if previous line has a modifier increase/decrease it". This is both simple, robust, typically meets the user expectations, and is AFAIK what all built-in major modes do.
Unfortunately we're long past that point, the purescript-mode indentation engine parses a lot of stuff it shouldn't. And frequently it gives a "parsing error". In my experience all those "errors" are bugs because the PS code is perfectly valid, but disregarding if it's a bug or an actual unfinished code in the buffer, engine should never leave a user with no indentation whatsoever.
So what this commit does is it detects such "errors", and takes previous indentation level. Even if it's not the correct indentation, in practice it's only off by
purescript-indentation-left-offset
, so a user often has much less to type compared to "no indentation" at all.Now, it turns out the mode has another bug. As explained in the function being added,
purescript-newline-and-indent
calls indentation calculations on the wrong line. This isn't some special code that onlypurescript-newline-and-indent
uses, it is a code that's being called by the TAB indentation as well.As there are huge amounts of poorly documented code that shouldn't even be there in the first place, and are sometimes using local variables from other functions, I decided instead of trying to fix the code it would be more productive to just detect whether we're being called from
purescript-newline-and-indent
or not.