-
Notifications
You must be signed in to change notification settings - Fork 17.3k
Allow Tree-sitter parsers to be used for syntax highlighting and code folding #16299
Conversation
Much of this is from the tree-sitter-syntax package. Also, add a dependency on the tree-sitter module.
8e119d0 to
256ed1a
Compare
|
\o/ bravo \o/ |
256ed1a to
4be3c85
Compare
a73db2a to
cd97b4e
Compare
cd97b4e to
273d708
Compare
Signed-off-by: Nathan Sobo <[email protected]>
Signed-off-by: Nathan Sobo <[email protected]>
|
@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). |
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.
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.
|
@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: |
|
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 |
|
@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. |
Overview
This pull request adds a new config setting to Atom:
core.useTreeSitterParsers, which defaults tofalse. If you set that setting totrue, 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:
would previously fold like this:
Now, we are able to fold it like this:
or, if you choose to fold the first two lines:
New Editing Commands
This PR adds two new text editing commands:
editor:select-larger-syntax-nodeandeditor:select-smaller-syntax-node. These commands can be used to quickly select syntactically meaningful units of code:Example
Multi-Cursor Example
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.