Skip to content

Auto pairing for Python triple quotes randomly fails with Treesitter #104

@AllanChain

Description

@AllanChain

When trying to type triple quotes in Python, the auto pairing fails randomly if Treesitter parser for Python is installed.

Expected:

"""|"""

Randomly (~60%) get:

"""|"

Steps to reproduce:

  1. Install lazy.nvim, ultimate-autopair.nvim, and nvim-treesitter:
Minimal init.lua
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  local lazyrepo = "https://github.com/folke/lazy.nvim.git"
  local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
  if vim.v.shell_error ~= 0 then
    vim.api.nvim_echo({
      { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
      { out, "WarningMsg" },
      { "\nPress any key to exit..." },
    }, true, {})
    vim.fn.getchar()
    os.exit(1)
  end
end
vim.opt.rtp:prepend(lazypath)

-- Make sure to setup `mapleader` and `maplocalleader` before
-- loading lazy.nvim so that mappings are correct.
-- This is also a good place to setup other settings (vim.opt)
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

-- Setup lazy.nvim
require("lazy").setup({
  spec = {
    -- import your plugins
    {
      'altermo/ultimate-autopair.nvim',
    event={'InsertEnter','CmdlineEnter'},
    branch='v0.6', --recommended as each new version will have breaking changes
    opts={
        --Config goes here
    },
    },
    {"nvim-treesitter/nvim-treesitter", lazy=false, build = ":TSUpdate"}
  },
  -- Configure any other settings here. See the documentation for more details.
  -- colorscheme that will be used when installing plugins.
  install = { colorscheme = { "habamax" } },
  -- automatically check for plugin updates
  checker = { enabled = true },
})
  1. Install Python parser with :TSInstall python
  2. Open an empty Python file and type """
Version info
NVIM v0.10.3
Build type: RelWithDebInfo
LuaJIT 2.1.1731601260
Health check
ultimate-autopair
- ERROR test(rfaswarp) { '"foo|"', "\1", '"|"foo', {ts = true} } failed, actuall result: '|""foo'
- ERROR test(rfaswarp) { '"|foo"', "\1", '"|"foo', {ts = true} } failed, actuall result: '"|foo"'
- ERROR test(rfaswarp) { '"|"', "\1", '"|"', {ts = true} } failed, actuall result: '|""'
- OK all test in category fastwarp have passed
- OK all test in category options have passed
- OK all test in category ext_cond have passed
- OK all test in category filter have passed
- OK all test in category simple have passed
- OK all test in category close have passed
- OK all test in category newline have passed
- OK all test in category backspace have passed
- OK all test in category tabout have passed
- OK all test in category ext_cmdtype have passed
- OK all test in category ext_alpha have passed
- OK all test in category multiline have passed
- OK all test in category ext_filetype have passed
- OK all test in category string have passed
- OK all test in category ext_suround have passed
- OK all test in category ext_escape have passed
- OK all test in category utf8 have passed
- OK all test in category ext_tsnode have passed
- OK all test in category ext_fly have passed
- OK all test in category space have passed
- OK all test in category space2 have passed

Additional information: Things work fine without Python parser installed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions