diff --git a/README.md b/README.md index 1bf3dbb..acb4155 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,6 @@ with the result. ```lua { 'ckolkey/ts-node-action', - dependencies = { 'nvim-treesitter' }, opts = {}, }, ``` @@ -49,7 +48,6 @@ with the result. ```lua use({ 'ckolkey/ts-node-action', - requires = { 'nvim-treesitter' }, config = function() require("ts-node-action").setup({}) end diff --git a/doc/ts-node-action.txt b/doc/ts-node-action.txt index 7e39bff..5f62ee7 100644 --- a/doc/ts-node-action.txt +++ b/doc/ts-node-action.txt @@ -43,7 +43,6 @@ INSTALLATION *ts-node-action-ts-node-action-installation* >lua { 'ckolkey/ts-node-action', - dependencies = { 'nvim-treesitter' }, opts = {}, }, < @@ -53,7 +52,6 @@ INSTALLATION *ts-node-action-ts-node-action-installation* >lua use({ 'ckolkey/ts-node-action', - requires = { 'nvim-treesitter' }, config = function() require("ts-node-action").setup({}) end diff --git a/lua/ts-node-action/init.lua b/lua/ts-node-action/init.lua index f4b8d5c..8804f66 100644 --- a/lua/ts-node-action/init.lua +++ b/lua/ts-node-action/init.lua @@ -1,5 +1,7 @@ local M = {} +local ts = vim.treesitter + --- @private --- @param targets TSNode[] --- @return integer start_row @@ -124,14 +126,18 @@ end --- @return TSNode, string --- @return nil function M._get_node() - local root_langtree = require("nvim-treesitter.parsers").get_parser() - if not root_langtree then + -- stylua: ignore + local parser = (vim.fn.has("nvim-0.12") == 1 and ts.get_parser()) + or (vim.fn.has("nvim-0.11") == 1 and ts.get_parser(nil, nil, { error = false })) + or (pcall(ts.get_parser, nil, nil)) + + if not parser then return end local lnum, col = unpack(vim.api.nvim_win_get_cursor(0)) local range4 = { lnum - 1, col, lnum - 1, col } - local langtree = root_langtree:language_for_range(range4) + local langtree = parser:language_for_range(range4) local node = langtree:named_node_for_range(range4) return node, langtree:lang() end