text stringlengths 0 2.02k |
|---|
[3055.44 --> 3057.34] So that's sort of like the first aspect. |
[3057.68 --> 3064.68] The second aspect is TreeSitter is built in a lot of ways specifically to run like inside |
[3064.68 --> 3068.50] of your text editor as opposed to like an LSP, which is some external process. |
[3069.40 --> 3075.22] So TreeSitter at a high level, for those who don't know, is effectively a library for writing |
[3075.22 --> 3078.70] error recovering incremental parsers. |
[3078.94 --> 3084.96] And it's very good at doing that, which is awesome for text editors because most of the |
[3084.96 --> 3087.88] time when you're writing code, the code is broken. |
[3087.88 --> 3088.40] Right. |
[3088.44 --> 3094.64] If you type a line of code until you get to the semicolon in C, right, it is broken. |
[3094.96 --> 3100.80] So you want to write parsers that can recover and not like drop highlighting for the rest |
[3100.80 --> 3102.68] of the file or do things like that. |
[3102.72 --> 3102.86] Right. |
[3102.88 --> 3107.04] You want to actually do error recovery and smart error recovery. |
[3107.04 --> 3109.42] And that's like quite difficult to do. |
[3109.80 --> 3114.50] But TreeSitter just sort of gives you that for free if you write a grammar in the correct |
[3114.50 --> 3114.86] way. |
[3115.30 --> 3116.66] So that's the first part. |
[3116.98 --> 3119.94] And then the second bit that's very important is that it's incremental. |
[3120.34 --> 3125.16] So it does not reparse the whole tree, which is awesome for when you're typing keystrokes |
[3125.16 --> 3129.48] in a very large file because you're going to smash 80 keystrokes. |
[3129.58 --> 3132.70] You don't want to reparse the entire file 80 times. |
[3132.88 --> 3132.98] Right. |
[3132.98 --> 3137.68] Instead, it actually just incrementally parses the things that it needs to and generates |
[3137.68 --> 3138.46] a new tree. |
[3138.84 --> 3139.88] Does that make sense so far? |
[3139.96 --> 3141.24] Any questions there? |
[3141.64 --> 3142.36] I'm with you. |
[3142.82 --> 3143.06] Okay. |
[3143.38 --> 3147.66] So once again, TreeSitter only focuses on exactly that file. |
[3147.66 --> 3152.32] So this is cool because this lets you do things like you can request highlights for the file |
[3152.32 --> 3156.70] by asking the tree questions and basically getting back named nodes. |
[3156.90 --> 3159.82] You can write queries in this scheme-like language. |
[3159.82 --> 3162.10] It will return to you named nodes. |
[3162.72 --> 3165.02] And then in those nodes, they have ranges. |
[3165.28 --> 3168.10] And so you can color them in your editor if you want. |
[3168.22 --> 3173.72] This is sort of like the thing that everyone recognizes about TreeSitter, but I find somewhat |
[3173.72 --> 3177.60] like the least exciting of all of the TreeSitter technologies. |
[3177.78 --> 3178.86] But it is the most obvious. |
[3178.86 --> 3183.88] And it also makes sense from like a performance perspective that you would like to only change |
[3183.88 --> 3185.70] the highlights that need to be changed. |
[3185.70 --> 3191.64] So this is like a really great improvement and allows you to write much better and powerful |
[3191.64 --> 3196.24] syntax highlighting than you could with like just regexes, which is like the built-in Vim |
[3196.24 --> 3197.34] syntax engine. |
[3197.34 --> 3201.50] And it prevents you from getting these situations where like, I don't know if you've ever had |
[3201.50 --> 3206.66] this, but in certain complicated file types, if you like scroll down the page, sometimes |
[3206.66 --> 3209.90] it like thinks everything in the rest of your file is like a string. |
[3210.12 --> 3211.84] And you're like, what is happening? |
[3212.04 --> 3213.88] Why is this all string? |
[3214.08 --> 3216.96] That can't happen when you have a tree, right? |
[3217.08 --> 3218.90] That's not going to be an option. |
[3218.90 --> 3222.76] So that's sort of like the first level of TreeSitter. |
[3223.16 --> 3225.62] And it doesn't communicate over the wire. |
[3225.98 --> 3230.50] This TreeSitter is running inside of NeoVim and it's like embedded inside of NeoVim. |
[3230.74 --> 3236.70] Now the parsers and the queries and things like that, those are external to NeoVim, can be |
[3236.70 --> 3237.64] configured by users. |
[3238.14 --> 3243.38] I have my own custom grammar for Lua to do some special things, et cetera. |
[3243.46 --> 3247.72] So those are all sort of configurable, but the engine itself is built into NeoVim. |
[3247.72 --> 3248.16] Hmm. |
[3248.92 --> 3252.74] And is the engine something that was built by the NeoVim team or you're actually embedding |
[3252.74 --> 3253.40] somebody else's? |
[3253.44 --> 3254.84] Is TreeSitter its own project? |
[3255.24 --> 3255.42] Yes. |
[3255.50 --> 3256.70] TreeSitter is its own project. |
[3256.80 --> 3261.38] It was originally made for Atom, but several other editors now have used it because it |
[3261.38 --> 3265.58] is designed to be a library to be embedded inside of other editors. |
[3265.90 --> 3270.98] And so it's very, very fast and performant and they spend a lot of time making it really |
[3270.98 --> 3271.34] awesome. |
[3271.52 --> 3272.92] And the TreeSitter team is super cool. |
[3273.22 --> 3277.70] To get it started with it, you kind of similar to LSP config, you have to, |
[3277.72 --> 3279.24] install a separate plugin. |
[3279.24 --> 3282.26] And is that just to help with the configuration then? |
[3282.36 --> 3286.36] I think that's where I like had confusion was because I was like, I thought that it was |
[3286.36 --> 3287.98] built in, but I have to install this plugin. |
[3288.24 --> 3288.34] Yeah. |
[3288.42 --> 3292.78] So to be like clear about it, you actually don't have to install plugins for either. |
[3292.78 --> 3296.28] Like you can start up the server by yourself for LSP. |
[3296.76 --> 3296.94] Yeah. |
[3296.98 --> 3298.88] It just is a little bit more boilerplate. |
[3298.98 --> 3302.26] So that's why we have LSP config, but it's like certainly possible to do. |
[3302.26 --> 3305.84] LSP config literally only has configurations. |
[3306.48 --> 3311.02] But for TreeSitter, you also don't necessarily have to install the plugin. |
[3311.34 --> 3312.52] It'll just be more complicated. |
[3312.52 --> 3318.76] Like it would involve you downloading a grammar file, running TreeSitter to generate the bindings |
[3318.76 --> 3321.30] because it's a separate executable to generate these bindings. |
[3321.46 --> 3326.76] And then creating your .so shared executable and then putting that in the right place. |
[3326.76 --> 3329.10] So you could do that. |
[3329.42 --> 3334.60] And then the engine that's built inside of NeoVim will see that shared executable, load |
[3334.60 --> 3338.54] it up and appropriately attach it, I guess, to the buffer. |
[3338.78 --> 3343.54] But that is not very fun to do. |
[3343.82 --> 3345.72] So that's where NVim TreeSitter comes in. |
[3345.90 --> 3352.08] And over time, we hope to, you know, upstream more of like NVim TreeSitter into NeoVim core. |
[3352.08 --> 3360.66] But there's a certain level of backwards compatibility and polish that we want to have in the core repository. |
[3361.10 --> 3366.02] And we felt that that would really hold back a lot of experimentation and interesting things happening. |
[3366.46 --> 3372.88] We tried to squish that all inside of NeoVim core, which is where NVim TreeSitter sort of came out as a separate plugin. |
[3372.88 --> 3381.92] So the engine, all of the interior things to do, like get the tree and have it parse incrementally as you type and all of that kind of stuff, |
[3382.04 --> 3384.20] that's inside of NeoVim all the time. |
[3385.14 --> 3394.80] Someday, someday, my goal would be we would at least ship TreeSitter grammars inside of NeoVim for C, Lua, and Vim, VimScript, |
[3394.80 --> 3399.38] because those are the languages that NeoVim deals with. |
[3399.48 --> 3404.98] And I think it would be cool to have a really awesome experience out of the box for those languages for people. |
[3405.10 --> 3406.46] But we're just kind of far away. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.