I use #sqlx, and I wanted syntax highlighting for embedded #SQL queries in my #Rust code. Making that work in #Neovim led me to learning a few things about #Treesitter, and #NixOS packaging conventions. Here's my write-up!
Public replies to this post will appear in a comments section under the blog post.
https://sitr.us/2026/05/03/embedded-sql-highlighting-in-neovim/
Embedded SQL highlighting in Neovim, a look into Treesitter, and some NixOS patching
This is the story of the rabbit hole I went down because I wanted pretty syntax highlighting for embedded SQL queries in my Rust code. I’m a fan of sqlx, which provides macros for writing inline SQL with real-time type checking. Because the queries are in Rust strings the whole query is highlighted uniform green by default. That’s not acceptable! By the end of my journey I had highlighting looking like this: In most cases this kind of embedded syntax highlighting is easy in Neovim, and it’s often set up by default if you use the nvim-treesitter plugin. But I ran into some issues in this particular case. That led me to learn some things about Treesitter, and about how nixpkgs packages Neovim plugins, and Treesitter packages. If you care to follow along, you’ll hear a tale of Neovim, Treesitter, injection queries, patching, NixOS, and more patching!…


