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

Treesitter conditions not working with comments #439

Open
SGauvin opened this issue Mar 8, 2024 · 1 comment
Open

Treesitter conditions not working with comments #439

SGauvin opened this issue Mar 8, 2024 · 1 comment
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@SGauvin
Copy link

SGauvin commented Mar 8, 2024

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:
image

When entering "%" at the end of the comment, it doesn't get a matching one (but it should)
Screenshot from 2024-03-08 15-59-02

When entering "%" inside the string, it gets a matching one like expected.
Screenshot from 2024-03-08 15-59-49

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,
  },
})
@SGauvin SGauvin added the bug Something isn't working label Mar 8, 2024
Copy link

stale bot commented May 9, 2024

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.

@stale stale bot added the wontfix This will not be worked on label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant