LunarVim / Neovim-from-scratch

📚 A Neovim config designed from scratch to be understandable
https://www.chrisatmachine.com/
GNU General Public License v3.0
5.43k stars 1.17k forks source link

syntax highlighting and snippet completion for injected languages #64

Open tvdab opened 2 years ago

tvdab commented 2 years ago

I found it difficult to make syntax highlighting and snippet completion work for pieces of code that are written in a different language than the language of the file they are embedded in. I found a hacky solution to cover my situation, but I would like to see a better and more easy way to achieve this.

By default a snippet of html-code inside a javascript file looks like this: image

So by default there is no syntax highlighting nor html-snippets available in this case.

These are the steps needed to make syntax highlighting and html-snippets work for this case:

I added this query inside ~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/ecma/injections.scm which probably isn't the best idea. This will probably be deleted when doing a packer clean update?

Now syntax highlighting is working:

image

But still no html-snippet expansion...

image

Now syntax highlighting and html-snippets are working: image

All sugestions to improve on this are welcome!

max397574 commented 2 years ago

open an issue or pr for nvim-treesitter with this injection query

tvdab commented 2 years ago

open an issue or pr for nvim-treesitter with this injection query

I would prefer to see a more general solution where injected languages get detected automatically. Not sure how that should/could work though.