-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend functionality to any buffer with injected language blocks? #3
Comments
Hi @bew! I think this would be great indeed. What I don't know is how uniform the structure for injected languages are. For example at the moment we make use of eg the following structure:
to both find what the injected language is and where the content lives in the buffer. Maybe there are other ways to retrieve this without querying the tree directly. If so, I'd be interested in knowing this :) |
With a quick look at the documentation around treesitter, I've found the functions around LanguageTrees: I didn't test anything, but it looks like you might not even need to navigate the parsed tree yourself, matching individual nodes, but instead you should be able to access directly the current injected language, where it starts/ends, etc... Edit: Looking a bit more at neovim's & nvim-treesitter's source code, the parser you get from |
This looks great and might indeed be a better way and more powerful. Thanks for sharing! I'll try to take a look at this 👍 |
@bew I started trying this out in #4, feel free to try it if it works for you. It does seem to work pretty well I think. One small issue is that if you for example have an empty codeblock in markdown, eg:
then there is in fact no injected language tree there and you can't selected. Also for a similar reason you currently only be able to open the window when you're on the start (back-ticks) of the code-block but not the last line with back-ticks. |
Hmm that's too bad.. As far for trying, you'll have to wait a bit, as I'm in the process of migrating my conf to Lua, with all the new things like treesitter. |
HI @AckslD , what do you think about the option of letting the user to use their own Treesittter queries? |
That might be the way to go indeed @ziontee113, ideally this would work automatically for any language injection but doesn't seem feasible since "empty" languages are not injected (which I guess makes sense). Do you have some language with a query in mind that I could try out as an example? |
You can take a look at this screenshot We're in a (
("string_content") @query
(#match? @query ";; query")
) Only strings that has the |
Thanks! Actually, this got me thinking, maybe we can also just extend eg the current markdown query to also match empty code-blocks. So I tried changing current injections.scm for markdown to something like:
This seems to indeed work. So I updated #4 to instead find matches of language injections queries. Feel free to try it if it works for you.
Note that Edit: turns out I just forgot |
One more thing I just realised is that is currently only works for injections with matches Edit: fixed by #6 |
#8 now enables also inline injections for example see the following example where lua is temporarily injected into python strings: femaco_inline_injections.mp4 |
This is awesome. |
Will just need to wait for nvim-treesitter/nvim-treesitter#3486 :) |
Hello!
This plugin looks nice & simple 👍
Have you considered making it work in all files (not just markdown), to support any language block injected in a base language using treesitter ?
The text was updated successfully, but these errors were encountered: