Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove nvim-treesitter dependency #437

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -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/latest/download/nvim-linux64.tar.gz
manager: sudo apt-get
packages: -y fd-find
steps:
Expand All @@ -32,7 +32,7 @@ jobs:
}
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
git clone --depth 1 --branch v0.7.2 https://github.com/nvim-treesitter/nvim-treesitter ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter
git clone --depth 1 https://github.com/nvim-treesitter/nvim-treesitter ~/.local/share/nvim/site/pack/vendor/start/nvim-treesitter
git clone --depth 1 https://github.com/nvim-treesitter/playground ~/.local/share/nvim/site/pack/vendor/start/playground
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
- name: Run tests
Expand Down
25 changes: 12 additions & 13 deletions lua/nvim-autopairs/ts-conds.lua
@@ -1,7 +1,4 @@
local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')

local log = require('nvim-autopairs._log')
local parsers = require'nvim-treesitter.parsers'
local utils = require('nvim-autopairs.utils')
local ts_get_node_text = vim.treesitter.get_node_text or vim.treesitter.query.get_node_text

Expand All @@ -17,8 +14,8 @@ conds.is_endwise_node = function(nodes)
if nodes == nil then return true end
if #nodes == 0 then return true end

parsers.get_parser():parse()
local target = ts_utils.get_node_at_cursor()
vim.treesitter.get_parser():parse()
local target = vim.treesitter.get_node({ ignore_injections = false })
if target ~= nil and utils.is_in_table(nodes, target:type()) then
local text = ts_get_node_text(target) or {""}
local last = text[#text]:match(opts.rule.end_pair)
Expand Down Expand Up @@ -59,7 +56,9 @@ conds.is_in_range = function(callback, position)
)
return function(opts)
log.debug('is_in_range')
if not parsers.has_parser() then
-- `parser` will be a table (on success) or a string (error message)
local _, parser = pcall(vim.treesitter.get_parser)
if not type(parser) == 'string' then
return
end
local cursor = position()
Expand All @@ -71,7 +70,7 @@ conds.is_in_range = function(callback, position)
local col = cursor[2]

local bufnr = 0
local root_lang_tree = parsers.get_parser(bufnr)
local root_lang_tree = vim.treesitter.get_parser(bufnr)
local lang_tree = root_lang_tree:language_for_range({ line, col, line, col })

local result
Expand Down Expand Up @@ -110,8 +109,8 @@ conds.is_ts_node = function(nodes)
log.debug('is_ts_node')
if #nodes == 0 then return end

parsers.get_parser():parse()
local target = ts_utils.get_node_at_cursor()
vim.treesitter.get_parser():parse()
local target = vim.treesitter.get_node({ ignore_injections = false })
if target ~= nil and utils.is_in_table(nodes, target:type()) then
return true
end
Expand All @@ -126,8 +125,8 @@ conds.is_not_ts_node = function(nodes)
log.debug('is_not_ts_node')
if #nodes == 0 then return end

parsers.get_parser():parse()
local target = ts_utils.get_node_at_cursor()
vim.treesitter.get_parser():parse()
local target = vim.treesitter.get_node({ ignore_injections = false })
if target ~= nil and utils.is_in_table(nodes, target:type()) then
return false
end
Expand All @@ -139,8 +138,8 @@ conds.is_not_ts_node_comment = function()
log.debug('not_in_ts_node_comment')
if not opts.ts_node then return end

parsers.get_parser():parse()
local target = ts_utils.get_node_at_cursor()
vim.treesitter.get_parser():parse()
local target = vim.treesitter.get_node({ ignore_injections = false })
if target ~= nil and utils.is_in_table(opts.ts_node, target:type()) then
return false
end
Expand Down
3 changes: 0 additions & 3 deletions tests/afterquote_spec.lua
Expand Up @@ -94,9 +94,6 @@ local data = {

local run_data = _G.Test_filter(data)

local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
_G.TU = ts_utils

describe('[afterquote tag]', function()
_G.Test_withfile(run_data, {})
end)
3 changes: 0 additions & 3 deletions tests/endwise_spec.lua
Expand Up @@ -70,9 +70,6 @@ local data = {

local run_data = _G.Test_filter(data)

local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
_G.TU = ts_utils

describe('[endwise tag]', function()
_G.Test_withfile(run_data, {
-- need to understand this ??? new line make change cursor zzz
Expand Down
3 changes: 0 additions & 3 deletions tests/fastwrap_spec.lua
Expand Up @@ -48,9 +48,6 @@

-- local run_data = _G.Test_filter(data)

-- local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
-- _G.TU = ts_utils

-- describe('[endwise tag]', function()
-- _G.Test_withfile(run_data, {})
-- end)
16 changes: 0 additions & 16 deletions tests/treesitter_spec.lua
Expand Up @@ -33,19 +33,6 @@ local data = {
after = [[ [[ aaa"| ]],
},

{
name = 'treesitter javascript quote',
filepath = './tests/endwise/javascript.js',
filetype = 'javascript',
linenr = 5,
key = [[(]],
before = {
[[ const data= `aaa | ]],
[[ ]],
'`',
},
after = [[ const data= `aaa (| ]],
},
{
setup_func = function()
npairs.add_rules({
Expand Down Expand Up @@ -127,9 +114,6 @@ local data = {

local run_data = _G.Test_filter(data)

local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
_G.TU = ts_utils

describe('[treesitter check]', function()
_G.Test_withfile(run_data, {
before_each = function(value)
Expand Down