Repository navigation
Change hard coded restrictions to enable more correct indentions - #6808
Conversation
|
@thomasjo did some more thinking and came to this solution. All existing tests now run successfully. I wouldn't mind adding more/specific tests for this, but I could use some help/pointers as to where to place those tests (in I looked around in the existing tests and there are already lots of tests around the indentation logic, so the only tests I can think of that would make sense are a test that verifies the behaviour as shown in the screencasts for both a language using brackets and a language using white spaces. |
|
@thomasjo @kevinsawicki just added some tests (and squashed the commits) for the first change (removing the hard coded restriction for decreasing indents) for both a curly-bracket language and a off-side rule language. Does these tests make sense and are they enough to cover the first use case? If so I will move on and add some tests for the second use case (the one needing the new/additional So please let me know any comments and/or concerns. Thanks! /CC @nathansobo as it looks like you've written (at least part) of the current code that's extended in this PR. |
|
I'll try to find time to play around with this PR tomorrow. Just wanted to let you know it's not being ignored. Maybe someone from @atom/feedback has time to give it a go? |
|
Cool... And thanks for the ping 😃 |
|
@thomasjo any comments and/or feedback you can share already? |
|
@thomasjo @kevinsawicki @mnquintana guess you guys are pretty busy as is, but would be great to get some feedback on this one. I myself and a few colleagues are using this for about 2 weeks now and it really improved our user experience. So would be great to get this reviewed and (if no issues/concerns) merged into Atom. Thanks! |
|
Wow thanks so much for diving in to fix this fairly gnarly issue @svanharmelen! Looking at the code now... |
There was a problem hiding this comment.
Does this test verify the new feature that you added? I would think that in order to test the new behavior, you would need to change the indent-pattern settings in the language-coffee-script or language-javascript packages.
There was a problem hiding this comment.
Oh, I think I see. I didn't realize that there was more to this PR than the addition of decreaseNextIndentPattern. So these tests must be about other fixes that you made to the indentation logic.
There was a problem hiding this comment.
Yes, you are absolutely right! Please see the first comment I made to this PR, as the existing tests are to verify that behaviour. And indeed they do not require any changes to the existing regexps as they seem to fix something that wasn't working as expected before.
As for the behaviour as described in the 3rd comment, for that indeed a regexp should be added to a language that needs/uses such behaviour. Go does, so I created a PR there which was merged just a few hours ago (atom/language-go#44) whit an additional regexp. So now that this one is merged I can add some more tests to verify the additional behaviour as well. Will do that shortly...
There was a problem hiding this comment.
I don't fully understand what this new code does, and I'm a little bit concerned about the performance implications of calling testSync() in doubly-nested loop. Just to help me understand: could you explain in a little more detail your intent behind the while loop and the inner for loop?
There was a problem hiding this comment.
Of course... To determine the correct level of indentation it will search for the most recent line that was indented and then calculate the current indent level based on the rows between the last indented row and the current row.
So the first part of the while loop searches for a previous line that matches the indent pattern. As soon as 1 is found, it will enter the for loop and process every row between the two. After entering the for loop, it will never get back to the while loop but will return the function there.
Does this help or do you want/need more insights/reasoning?
There was a problem hiding this comment.
@maxbrunsfeld additionally please note that it will only ever get to the while and for loops when you insert a newline (press return) and the trailing chars that will then move to the newline, match a decrease or decreaseNext pattern.
So this code path itself will be triggered by every newline (return), but in most cases the loops will never be reached.
Still it should be efficient of course! But I do believe it is. I myself (and some colleagues) are using this for some time now and I can tell any delays or something alike. Don't know if there are benchmark tests for something like this to show the impact?
|
@svanharmelen Would you mind merging in / rebasing master and fixing the merge conflicts? |
|
@mnquintana done... |
|
@maxbrunsfeld just updated the PR so Atom now uses version 0.27.0 of the I believe all changes are now fully covered with tests so I would like to know what I can do next to get this merged? It would be really awesome to get this in Atom v1.0, but even if that's not an option we should really try to get this in as it improves the auto indentation a lot. So please let me know your thoughts and how to continue. |
|
@maxbrunsfeld @mnquintana just rebased again to have a clean/merge-able PR. Any update on how to proceed? |
|
@thomasjo @maxbrunsfeld @kevinsawicki I really appreciate you guys a very busy, but this PR is open for about a month now and even through I did receive some comments, after following up on them it got pretty silent again. I really believe this is a good fix that improves the overall indenting capabilities of Atom and does not have any general performance drawbacks. If you know of a way how to benchmark that (if that is a concern) then please let me know how to do that so I can take care of that. Otherwise I don't know what else I can/should do to get this merged, so please if any of you can spare a minute? Thanks! /CC @atom/feedback @anyone? |
|
Sorry! Been super busy, but will try to play around with it over the weekend. |
|
@thomasjo I understand... And that would be really great! Will be awaiting your comments... Thx! |
|
Hi @thomasjo... Hope you had a good weekend and had some time to play with this? Any feedback would be great in order to get this one going. Thx... |
|
Ok, really sorry for the delay in giving you further feedback on this @svanharmelen. We've been super busy and this change is pretty involved. Thanks again for taking it on. Here is my take on it:
Do you still have the un-squashed version of your work from this PR? Could you submit a second PR that references this one, and just addresses the problems that originally described at the beginning of the PR? |
|
@thomasjo @maxbrunsfeld thanks for the update! I must admit I think it's a bad idea to only fix the hard-coded indentation restriction and not add the As for your reasoning why you would like to hold of on the But I just had another look (spent a couple of hours actually) to see if there really wasn't another way to get the same result without the additional So let me run some tests and work with the new code for a day or two to see if everything still works as intended after which I will update the PR and give you a ping again for another review. As for renaming The code in this PR is currently allowing both pattern names so it doesn't require any immediate changes in existing (language) packages. So we can safely merge/update this now and then start updating all the existing (language) packages in the upcoming time (I will personally make a PR for that in every language package I can find 😉). And then later on we can make the But as said let me test and work with the updated solution first and if everything looks good, I'll update the PR and we can have another look. I think the current solution looks very clean and so I would say adding the I'll ping you again in a day or two. Thx! |
@svanharmelen That sounds great. Thanks so much for sticking with this.
I'm not dead-set opposed to adding this feature, but because it constitutes a new API that we would need to support indefinitely, we need to be more cautious about adding it than the other change that you had originally addressed with this PR. I'm also considering the fact that currently, we support a subset of TextMate's indentation system (see section 24.2.2 of the texmate docs). TextMate does not have a separate regex for |
|
@maxbrunsfeld could you give Travis a little push to build/test the PR again (as the reason it currently failed wasn't due to code itself)? Also please take a minute to review the PR again. I changed/updated the solution so it doesn't need/use any loops anymore, so I think the current solution is much better and cleaner. As for renaming You referenced the TextMate docs in which I noticed they also acknowledge the need for a As for the Thanks! |
|
Bumped Mr. Travis CI. Hopefully it goes 💚 |
|
@thomasjo unfortunately it seems I got the same error again: |
|
@svanharmelen Not your fault. The problem is caused by a license change in jschardet. Either we need to fix the version of the dependency to v1.1.1, or we need to replace the dependency. /cc @atom/feedback |
|
@thomasjo check... Then I'll just wait for the feedback from @maxbrunsfeld 😃 |
|
Please note that the Travis failure has noting to do with the code itself. It seems atom.io was unavailable... Travis was triggered by rebasing my PR on v1.0.0. |
|
@maxbrunsfeld it's been a pretty silent week... Any change you could pick this one up again? Thanks! |
|
Sorry @svanharmelen. I forgot to let you know that I was on vacation last week. Testing now... |
|
Ok, looks good. I like the way that you cleaned up |
|
@maxbrunsfeld sure thing, I'll update the PR shortly so we keep using And to be better inline with the naming TextMate uses, I will also rename Will update as soon as atom/language-go#47 is merged so the tests can use the update name to confirm all is still good and we can get this one merged in 😃 |
|
Kudos to @svanharmelen for the persistence and patience on this! |
|
@maxbrunsfeld just updated the PR like discussed yesterday... |
I'm not sure if makes sense to adopt that naming convention. TextMate's /cc @nathansobo what do you think about naming here? |
|
@maxbrunsfeld you could have saved me some time and effort if you would have told me this yesterday after I suggested the change, instead of now after I updated But I'm fine either way so please let me know how you want it and I'll make it so... |
|
Yeah, please keep in mind that we're dealing with hundreds of existing language bundles. The value of changes, even if the names are more optimal, needs to be weighed against the cost of forcing everyone to change or the potential confusion caused by supporting two options that do the same exact thing. We need to be conservative with changes and find ways to blend in with what exists the best we can. I wish that weren't the case, and sometimes it will be worth it to make a breaking change. In the case of these regex names I don't think it is. |
|
So, to clarify, I think |
|
@nathansobo I'm fully aware of the impact and agree it's important to get the naming right... So I'm perfectly fine with having this discussion 😃 Will update and rebase the PR in a few... |
…g a 3rd regexp Currently there are only two regexps that can influence the indents. Those are `increaseIndentPattern` (which tells Atom the indent of next line should be increased) and `decreaseIndentPattern` (which tells Atom the indent of the current line should be decreased). But I found that a couple of languages would need a 3rd regexp in order to support their use cases. This 3rd regexp should be a mixture of the existing two so it tells Atom that the indent of the next line should decrease. I’ll add a screencast to show a use case for this 3rd regexp which I would like to call `decreaseNextIndentPattern`.
|
Alright. This thing's done. 🍴 Thanks for sticking with it @svanharmelen. |
Change hard coded restrictions to enable more correct indentions
|
Great job @svanharmelen! |
|
@maxbrunsfeld thank you too for sticking with me as well 😉 |
|
This was just released in Atom 1.0.2, thanks @svanharmelen 👍 |
|
Cool 😃 One thing left I assume... Documenting the new |
|
@svanharmelen Ideally in the Flight Manual at least, specifically in https://github.com/atom/docs/blob/master/book/03-hacking-atom/sections/xx-language.asc, but unfortunately that section was never finished it seems like. Maybe you feel like taking on the challenge of beginning to document the language grammar support in Atom? That'd be amazing ✨ |
|
Uuh... Hmm... Think I'll have to think about that one 😉 But thanks for the info! |


Currently the hard coded restrictions prevent some very valid use cases (will add a before and after screencasts at the bottom) and limit the possibilities to implement correct indentation.
Before:

As you can see here the bracket isn't indented correctly when moving it to the next line. The decreaseIndentPattern is correct as it does increase when removing and typing in the bracket again on the same line.
After:

After removing the hard coded restrictions, the bracket is indented as expected.