7 ms·
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
by srcreigh 6y ago
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 https://github.com/ubolonton/emacs-tree-sitter
[2]: https://ubolonton.github.io/emacs-tree-sitter/ https://ubolonton.github.io/emacs-tree-sitter/
[3]: https://github.com/ubolonton/emacs-tree-sitter/issues/66#issuecomment-778692779 https://github.com/ubolonton/emacs-tree-sitter/issues/66#iss...
- lalaithion 6y agoMaybe I can finally have this syntax highlighting style: https://youtu.be/b0EF0VTs9Dc?t=900 https://youtu.be/b0EF0VTs9Dc?t=900
- srcreigh 6y agoThere 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 https://github.com/alphapapa/prism.el
- jackcviers3 6y agoRainbow delimiters mode kind of does this, but doesn't maintain the scope color of referenced variables.
- brundolf 6y agoThe idea is pretty awesome, but my eyes nearly rolled out of my head from the needless condescension at the beginning.
- chewxy 6y agoit'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.
- deleted 6y ago[deleted]
- nerdponx 6y agoI 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.
- cat199 6y agoif 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" :)
- nerdponx 6y agoI'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.
- komodo009 6y agonvim-treesitter is pretty promising, do you know if it supports this type of highlighting already?
- dcreager 6y agoWorth 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/queries https://github.com/tree-sitter/tree-sitter-go/tree/master/qu...
- eins1234 6y agoAwesome 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.
- The_rationalist 6y agohttps://github.com/microsoft/vscode/issues/77140 https://github.com/microsoft/vscode/issues/77140
- rgossiaux 6y agoNeovim 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.
- mkingston 6y agoThe 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 https://github.com/neovim/neovim/milestone/19
- tazjin 6y agoA 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-sitter-move https://cs.tvl.fyi/depot/-/tree/users/Profpatsch/emacs-tree-... The potential for this is essentially something like Paredit, but for all languages.
- yewenjie 6y agoCan someone point some examples of what `paredit` for other languages provide? I do various lisp programming occasionally but have not used `paredit` yet.
- tazjin 6y agoCheck out this video for a quick demo: http://emacsrocks.com/e14.html 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.
- z3t4 6y agoLooks 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.
- tazjin 6y agoIt'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.
- mumblemumble 6y agoI 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.
- robto 6y agoI'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 :)
- Annili 6y ago> "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`
- eins1234 6y agoDon'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/ https://darklang.com/
- josteink 6y agoTooting 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/csharp-tree-sitter.el https://github.com/emacs-csharp/csharp-mode/blob/master/csha...
- ywei3410 6y agoThis looks awesome! Do you mind elaborating on any kinks which you found?
- josteink 6y agoA 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.
- ubolonton_ 6y agoWhen 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 https://github.com/tree-sitter/tree-sitter/issues/930