Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Conversation

@maxbrunsfeld
Copy link
Contributor

@maxbrunsfeld maxbrunsfeld commented Nov 30, 2017

Overview

This pull request adds a new config setting to Atom: core.useTreeSitterParsers, which defaults to false. If you set that setting to true, when editing files written in certain languages, Atom will use a new parsing system called Tree-sitter to provide improved syntax highlighting and code folding.

Syntax Highlighting Improvements

Using the syntax trees provided by Tree-sitter, we can produce syntax highlighting that is more consistent and specific than before. Different kinds of names in your code like types, functions, properties/fields, and local variables should be grouped by color in a more consistent way.

The new syntax highlighting uses the same CSS classes as the old system, so you should be able to continue using your current themes without disruption.

Code Folding Improvements

Currently, Atom's code folding is based on indentation: in a fold, lines with greater indentation are hidden. This usually gives good results, but it is unintuitive in some cases. Now, by basing the code folding on the syntax tree provided by Tree-sitter, we can fold code in an intuitive way regardless of its indentation.

Example

Code like this:

int add(int left,
        int right) {
  return left + right;
}

would previously fold like this:

int add(int a

Now, we are able to fold it like this:

int add(int left,
        int right) {…}

or, if you choose to fold the first two lines:

int add(…) {…}

New Editing Commands

This PR adds two new text editing commands: editor:select-larger-syntax-node and editor:select-smaller-syntax-node. These commands can be used to quickly select syntactically meaningful units of code:

Example

extend-selection-2

Multi-Cursor Example

extend-selection-3

Supported Languages

Initially, the following languages will be supported:

Next Steps

The new parsing system is disabled by default because there are some known bugs and it needs more testing before we roll it out to all Atom users. After this PR lands, I'll be focused on fixing bugs in the new parsing system and the existing grammars so that soon, we can enable the new parsing system by default.

Much of this is from the tree-sitter-syntax package.
Also, add a dependency on the tree-sitter module.
@maxbrunsfeld maxbrunsfeld force-pushed the mb-tree-sitter-parsers branch from 8e119d0 to 256ed1a Compare November 30, 2017 04:34
@alexandernst
Copy link

\o/ bravo  \o/

@maxbrunsfeld maxbrunsfeld force-pushed the mb-tree-sitter-parsers branch from 256ed1a to 4be3c85 Compare November 30, 2017 17:32
@maxbrunsfeld maxbrunsfeld force-pushed the mb-tree-sitter-parsers branch 3 times, most recently from a73db2a to cd97b4e Compare November 30, 2017 22:13
@maxbrunsfeld maxbrunsfeld force-pushed the mb-tree-sitter-parsers branch from cd97b4e to 273d708 Compare November 30, 2017 22:22
@mkutny
Copy link

mkutny commented Mar 25, 2018

@maxbrunsfeld , really decent feature, thanks for developing it!

Have noticed that the following snipped gets folded non-intuitively (as to my eyes). Want to know if it works as designed or I should open an issue.

Code likes this:

function add({
  a, b
}) {
  return a + b;
}

Folds into:

function add({}) {
  return a + b;
}

with no possibility to fold further (no angle bracket to the left).

DSpeckhals added a commit to DSpeckhals/python-indent that referenced this pull request Mar 29, 2018
This commit adds the newer `scopeName` for Python. With the new syntax
parsing implemented with Tree Sitter
(atom/atom#16299,
atom/language-python#220), this new scope name
was added. Otherwise, the indentation seems to work as expected.
DSpeckhals added a commit to DSpeckhals/python-indent that referenced this pull request Mar 29, 2018
This commit adds the newer `scopeName` for Python. With the new syntax
parsing implemented with Tree Sitter
(atom/atom#16299,
atom/language-python#220), this new scope name
was added. Otherwise, the indentation seems to work as expected.
@maxbrunsfeld
Copy link
Contributor Author

@mkutny Ah yeah, that's a bug: Atom doesn't know what kind of 'fold arrow' to show in the gutter if a line is foldable and already has one fold. You should still be able to fold the body of the function with the keyboard though: Editor: Fold Current Row is the command; cmd-alt-[ on mac.

@mkutny
Copy link

mkutny commented Apr 21, 2018

Yeah, that's understandable.

Still, one would expect the whole function to collapse, not only its args.

From grammar perspective

function add({
  a, b
}) {
  return a + b;
}

is equivalent to

function add({ a, b }) {
  return a + b;
}

but folding function line gives different results in these two cases.

@maxbrunsfeld
Copy link
Contributor Author

@calebmeyer Just an update on the Ruby parser. It took a long time because of some internal issues, but it's now working well and will be included in Atom 1.30.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.