News for hackers. Stuff that matters.
Re:Tree-sitter: an incremental parsing system for programmin... by srcreigh on Monday February 22, 2021 @11:30AM (#26226392)
Tree Sitter is amazing. The parsing is fast enough to run on every keystroke. The parse tree is extremely concise and readable. It resembles an AST more than a parse tree (ie no 11 levels of binary op precedence rules in the tree). The parse tree emits specific ERROR nodes, so you can get a semi-functional tree even with broken syntax.

I can't wait for the tools to get built with this. Paredit for TypeScript. Syntax-tree based highlighting (vs regex highlighting). A command to "add an arg to current function" which works across languages. A command to add a CSS class to the nearest JSX node, or to walk up the tree at the className="| ..." position, adding a new className if it doesn't exist.

There's a nicely documented Emacs package for this [1]. The documentation is at [2]. The parse trees work great. There's syntax highlighting support and tree-walking APIs. There's a bit of confusion about TSX vs typescript langs but it's fixable with some config change [3].

[1]: https://github.com/ubolonton/emacs-tree-sitter [2]: https://ubolonton.github.io/emacs-tree-sitter/ [3]: https://github.com/ubolonton/emacs-tree-sitter/issues/66#iss...

Re:Tree-sitter: an incremental parsing system for programmin... by dcreager on Monday February 22, 2021 @12:24PM (#26227214)
Worth calling out that the syntax highlighting support is used to highlight several languages in github.com. (Linguist is still used for the long tail of languages, but we plan to migrate more and more over to tree-sitter-based highlighting over time.)

The query language is also what's used to drive the fuzzy/ctags-like Code Navigation feature. Both of those are powered by tree-sitter query files defined in each language's repo, like these for Go: https://github.com/tree-sitter/tree-sitter-go/tree/master/qu...

Re:Tree-sitter: an incremental parsing system for programmin... by eins1234 on Monday February 22, 2021 @04:52PM (#26231155)
Awesome to hear that amazing tech like tree-sitter lives on even though Atom, the product it was built for, is pretty much on life support at this point.

Curious if there's any efforts to bring tree-sitter to VSCode? Exposing tree-sitter to extensions could open up so many possibilities like OP mentioned.

Re:Tree-sitter: an incremental parsing system for programmin... by The_rationalist on Monday February 22, 2021 @07:23PM (#26232435)
Re:Tree-sitter: an incremental parsing system for programmin... by tazjin on Monday February 22, 2021 @01:03PM (#26227850)
A friend of mine started working on an experimental Emacs mode to provide structural navigation of code based on tree-sitter: https://cs.tvl.fyi/depot/-/tree/users/Profpatsch/emacs-tree-...

The potential for this is essentially something like Paredit, but for all languages.

Re:Tree-sitter: an incremental parsing system for programmin... by yewenjie on Monday February 22, 2021 @02:52PM (#26229647)
Can someone point some examples of what `paredit` for other languages provide? I do various lisp programming occasionally but have not used `paredit` yet.
Re:Tree-sitter: an incremental parsing system for programmin... by tazjin on Monday February 22, 2021 @03:09PM (#26229881)
Check out this video for a quick demo: http://emacsrocks.com/e14.html

If you know a Lisp I recommend just giving paredit a spin for a few minutes, it's an interesting experience.

Re:Tree-sitter: an incremental parsing system for programmin... by z3t4 on Monday February 22, 2021 @03:29PM (#26230124)
Looks like it's mainly tree/code manipulation. Typing code on the keyboard is probably the least taxing thing when it comes to software development. But I guess it will be nice once it has become a "reflex" rather then a conscious key-combo.
Re:Tree-sitter: an incremental parsing system for programmin... by tazjin on Monday February 22, 2021 @04:11PM (#26230689)
It's not so much about reducing the amount of characters typed, and instead moving the way you think about code from the character level to a more structural level.

Calling it a "reflex" is an interesting phrase! Tools like magit let me encode complicated processes into muscle memory, in a way where retrieval doesn't have to go through remembering and typing a string. Structural editing is similar.

Re:Tree-sitter: an incremental parsing system for programmin... by coldtea on Monday February 22, 2021 @09:44PM (#26233300)
It's not about easier typing.

It's about typing code, as opposed to typing text, with all the structural, highlighting, auto-formatting, auto-completion, error-detection, etc advantages this brings.

Re:Tree-sitter: an incremental parsing system for programmin... by mumblemumble on Monday February 22, 2021 @05:54PM (#26231785)
I only started using it a few months ago. It's such a natural way to edit code, it only took me about a day for it to become reflexive.

Now it just feels vaguely annoying to work without it. It's fine, it's just one of those ergonomic changes that nags at you a bit. Kind of like the opposite of that feeling of taking off uncomfortable business clothes at the end of the day. Or what I imagine people who are better at vim than me keep talking about.

Re:Tree-sitter: an incremental parsing system for programmin... by roninhacker on Monday February 22, 2021 @09:36PM (#26233256)
It's not just saving keystrokes. It eliminates a whole class of errors. I recently did ~4-500 lines of Clojure in CodeMirror and wanted to kill myself by the end of it.
Re:Tree-sitter: an incremental parsing system for programmin... by throwaway_2047 on Tuesday February 23, 2021 @01:13AM (#26234315)
Can someone recommend what's the best material to learn emacs and lisp at the same time
Re:Tree-sitter: an incremental parsing system for programmin... by josteink on Monday February 22, 2021 @05:06PM (#26231316)
Tooting my own horn, Emacs’ csharp-mode[1] is undergoing a rewrite to be 100% based on tree-sitter rather than regexps.

The new code runs way faster and is so much nicer to work with.

Once all the kinks are gone, I can’t imagine going back.

[1] https://github.com/emacs-csharp/csharp-mode/blob/master/csha...

Re:Tree-sitter: an incremental parsing system for programmin... by ywei3410 on Monday February 22, 2021 @06:53PM (#26232229)
This looks awesome! Do you mind elaborating on any kinks which you found?
Re:Tree-sitter: an incremental parsing system for programmin... by josteink on Tuesday February 23, 2021 @10:13AM (#26238162)
A few:

- indentation may be fine for a final doc, but not always while editing. Especially for new lines starting new code-blocks.

- adding new syntax not already known by tree-sitter requires up streaming to at least 2 repos before we can use it in a released version of our package. This can feel less hands on and slow than working in a single repo where you have full control.

No super-biggies yet though.

Re:Tree-sitter: an incremental parsing system for programmin... by ubolonton_ on Tuesday February 23, 2021 @11:11PM (#26246503)
When tree-sitter reaches 1.0 [0], it may be possible to eliminate the tree-sitter-langs upstream, or both.

[0]: https://github.com/tree-sitter/tree-sitter/issues/930

Re:Tree-sitter: an incremental parsing system for programmin... by rgossiaux on Monday February 22, 2021 @12:42PM (#26227516)
Neovim nightly already has some tools available as plugins. I'm using tree-sitter for syntax highlighting, text objects, and folding right now. Pretty satisfied so far.
Re:Tree-sitter: an incremental parsing system for programmin... by mkingston on Monday February 22, 2021 @01:35PM (#26228397)
The official release of built-in treesitter comes with neovim 0.5. Which looks like it'll be out pretty soon. I've been watching a fairly steady march toward release here: https://github.com/neovim/neovim/milestone/19
Re:Tree-sitter: an incremental parsing system for programmin... by robto on Monday February 22, 2021 @01:28PM (#26228252)
I'm so excited for this to become built-in in more places! I think once non-lisp users can experience the Power of Structural Editing they'll say, "Hey, I understand now why you all feel so passionate about your parentheses!"

And I can stop feeling like my fingers have all lost a knuckle when I'm writing Typescript :)

Re:Tree-sitter: an incremental parsing system for programmin... by lalaithion on Monday February 22, 2021 @12:15PM (#26227084)
Maybe I can finally have this syntax highlighting style: https://youtu.be/b0EF0VTs9Dc?t=900
Re:Tree-sitter: an incremental parsing system for programmin... by srcreigh on Monday February 22, 2021 @12:57PM (#26227748)
There is an emacs package for this (maybe beta). I can't remember the name of it and Google is failing me.

EDIT: finally found it https://github.com/alphapapa/prism.el

Re:Tree-sitter: an incremental parsing system for programmin... by jackcviers3 on Monday February 22, 2021 @01:19PM (#26228085)
Rainbow delimiters mode kind of does this, but doesn't maintain the scope color of referenced variables.
Re:Tree-sitter: an incremental parsing system for programmin... by brundolf on Monday February 22, 2021 @05:21PM (#26231470)
The idea is pretty awesome, but my eyes nearly rolled out of my head from the needless condescension at the beginning.
Re:Tree-sitter: an incremental parsing system for programmin... by chewxy on Tuesday February 23, 2021 @05:25AM (#26235668)
it's just how old people talk. Rob Pike speaks of syntax colouring in the same way - he quotes the Bible.

I don't see it as condescension though. I think it's just a way of speaking.

Re:Tree-sitter: an incremental parsing system for programmin... by nerdponx on Wednesday February 24, 2021 @12:14PM (#26252536)
I know plenty of "old people" who don't talk like this. In fact, the "old people" that I respect tend to be a lot more open-minded.

It's one thing to joke about it a little, but this is just arrogance on display with obvious derision for us children who find that traditional syntax highlighting is beneficial.

I recall reading once that Vim tabs were a crutch for people who "can't remember what they're working on". It's the same kind of arrogance and presumptiveness.

Re:Tree-sitter: an incremental parsing system for programmin... by nerdponx on Tuesday February 23, 2021 @12:05AM (#26233991)
I'm pretty sure you can implement this in Neovim with Tree Sitter now.

This would be a wonderful idea in any programming language.

But I agree with the other commenter that this speaker is really condescending. Not a person I'd want to work with.

Re:Tree-sitter: an incremental parsing system for programmin... by komodo009 on Tuesday February 23, 2021 @01:03AM (#26234265)
nvim-treesitter is pretty promising, do you know if it supports this type of highlighting already?
Re:Tree-sitter: an incremental parsing system for programmin... by cat199 on Monday February 22, 2021 @09:13PM (#26233127)
if your mute is on, accompanying audio states:

"You've all seen syntax coloring, right? That's something we put in our text editors to make it easier for kindergardeners to do programming"

:)

Re:Tree-sitter: an incremental parsing system for programmin... by Annili on Monday February 22, 2021 @04:00PM (#26230533)
> "Paredit for TypeScript"

Is there a list of ideas for Structural Editing in C-like languages?

I can think of `extend-selection, `move to parent block`, `add arg to function`

Re:Tree-sitter: an incremental parsing system for programmin... by eins1234 on Monday February 22, 2021 @07:49PM (#26232609)
Don't have a list, but Dark is doing some really cool things with an editor that depends pretty much exclusively on structural editing (i.e. you can't even make a syntax error if you tried): https://darklang.com/