Remove usage of nvim-treesitter utilities (#152)

`vim.treesitter` is now shipped, therefore nvim-treesitter plugin is not needed anymore as a requirement.
References to nvim-treesitter was deleted in the code and the README points to `:h treesitter-parsers`

---------

Co-authored-by: danymat <d.danymat@gmail.com>
This commit is contained in:
Amaan Qureshi
2024-03-03 15:42:36 -05:00
committed by GitHub
parent 70127baaff
commit a9641d131c
10 changed files with 30 additions and 33 deletions

View File

@@ -32,7 +32,7 @@
## Requirements ## Requirements
- Install [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) Have Tree-sitter parsers installed on your system. For more information, check out the [:treesitter-parsers](https://neovim.io/doc/user/treesitter.html#treesitter-parsers) neovim help page.
## Installation ## Installation
@@ -43,7 +43,6 @@ Use your favorite package manager to install Neogen, e.g:
```lua ```lua
{ {
"danymat/neogen", "danymat/neogen",
dependencies = "nvim-treesitter/nvim-treesitter",
config = true, config = true,
-- Uncomment next line if you want to follow only stable versions -- Uncomment next line if you want to follow only stable versions
-- version = "*" -- version = "*"
@@ -58,7 +57,6 @@ use {
config = function() config = function()
require('neogen').setup {} require('neogen').setup {}
end, end,
requires = "nvim-treesitter/nvim-treesitter",
-- Uncomment next line if you want to follow only stable versions -- Uncomment next line if you want to follow only stable versions
-- tag = "*" -- tag = "*"
} }

View File

@@ -1,13 +1,6 @@
local helpers = require("neogen.utilities.helpers") local helpers = require("neogen.utilities.helpers")
local notify = helpers.notify local notify = helpers.notify
local ok, ts_utils = pcall(require, "nvim-treesitter.ts_utils")
if not ok then
notify("neogen requires nvim-treesitter to operate :(", vim.log.levels.ERROR)
return function(_, _) end
end
local ts_parsers = require("nvim-treesitter.parsers")
local conf = require("neogen.config").get() local conf = require("neogen.config").get()
local granulator = require("neogen.granulator") local granulator = require("neogen.granulator")
@@ -65,11 +58,11 @@ end
-- Get nearest parent node -- Get nearest parent node
local function get_parent_node(filetype, node_type, language) local function get_parent_node(filetype, node_type, language)
local parser_name = ts_parsers.ft_to_lang(filetype) local parser_name = vim.treesitter.language.get_lang(filetype)
local parser = vim.treesitter.get_parser(0, parser_name) local parser = vim.treesitter.get_parser(0, parser_name)
local tstree = parser:parse()[1] local tstree = parser:parse()[1]
local tree = tstree:root() local tree = tstree:root()
local current_node = ts_utils.get_node_at_cursor(0) local current_node = vim.treesitter.get_node()
local match_any = node_type == ANY_TYPE local match_any = node_type == ANY_TYPE
local target_node, target_type local target_node, target_type
local locator = language.locator or default_locator local locator = language.locator or default_locator

View File

@@ -1,7 +1,7 @@
local helpers = require("neogen.utilities.helpers") local helpers = require("neogen.utilities.helpers")
--- Tries to use the configuration to find all required content nodes from the parent node --- Tries to use the configuration to find all required content nodes from the parent node
---@param parent_node userdata the node found by the locator ---@param parent_node TSNode the node found by the locator
---@param node_data table the data from configurations[lang].data ---@param node_data table the data from configurations[lang].data
return function(parent_node, node_data) return function(parent_node, node_data)
local result = {} local result = {}

View File

@@ -299,7 +299,7 @@ end
--- with multiple annotation conventions. --- with multiple annotation conventions.
---@tag neogen-changelog ---@tag neogen-changelog
---@toc_entry Changes in neogen plugin ---@toc_entry Changes in neogen plugin
neogen.version = "2.15.2" neogen.version = "2.15.3"
--minidoc_afterlines_end --minidoc_afterlines_end
return neogen return neogen

View File

@@ -1,12 +1,12 @@
---@class Neogen.node_info ---@class Neogen.node_info
---@field current userdata the current node from cursor ---@field current TSNode the current node from cursor
---@field root? userdata the root node ---@field root? TSNode the root node
--- The default locator tries to find one of the nodes to match in the current node --- The default locator tries to find one of the nodes to match in the current node
--- If it does not find one, will fetch the parents until he finds one --- If it does not find one, will fetch the parents until he finds one
---@param node_info Neogen.node_info a node informations ---@param node_info Neogen.node_info a node informations
---@param nodes_to_match table a list of parent nodes to match ---@param nodes_to_match TSNode[] a list of parent nodes to match
---@return userdata node one of the nodes to match directly above the given node ---@return TSNode? node one of the nodes to match directly above the given node
return function(node_info, nodes_to_match) return function(node_info, nodes_to_match)
if not node_info.current then if not node_info.current then
if vim.tbl_contains(nodes_to_match, node_info.root:type()) then if vim.tbl_contains(nodes_to_match, node_info.root:type()) then

View File

@@ -1,4 +1,3 @@
local ts_utils = require("nvim-treesitter.ts_utils")
local default_locator = require("neogen.locators.default") local default_locator = require("neogen.locators.default")
return function(node_info, nodes_to_match) return function(node_info, nodes_to_match)
@@ -6,7 +5,7 @@ return function(node_info, nodes_to_match)
if node_info.current and node_info.current:type() == "source" then if node_info.current and node_info.current:type() == "source" then
local start_row, _, _, _ = vim.treesitter.get_node_range(node_info.current) local start_row, _, _, _ = vim.treesitter.get_node_range(node_info.current)
vim.api.nvim_win_set_cursor(0, { start_row + 1, 0 }) vim.api.nvim_win_set_cursor(0, { start_row + 1, 0 })
node_info.current = ts_utils.get_node_at_cursor() node_info.current = vim.treesitter.get_node()
end end
local found_node = default_locator(node_info, nodes_to_match) local found_node = default_locator(node_info, nodes_to_match)

View File

@@ -1,5 +1,8 @@
local default_locator = require("neogen.locators.default") local default_locator = require("neogen.locators.default")
---@param node_info Neogen.node_info
---@param nodes_to_match TSNode[]
---@return TSNode?
return function(node_info, nodes_to_match) return function(node_info, nodes_to_match)
local found_node = default_locator(node_info, nodes_to_match) local found_node = default_locator(node_info, nodes_to_match)

View File

@@ -20,13 +20,17 @@ return {
return vim.tbl_keys(language.parent) return vim.tbl_keys(language.parent)
end, end,
---@param s string
---@param sep string
---@param plain boolean
---@return string[]
split = function(s, sep, plain) split = function(s, sep, plain)
return vim.fn.has("nvim-0.6") == 1 and vim.split(s, sep, { plain = plain }) or vim.split(s, sep, plain) return vim.fn.has("nvim-0.6") == 1 and vim.split(s, sep, { plain = plain }) or vim.split(s, sep, plain)
end, end,
--- Gets the text from the node --- Gets the text from the node
---@private ---@private
---@param node userdata node to fetch text from ---@param node TSNode node to fetch text from
---@param bufnr? number originated buffer number. Defaults to 0 ---@param bufnr? number originated buffer number. Defaults to 0
---@return table newline separated list of text ---@return table newline separated list of text
get_node_text = function(node, bufnr) get_node_text = function(node, bufnr)

View File

@@ -2,7 +2,7 @@ local helpers = require("neogen.utilities.helpers")
return { return {
--- Get a list of child nodes that match the provided node name --- Get a list of child nodes that match the provided node name
--- @param _ any --- @param _ any
--- @param parent userdata the parent's node --- @param parent TSNode the parent's node
--- @param node_type? string the node type to search for (if multiple childrens, separate each one with "|") --- @param node_type? string the node type to search for (if multiple childrens, separate each one with "|")
--- @return table a table of nodes that matched the name --- @return table a table of nodes that matched the name
matching_child_nodes = function(_, parent, node_type) matching_child_nodes = function(_, parent, node_type)
@@ -27,7 +27,7 @@ return {
end, end,
--- Find all nested childs from `parent` that match `node_name`. Returns a table of found nodes --- Find all nested childs from `parent` that match `node_name`. Returns a table of found nodes
--- @param parent userdata --- @param parent TSNode
--- @param node_name string --- @param node_name string
--- @param opts table --- @param opts table
--- - opts.first (bool): if true, breaks at the first recursive item --- - opts.first (bool): if true, breaks at the first recursive item
@@ -53,7 +53,7 @@ return {
end, end,
--- Get all required nodes from tree --- Get all required nodes from tree
--- @param parent userdata the parent node --- @param parent TSNode the parent node
--- @param tree table a nested table : { retrieve = "all|first", node_type = node_name, subtree = tree, recursive = true } --- @param tree table a nested table : { retrieve = "all|first", node_type = node_name, subtree = tree, recursive = true }
--- If you want to extract the node, do not specify the subtree and instead: extract = true --- If you want to extract the node, do not specify the subtree and instead: extract = true
--- Optional: you can specify position = number instead of retrieve, and it will fetch the child node at position number --- Optional: you can specify position = number instead of retrieve, and it will fetch the child node at position number