Treesitter conditions not working with comments
SGauvin opened this issue · comments
Simon Gauvin commented
Description
I'm trying to have a setup where single quotes don't get auto-paired when writing a comment.
I took the example in the README, but even this doesn't seem to work for comments.
Mapping bug
No response
Steps to reproduce
See that the comment
node is properly detected by treesitter:
When entering "%" at the end of the comment, it doesn't get a matching one (but it should)
When entering "%" inside the string, it gets a matching one like expected.
For some reason the "comment" node doesn't seem to be working
Minimal config
-- config using lazy
-- [[ Install `lazy.nvim` plugin manager ]]
-- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
end ---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function()
---@diagnostic disable-next-line: missing-fields
require("nvim-treesitter.configs").setup({
ensure_installed = {"lua"},
auto_install = true,
highlight = { enable = true },
indent = { enable = true },
})
end,
},
{
"windwp/nvim-autopairs",
event = "InsertEnter",
config = function()
local npairs = require("nvim-autopairs")
local Rule = require("nvim-autopairs.rule")
npairs.setup({
check_ts = true,
})
local ts_conds = require("nvim-autopairs.ts-conds")
require("nvim-autopairs").get_rules("'")[1]:with_pair(ts_conds.is_not_ts_node({ "comment" }))
-- press % => %% only while inside a comment or string
npairs.add_rules({
Rule("%", "%", "lua"):with_pair(ts_conds.is_ts_node({ "string", "comment" })),
Rule("$", "$", "lua"):with_pair(ts_conds.is_not_ts_node({ "function" })),
})
end,
},
})
stale commented
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.