From 434dc5c6c40072321051f2abbe426672af7fb93d Mon Sep 17 00:00:00 2001 From: arne314 <73391160+arne314@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:44:16 +0100 Subject: [PATCH] feat(snip): warning if jsregexp is not installed --- README.md | 2 +- lua/typstar/autosnippets.lua | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1243274..cee2061 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ require('typstar').setup({ ### Snippets 1. Install [LuaSnip](https://github.com/L3MON4D3/LuaSnip/), set `enable_autosnippets = true` and set a visual mode selection key (e.g. `store_selection_keys = ''`) in the configuration -2. Install [jsregexp](https://github.com/kmarius/jsregexp) as described [here](https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#transformations) (running `:lua require('jsregexp')` in nvim should not result in an error) +2. Install [jsregexp](https://github.com/kmarius/jsregexp) as described [here](https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#transformations) (You will see a warning on startup if jsregexp isn't installed properly) 3. Install [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) and run `:TSInstall typst` 4. Optional: Setup [ctheorems](https://typst.app/universe/package/ctheorems/) with names like [here](./lua/typstar/snippets/markup.lua) diff --git a/lua/typstar/autosnippets.lua b/lua/typstar/autosnippets.lua index 44ca4e2..9fe5c8b 100644 --- a/lua/typstar/autosnippets.lua +++ b/lua/typstar/autosnippets.lua @@ -105,6 +105,13 @@ function M.setup() ) end luasnip.add_snippets('typst', autosnippets) + local jsregexp_ok, _ = pcall(require, "luasnip-jsregexp") + if not jsregexp_ok then + jsregexp_ok, _ = pcall(require, "jsregexp") + end + if not jsregexp_ok then + vim.notify("WARNING: Most snippets won't work as jsregexp is not installed", vim.log.levels.WARN) + end end end