-
Notifications
You must be signed in to change notification settings - Fork 17.3k
Implementing tree-sitter based indentation logic #18321
Conversation
|
Sorry about those linting errors. I'll fix them. |
|
This is very, very cool. @chfritz Just letting you know - because this is a big and important new feature, (and we're currently addressing regressions that we discovered after enabling Tree-sitter by default), it will probably take some time for us to get to this and review it. But I'm definitely very interested. Some initial questions:
|
b3e5448 to
98c7578
Compare
|
@maxbrunsfeld : sorry for the delay in responding. I somehow broke my dev mode (it keeps crashing with a segfault), and haven't been able to try a few things on Item 1 that I wanted to try. I'll get back to you as soon as I get past this impasse. On Item 2: that's a really interesting idea. I need to think this through further. I'm not yet sure whether the correct (i.e., desired) indentation can be inferred from just one example in all cases, or how many variables the implied set of equations has. If the only logic is scopes, then yes, this should be possible. But those additional conditions (Item 1) seem to span a much bigger space. The current solution actually already provides a fair bit of room for customization, because users can decide for themselves which scopes should cause indentation. That way, issues that are more of a matter of opinion such as atom/language-javascript#298 can be made a thing of the past. |
98c7578 to
2f321e4
Compare
33da130 to
c547d98
Compare
|
@maxbrunsfeld at long last I've gotten my dev-mode back into a working condition to test changes to this PR. I evaluated translating the code-based config to something declarative, but that was just getting too convoluted. So I've now gone the other way you suggested and moved all config to code, see my example for language-javascript. I think this is ready for review now. |
c547d98 to
9e32f61
Compare
…core See this PR in atom/atom: atom/atom#18321. Once the other PR is merged, this one then fixes atom#594. Updated: now without the need for a callback function as part of configuration
c8257b3 to
92550d0
Compare
|
Good news, @maxbrunsfeld , I was wrong! I did find a way to get rid of the non-declarative part of the configuration after all. The language-specific configuration is now all declarative as it should be: https://github.com/atom/language-javascript/pull/608/files. |
|
Woah, that’s looking very very clean. Nice work, @chfritz! |
f35e656 to
4979677
Compare
|
Thanks! |
|
@chfritz This sounds pretty awesome. Unfortunately, before we can spend a bunch of time reviewing it, we're going to need comprehensive tests added so that we can ensure we don't accidentally regress any of the functionality you've painstakingly built here. |
|
I'd be happy to write some tests, but unfortunately I'm still having a hose of issues with my source build on Linux. My dev mode crashes all the time, and when I try to run tests I get: This doesn't seem to depend on the specs I'm testing. Even some of the tiniest specs fail: This is after a clean checkout of master, Furthermore I have been struggling with issues of this sort since end of October and frankly, they make developing for atom.io quite annoying. Any idea what might be going wrong? By now I've spent more time trying to debug why the development environment doesn't work than I've spent on the actual contribution I'm trying to make. For completeness: |
798fd8a to
35677c5
Compare
|
I was able to develop and add tests by using the deb-package installation of atom (9 tests, 292 assertions). The bulk of the test cases are defined in terms of correctly indented sample files. For each of these tests it is verified that the proposed indentation matches the one in the file. |
…core See this PR in atom/atom: atom/atom#18321. Once the other PR is merged, this one then fixes atom#594. Updated: now without the need for a callback function as part of configuration
|
Hey! 👋 We have recently started using This is good news: now the Atom code is more consistent and it's much easier to re-format the code to follow the codestyle (now you only need to run This change caused conflicts on your PR that we have automatically solved, hope you don't mind 😄 With ❤️, the Atom team. |
|
It's now been almost a year since I've opened this PR and more than six months since finishing all requested changes. Are there any plans to still consider this, or will this PR go the same route as the one I opened three years ago, which never got merged? It's a little frustrating to work on something that was endorsed by the core developers and then see it being ignored forever and ever. |
|
PS: needless to say that this PR is yet again out of date by now I need to put more work into catching up with changes that happened elsewhere. But I'd like to have some assurance that all that work is not for nothing. |
|
This is amazing. Apparently this PR has inspired tree-sitter based indentation logic for both emacs and neovim. Both of these seem to have been merged. Maybe if we give it another two years we can put a plan together to merge this into atom as well? |
30b6344 to
0f2e90a
Compare
|
@chfritz I know this has been long overdue. I have resolved some conflicts on this PR to give you an easy time should you choose to fix the failing tests. |
|
Thanks, @sadick254 . Glad to hear this effort may not have been in vein. I'd be happy to try and fix the failing tests, but to be honest, I can't quite decipher them. What has to do with my code? But I can try to work on this one, which seems to be about the should-be indentation. |
|
@chfritz For now you can ignore any errors that are not relevant to the indentation work. |
|
I think the test that is failing is just about specifying what is correct indentation. The new logic changes the indentation -- to the better, I would argue, of course. So the "fix" would be to change the specification. |
|
@chfritz No worries. Just let me know if you need any assitance. I am keen to see this go through. |
|
I've been trying to compile atom for the last two days, with no luck. It gets stuck on this bizarre error: Any advise? |
|
ok, I got past that by upgrading the version of vscode-ripgrep to the latest. Now I get: |
|
Could you try running |
c964f1c to
10c4b7b
Compare
- Four days of work to get those damn test to run again, just for a two character change to fix the tests. - Now also added all other, minor changes to sane-indendation over the last five years since the PR for this change was opened.
10c4b7b to
98f3082
Compare
|
@sadick254 : at long last I've been able to get atom to compile again (in a lxc container), migrate my changes (had to manually re-add all changes, since the package-locks seem to have been messing things up), and fixed the issue. The fix was trivial -- literally just removing a All tests are now passing. Looking forward to having this PR finally get merged -- five years after making my first attempt to improve the indentation logic. Thanks for your help and for picking this back up! |
sadick254
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very good. It's working well as I expected. Thank you for the awesome work @chfritz.
Issue or RFC Endorsed by Atom's Maintainers
This approach was supported by @maxbrunsfeld in atom/language-javascript#594 (comment). It also addresses a number of indentation logic related issues such as #6655, atom/language-javascript#560, and potentially others.
Description of the Change
Implements a tree-sitter based indentation logic. This was previously developed and tested in the sane-indentation package (> 0.9). Refer to atom/language-javascript#594 (comment)
By itself this does nothing. The new logic is only used if the language package for the current language contains the necessary configuration (e.g., which scopes to indent on). So this PR goes together with, e.g., atom/language-javascript#608 in language-javascript.
Alternate Designs
I went through a number of iterations developing this code in the sane-indentation package. I first used the scopes array directly, but found that it only got me so far because it was lacking context. So I switched to this new tree-walk approach. It is more concise and has more context to make indentation decisions on. As reported in atom/language-javascript#594 (comment), I found this enough to implement proper indentation for a variety of languages.
Possible Drawbacks
I have not found any cases where the new indentation logic is worse that the previous, regex based logic. In particular it uses the already-present parse tree from tree-sitter, so it seems faster and more comprehensive.
Verification Process
I developed this code over the course of the last two months in the sane-indentation package (which monkey patches the
suggestIndentForBufferRowfunction to replace the atom indentation logic with this new logic. As proposed by @maxbrunsfeld (atom/language-javascript#594 (comment)), I worked on adding support for other languages besides javascript to make sure the logic is general enough to support various types of languages. As reported in atom/language-javascript#594 (comment), I found this logic sufficient for implementing proper indentation for Javascript (incl. JSX), HTML, Python, C and C++. I have not yet tried others.The most comprehensive test was using this new logic in my every-day development (Javascript, JSX, and HTML) for over a month now.