diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 823a99d..8b41843 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: matrix: include: - os: ubuntu-20.04 - url: https://github.com/neovim/neovim/releases/download/v0.7.0/nvim-linux64.tar.gz + url: https://github.com/neovim/neovim/releases/download/v0.9.5/nvim-linux64.tar.gz manager: sudo apt-get packages: -y fd-find steps: @@ -43,5 +43,6 @@ jobs: run: | export PATH="${PWD}/_neovim/bin:${PATH}" export VIM="${PWD}/_neovim/share/nvim/runtime" - nvim --headless -u tests/minimal.vim -c "TSInstallSync html javascript typescript svelte vue tsx php glimmer rescript" -c "q" + # nvim --headless -u tests/minimal.vim -c "q" + nvim --headless -u tests/minimal.vim -c "PlenaryBustedDirectory tests/ {minimal_init = 'tests/minimal.vim', sequential = true}" make test diff --git a/lua/nvim-ts-autotag.lua b/lua/nvim-ts-autotag.lua index 572fff6..8e5073a 100644 --- a/lua/nvim-ts-autotag.lua +++ b/lua/nvim-ts-autotag.lua @@ -3,14 +3,17 @@ local internal = require("nvim-ts-autotag.internal") local M = {} function M.init() - require "nvim-treesitter".define_modules { - autotag = { - module_path = 'nvim-ts-autotag.internal', - is_supported = function(lang) - return internal.is_supported(lang) - end - } - } + local ts = require('nvim-treesitter') + if ts and ts.define_modules then + require('nvim-treesitter').define_modules({ + autotag = { + module_path = 'nvim-ts-autotag.internal', + is_supported = function(lang) + return internal.is_supported(lang) + end, + }, + }) + end end function M.setup(opts) diff --git a/lua/nvim-ts-autotag/internal.lua b/lua/nvim-ts-autotag/internal.lua index 89bea74..3d42008 100644 --- a/lua/nvim-ts-autotag/internal.lua +++ b/lua/nvim-ts-autotag/internal.lua @@ -1,6 +1,3 @@ -local _, ts_utils = pcall(require, "nvim-treesitter.ts_utils") -local configs = require("nvim-treesitter.configs") -local parsers = require("nvim-treesitter.parsers") local log = require("nvim-ts-autotag._log") local utils = require("nvim-ts-autotag.utils") @@ -160,7 +157,7 @@ local setup_ts_tag = function() end local function is_in_template_tag() - local cursor_node = ts_utils.get_node_at_cursor() + local cursor_node = vim.treesitter.get_node() if not cursor_node then return false end @@ -248,7 +245,7 @@ local function get_tag_name(node) end local function find_tag_node(opt) - local target = opt.target or ts_utils.get_node_at_cursor() + local target = opt.target or vim.treesitter.get_node() local tag_pattern = opt.tag_pattern local name_tag_pattern = opt.name_tag_pattern local skip_tag_pattern = opt.skip_tag_pattern @@ -324,7 +321,7 @@ local function check_close_tag(close_slash_tag) if close_slash_tag then -- Find start node from non closed tag - local current = ts_utils.get_node_at_cursor() + local current = vim.treesitter.get_node() -- log.debug(current) target = find_start_tag(current) -- log.debug(target) @@ -367,7 +364,7 @@ local function check_close_tag(close_slash_tag) end M.close_tag = function() - local buf_parser = parsers.get_parser() + local buf_parser = vim.treesitter.get_parser() if not buf_parser then return end @@ -380,7 +377,7 @@ M.close_tag = function() end M.close_slash_tag = function() - local buf_parser = parsers.get_parser() + local buf_parser = vim.treesitter.get_parser() if not buf_parser then return end @@ -553,17 +550,25 @@ local is_before_word = is_before('%w', 1) local is_before_arrow = is_before('<', 0) M.rename_tag = function() - if is_before_word() and parsers.has_parser() then - parsers.get_parser():parse() - rename_start_tag() - rename_end_tag() + if is_before_word() then + local ok, parser = pcall(vim.treesitter.get_parser) + if ok then + parser:parse() + rename_start_tag() + rename_end_tag() + end end end M.attach = function(bufnr, lang) M.lang = lang - local config = configs.get_module("autotag") - M.setup(config) + local ok, configs = pcall(require, "nvim-treesitter.configs") + if ok then + local config = configs.get_module("autotag") + M.setup(config) + else + M.setup() + end if is_in_table(M.tbl_filetypes, vim.bo.filetype) then setup_ts_tag() diff --git a/lua/nvim-ts-autotag/utils.lua b/lua/nvim-ts-autotag/utils.lua index fd66137..d0822e6 100644 --- a/lua/nvim-ts-autotag/utils.lua +++ b/lua/nvim-ts-autotag/utils.lua @@ -1,6 +1,5 @@ -local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils') local log = require('nvim-ts-autotag._log') -local get_node_text = vim.treesitter.get_node_text or vim.treesitter.query.get_node_text or ts_utils.get_node_text +local get_node_text = vim.treesitter.get_node_text or vim.treesitter.query.get_node_text local M = {} M.get_node_text = function(node) diff --git a/tests/minimal.vim b/tests/minimal.vim index 950b620..4df2148 100644 --- a/tests/minimal.vim +++ b/tests/minimal.vim @@ -29,6 +29,13 @@ _G.__is_log=true _G.ts_filetypes = { 'html', 'javascript', 'typescript', 'svelte', 'vue', 'tsx', 'php', 'glimmer', 'rescript', 'embedded_template' } +require("nvim-treesitter.configs").setup({ + ensure_installed = _G.ts_filetypes, + highlight = { enable = true }, + sync_install = true +}) +vim.treesitter.language.register('tsx', 'typescriptreact') +vim.treesitter.language.register('embedded_template', 'eruby') require("plenary/busted") vim.cmd[[luafile ./tests/test-utils.lua]] require("nvim-ts-autotag").setup({