Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Adding configuration for new, tree-sitter based indentation logic #608

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chfritz
Copy link

@chfritz chfritz commented Oct 25, 2018

Description of the Change

This adds the configuration needed for the new, tree-sitter based indentation logic. That new logic is implemented in this PR in atom/atom: atom/atom#18321.

Once that PR is merged, this one then fixes #594.

Alternate Designs

Since this only adds configuration, the real discussion about alternate design is in atom/atom#18321.

Benefits

Fixes several indentation issues that all arise from the fact that the previous regex based logic was inductive (i.e., only based on the previous line). This prevented the implementation of certain patterns that seem preferred by users (and seem more correct). See, e.g., atom/atom#6655 and others.

Possible Drawbacks

I'm not a huge fan of how I'm adding the functional configuration (precedingRowConditions) to the grammar. This clutters the namespace in that object a little (but not much). Other than that I don't see any downsides. -- this has now been improved to where precedingRowConditions is no longer required.

Applicable Issues

atom/atom#6655
#476
#560
to name a few.

…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
@chfritz
Copy link
Author

chfritz commented May 31, 2021

Now that atom/atom#18321 is merged, merging this PR will enable the new tree-sitter based indentation for javascript. See https://github.com/atom/atom/pull/18321/files#diff-2b51afa53cf043f5ac43123d778c7717f22c18ba3debe76fd34f4e1d0da9c416 for samples of this indentation. One of the main motivations for it was unbalanced closing brackets, which currently cause very bad indentation, e.g.:

if (test) {
  foo( 2, {
    sd,
    sdf
  },  // not ideal
  4 // not ideal
); // wrong
should_be_indented(); // wrong
}

This is happening because the current indentation logic in Atom is only based on the previous line and doesn't count all opening scopes (as was proposed here). This can result in negative indentation as seen above.

The new logic is using the parse tree provided by tree-sitter to get things like that right:

if (test) {
  foo( 2, {
      sd,
      sdf
    },
    4
  ); // correct
  should_be_indented(); //correct
}

FYI, @sadick254 .

@chfritz
Copy link
Author

chfritz commented Jun 4, 2021

The failing tests don't seem to be related to the changes in this PR.

@sadick254
Copy link
Contributor

@chfritz am working on resolving those errors. We should be good to go once resolved.

@chfritz
Copy link
Author

chfritz commented Feb 13, 2022

Hi @sadick254 , I saw that atom 1.59 was released, including the tree-sitter based indentation logic. That's exciting! Now once we can merge sort out the issues with this PR and merge it, people will see the benefits and we should be able to close a number of indentation related issues. Let me know how I can help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement new indentation logic based on tree-sitter
2 participants