From 6ee7a9ad94ed4e4a8fa15317efd91225c1c0d298 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 8 Nov 2024 23:47:04 +0300 Subject: [PATCH] neovim: add sql language injection in the javascript --- flake.lock | 8 ++++---- neovim/dev.nix | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/flake.lock b/flake.lock index 7943704..93bb7c2 100644 --- a/flake.lock +++ b/flake.lock @@ -299,11 +299,11 @@ ] }, "locked": { - "lastModified": 1723290966, - "narHash": "sha256-HlSsIOCqmSa4pYMoBlFMfyWuw0rpgGfJdcLHaey+WoM=", + "lastModified": 1731097096, + "narHash": "sha256-hMBcuTUJs1+zQ5nwTA06isLxk/vUd1r5qs95JRJ5L5E=", "ref": "refs/heads/main", - "rev": "328ed672995614acb3d42752f20ba41b7f6e77b3", - "revCount": 93, + "rev": "20bf0c7e51e1e5ebf5f3754332f134a8ca0ce04c", + "revCount": 94, "type": "git", "url": "https://git.pleshevski.ru/pleshevskiy/nixeovim" }, diff --git a/neovim/dev.nix b/neovim/dev.nix index 8454031..e648a8f 100644 --- a/neovim/dev.nix +++ b/neovim/dev.nix @@ -3,7 +3,6 @@ let inherit (lib.mod) ctrl; inherit (lib.nix2lua) pipe1 require call0 nf var; - in { imports = [ @@ -35,18 +34,37 @@ in # Enable fast navigation between windows vim.keymap.set = map (k: { mode = "n"; lhs = ctrl k; rhs = "${ctrl "w"}${k}"; }) [ "h" "l" "j" "k" ]; - plugins.style.nvim-treesitter.extraGrammars = { - tree-sitter-d2 = rec { - language = "d2"; - version = "1e6d8ca3d85c0031ff010759bb60804dd47b95f2"; - src = pkgs.fetchFromGitea { - domain = "git.pleshevski.ru"; - owner = "pleshevskiy"; - repo = "tree-sitter-d2"; - rev = version; - sha256 = "sha256-ld9zlJ7tXl/SyrHJXwPKviDHePbw/jhI9WPT3aNntt8="; + plugins.style.nvim-treesitter = { + extraGrammars = { + tree-sitter-d2 = rec { + language = "d2"; + version = "1e6d8ca3d85c0031ff010759bb60804dd47b95f2"; + src = pkgs.fetchFromGitea { + domain = "git.pleshevski.ru"; + owner = "pleshevskiy"; + repo = "tree-sitter-d2"; + rev = version; + sha256 = "sha256-ld9zlJ7tXl/SyrHJXwPKviDHePbw/jhI9WPT3aNntt8="; + }; }; }; + + # Source: https://github.com/DariusCorvus/tree-sitter-language-injection.nvim/blob/main/lua/tree-sitter-language-injection/init.lua + extraQueries.javascript.injections = + let + lang = "sql"; + langMatch = ''^//+( )*${lang}( )*|^/[*]+( )*${lang}( )*[*]+/$''; + in + '' + ((comment) @comment . + ([ (string(string_fragment) @injection.content) + (template_string(string_fragment) @injection.content) + ] @injection.content + ) + (#match? @comment "${langMatch}") + (#set! injection.language "${lang}") + ) + ''; }; plugins.style.neoformat.autoformat = {