7 ms·
How to Get Started with Tree-Sitter
- nico 3y agoThere is a very cool gif demo at the bottom showing contextual editing with multiple cursors using an extension Some pictures/video or gif would have been really nice at the top of the article to get a quick idea of what I’ll be able to get by following the guide
- nektro 3y agotitle should include "in Emacs"
- gumby 3y agoGiven how powerful Emacs is and how important it has been for my computing over the past four decades, I think it would be more useful to me for people to label all non-emacs articles [Not Emacs]
- bitwize 3y agoEmacs is relatively obscure now. It is most practical to assume that all editor-related articles are about Visual Studio Code unless indicated otherwise, since a majority of developers use that. Vim if the article concerns in-terminal editor use.
- 0x457 3y agosar·casm noun: sarcasm; plural noun: sarcasms the use of irony to mock or convey contempt. "his voice, hardened by sarcasm, could not hide his resentment"
- toadi 3y agohis voice hardened... I didn't hear that in the comment. Maybe /s at the end of the comment would have helped missing out on the body language or verbal queues. /s
- pcstl 3y agoI think adding "in Emacs" to the title of an article published on Mastering Emacs Dot Org might be a bit redundant.
- agumonkey 3y agosome times a bit of redundancy doesn't hurt
- mekster 3y agoIs everyone supposed to comprehend the domain name of the post?
- wafflemaker 3y agoScrolled over the title (thought it was some programming algorithm concept) and then by chance I've read the site name saying it's about Emacs which prompted me to open the discussion. Maybe on some setups the site name is not as easily visible as the title?
- layer8 3y agoWhat’s visible on the HN page is “masteringemacs”, which is just nonobvious enough to parse (“master in <whatever>”) that it doesn’t register.
- z3t4 3y agoI take it that many people like the idea with tree-sitter but don't really know how to use it. Tree-sitter does have documentation but it's not that useful. It would be interesting to know how many sales you get from a niche book like this though.
- alwaysbeconsing 3y agoThere's not much end-user documentation the Tree-sitter project can really provide. It's a programming interface. The stuff that an Emacs, NeoVim, ... user is actually interacting with depends on the integration in the editor. So it's up to those docs to explain what features they expose based on Tree-sitter. For example, the multiple cursor thing at the end is enabled by having the concrete syntax tree from Tree-sitter's parse, but Tree-sitter has nothing whatsoever to do with the cursors: it just provides locations in the text based on particular queries (like "all `identifier` nodes named 'foo' that are sub-nodes of this other node"). Even the headliner feature, syntax highlighting, isn't provided directly by Tree-sitter. It's up to the client system to inspect the syntax tree and apply attributes to its rendered text -- however it does that rendering.
- nerdponx 3y agoThe query language and CLI tools are absolutely user-facing features on their own. But even if they aren't, developers still need to be able to learn from the docs. Currently that's very difficult to do. My experience is that you have to rely heavily on copying other people's examples in order to make progress.
- alwaysbeconsing 3y agoPoint taken about the developer documentation. But the query language is only user-facing if the tool you're using exposes it. And the CLI only if you need to build your own grammars; I expect that to be less and less common as time goes on.
- nerdponx 3y ago
- audiodude 3y agoThis is so hopeless complicated that I'm glad I use VSCode and not Emacs anymore. Sheesh.
- okasaki 3y agoOK? It's feature in development. Eventually emacs 29 with tree sitter will be part of distro packaging, and it will just be an "apt install emacs" away.
- audiodude 3y agoThat's not the impression I got from TFA. It sounds like, once you have Emacs compiled with tree-sitter, you also need to have a language binding in a shared library in a known location (that you have to compile yourself or depend on the kindness of strangers). And once you have that, you actually need someone to write a major mode that utilizes it at all. And if you want to make that major mode the default for that file type, there are a few other things you need to do. Etc.
- slondr 3y agoI use emacs 29 beta right now and that is just not how it works. For example for elixir you just install elixir-ts-mode like any other package, answer yes to the prompt to install the elixir ts library, and you’re done. Even that setup step will be unnecessary in emacs 30, when all this stuff will be shipped by default.
- audiodude 3y agoOkay, that's a good thing! From the article: > Neither tree-sitter nor Emacs come installed with language grammars > ...it’ll only work if you don’t have an exceptional setup (so it won’t work well unless you have GCC and run some flavor of Linux.) > Determining if a grammar is available is not intuitive nor obvious unless you use elisp > Note that, just because you have installed a grammar, does not mean Emacs supports it. Someone still has to write the – admittedly, way easier – syntax and indentation logic and all that good stuff. > Annoyingly, there’s no easy way to see if you’re using the normal or the TS-powered major mode > If you use Customize, then you don’t have to do anything, but if you normally use setq, you’ll have to use customize-set-variable instead to ensure the setter is called properly. > That sounds like a great idea until you realize that it is not possible to make one-size-fits all commands that do this. Believe me: I’ve tried.
- d357r0y3r 3y agoIt feels like people use these editors for the novelty of it and not because it's truly the best for productivity.
- okasaki 3y agoAh yes, the novelty of using emacs, an editor that started in 1976.
- deleted 3y ago[deleted]
- Barrin92 3y agofact aside that I don't think I've ever heard emacs associated with novelty (the thing is as old as Stonehenge), I wish this productivity cult would die. Programming is fun and play. Discovery and experimentation are great things.
- snapdaddy 3y agoI will treat your comment as serious and explain why I personally use emacs. The thing I love most about emacs is that it is joyously consistent. The same key combination to jump ahead by a word works everywhere, such as when you're opening files or navigating directories. This consistency means that I am often very efficient trying new packages that I have never used. Maybe you've never seen someone use emacs in anger? If so, check out this video of Steve Yegge doing some stuff in Emacs: https://youtu.be/lkIicfzPBys?t=142 https://youtu.be/lkIicfzPBys?t=142
- avodonosov 3y agoAnyone knows, why github code navigation, which is based on tree-sitter [1], supports only subset of languages for which tree-sitter has parsers [2]? For example, Common Lisp is not supported. I asked github [3], but they are silent. 1 - the "search based" navigation is based on tree sitter https://docs.github.com/en/repositories/working-with-files/using-files/navigating-code-on-github https://docs.github.com/en/repositories/working-with-files/u... 2 - the list of parsers in the official docs: https://tree-sitter.github.io/tree-sitter/ https://tree-sitter.github.io/tree-sitter/ 3 - https://github.com/orgs/community/discussions/55704 https://github.com/orgs/community/discussions/55704
- kfir 3y agoI believe this paper has an answer to your question - https://queue.acm.org/detail.cfm?id=3487022 https://queue.acm.org/detail.cfm?id=3487022
- avodonosov 3y agoThank you very much for the link. I don't see an answer in there, though. They use tagging (as described also here: https://tree-sitter.github.io/tree-sitter/code-navigation-systems https://tree-sitter.github.io/tree-sitter/code-navigation-sy...). From both docs I assume `tree-sitter tags` works out of box for any language that has a parser. (Since neither doc instructs to save a custom config for tag extraction query, I assume every language plugin provides tagging queries).
- awayto 3y agoI worked with tree sitter a bit for a small project. It seems to be the case that, while it covers a large set of languages, the actual implementation of each subset doesn't follow the exact same underlying API. And it follows that there is no universal AST parser as far as I can tell. Languages have many types of atomic parts to such an extent that unifying them is a tremendously complex task.
- avodonosov 3y agoHave you used the `tree-sitter tags` command?
- xvilka 3y agoIn my case, Tree-Sitter grammar for C has many shortcomings (ignore preprocessor bugs, they can't be solved in the current TS model anyway): https://github.com/tree-sitter/tree-sitter-c/issues https://github.com/tree-sitter/tree-sitter-c/issues
- gHA5 3y agoI used Tree-sitter to navigate and extract syntactic information from source code files in multiple programming languages. It was great that I didn't have to use multiple parser (generator) libraries.
- distantsounds 3y ago[flagged]
- hifikuno 3y agoFocusing on the Tree-Sitter side, it's something I've been meaning to look into. We have a lot of Oracle SQL files that make up our ETL pipeline at work, and I would love to be able to visualize the flow of the data. I know there are some products out there but our ETL was written from scratch without any tooling besides Oracle SQL and bash scripts (and cron). I feel like a well written Tree-Sitter grammar should allow me to parse the files and follow the data from source to dashboard.
- nerdponx 3y agoI believe there is a grammar for SQL, but it probably doesn't support a lot of the vendor-specific language extensions you might be using. You could end up writing your own grammar or heavily extending any grammar that already exists. There might already be libraries specific to parsing Oracle SQL into a syntax tree, at which point Tree Sitter isn't really adding value. That said, the ability to query for things like "all SELECT statements where table 'xyz' is referenced in any table identifier" is very powerful.
- hifikuno 3y agoThat's a good idea, that would save me starting from scratch. We do use a fair bit of vendor-specific language, would be cool to make a good Oracle version and then commit back to the project.
- nanna 3y agoMickey Peterson's writing is like that of an explorer charting wildernesses that only a few have yet had the capacities to visit.
- ossusermivami 3y agoi am in awe how emacs is able to reinvent itself again and again, (along with vim/neovim)..