diff --git a/.gitignore b/.gitignore index a7b6a7d..e3df9c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Tag file created by Vim doc/tags -test/xdg/config/nvim/ + +# Fake user directory structures test/xdg/local/share/nvim/ test/xdg/local/state/nvim/ !test/xdg/local/share/nvim/site/pack/testing/start/rainbow-delimiters diff --git a/test/e2e/config.lua b/test/e2e/config.lua index 1787dd6..2849514 100644 --- a/test/e2e/config.lua +++ b/test/e2e/config.lua @@ -71,7 +71,7 @@ describe('User settings are respected', function() end) it('Uses the strategy returned by the thunk', function() - request('nvim_command', 'TSInstallSync! lua') + request(exec_lua, 'TSEnsure(...)', {'lua'}) request(buf_set_lines, 0, 0, -1, true, {'print "Hello world"', '-- vim:ft=lua'}) request('nvim_command', 'filetype detect') local attachments = request(exec_lua, 'return the_strategy.attachments[1]', {}) @@ -79,7 +79,7 @@ describe('User settings are respected', function() end) it('Does nothing if the thunk returns nil', function() - request('nvim_command', 'TSInstallSync! vim') + request(exec_lua, 'TSEnsure(...)', {'vim'}) request(buf_set_lines, 0, 0, -1, true, {'echo "Hello world"', '" vim:ft=vim'}) request('nvim_command', 'filetype detect') local attachments = request(exec_lua, 'return the_strategy.attachments[1]', {}) diff --git a/test/xdg/config/nvim/plugin/ts-ensure.lua b/test/xdg/config/nvim/plugin/ts-ensure.lua new file mode 100644 index 0000000..8bd783e --- /dev/null +++ b/test/xdg/config/nvim/plugin/ts-ensure.lua @@ -0,0 +1,14 @@ +local get_runtime_file = vim.api.nvim_get_runtime_file +local parser_pattern = 'parser/%s.*' + +---Wrapper around the `:TSinstall` command which will only install a parser if +---it is not installed yet +---@param lang string Language to install +function TSEnsure(lang, ...) + for _, l in ipairs({lang, ...}) do + local parsers = get_runtime_file(parser_pattern:format(l), true) + if #parsers == 0 then + vim.cmd {cmd = 'TSInstallSync', args = {l}} + end + end +end