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