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

Endwise does not work for bash/vim with nvim-ts-rainbow and nvim-treesitter-context enabled #14

Open
nkakouros opened this issue Mar 9, 2022 · 7 comments

Comments

@nkakouros
Copy link

nkakouros commented Mar 9, 2022

Describe the bug
When I have nvim-treesitter-endwise, nvim-treesitter-context and nvim-ts-rainbow enabled, then endwise does not work for the filetypes sh and vim. It works for ruby and lua.

I have traced down the behavior to this init.lua:

-- Vim Plug Installation {{{
local packer_path = os.getenv('HOME') .. '/.local/share/nvim/site/pack/packer/start/packer.nvim/'
local f = io.open(packer_path .. "lua/packer.lua", "r")
if f == nil then
  local result = os.execute("git clone --depth 1 https://github.com/wbthomason/packer.nvim " ..
    "~/.local/share/nvim/site/pack/packer/start/packer.nvim")
end
function run_packer()
   require("packer").sync()
end

vim.api.nvim_create_augroup("PackerAutoInstall", {clear=true})
vim.api.nvim_create_autocmd("VimEnter", {group="PackerAutoInstall", callback=run_packer})
-- }}}

plugins = {
  {url='https://github.com/wbthomason/packer.nvim', enable=true},
  {
    description = 'Nvim Treesitter configurations and abstraction layer',
    url = 'https://github.com/nvim-treesitter/nvim-treesitter',
    enabled = true,
    on_update = ":TSUpdate",
    config = function() require('nvim-treesitter.configs').setup ({
      ensure_installed = {"bash", "bibtex", "c", "comment", "cpp", "css", "commonlisp", "dockerfile",
        "html", "http", "java", "javascript", "json", "latex", "lua", "make", "markdown",
        "php", "phpdoc", "python", "r", "regex", "rst", "scss", "toml", "vim", "yaml"},

      rainbow = {
        enable = true,
        extended_mode = true, -- Also highlight non-bracket delimiters like html tags
      },

      endwise = {
        enable = true,
      },

    }) end,
  },
  {
    description = 'Rainbow parentheses for neovim using tree-sitter',
    url = 'https://github.com/romgrk/nvim-treesitter-context',
    enabled = true,
    config = function() require'treesitter-context'.setup({
      patterns = {
        default = {
          'class',
          'function',
          'method',
          'for',
          'while',
          'if',
          'switch',
          'case',
        },
      },
    }) end
  },
  {
    description = 'Rainbow parentheses for neovim using tree-sitter',
    url = 'https://github.com/p00f/nvim-ts-rainbow',
    enabled = true,
  },
  {
    description = 'Wisely add "end" in Ruby, Vimscript, Lua, etc. Tree-sitter aware',
    url = 'https://github.com/RRethy/nvim-treesitter-endwise',
    enabled = true,
  },
  -- }}}
}

function install_plugins(plugins)
  for i, plugin in ipairs(plugins) do
    require("packer").use({
            plugin.url,
            branch=plugin.branch,
            disable=not plugin.enabled,
            requires=plugin.dependencies,
            run=plugin.on_update,
            config=plugin.config,
    })
  end
end

packer = require("packer")
packer.reset()
packer.init({compile_path = packer_db})
install_plugins(plugins)

To Reproduce
Steps to reproduce the behavior with a minimal init.lua:

  1. Start vim with the above init.lua only
  2. Install the plugins using :PackerSync
  3. Restart nvim
  4. Add a function to a lua file, endwise works ok
  5. Add a while loop to a shell script (either ft=sh or ft=bash), endwise does not work
  6. Disable nvim-ts-rainbow and nvim-treesitter-context and repeat, endwise now works for all 4 supported filetypes
  7. Disable only one of the above two conflicting extensions, endwise still does not work

Expected behavior
Endwise should work.

Screengrab
If applicable, add screengrabs which record any weird behaviour.

Additional context
neovim --version:

NVIM v0.7.0-dev+1186-g83fc91433                                                                               Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions     -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security     -fstack-clash-protection -fcf-protection -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/build/config -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/neovim-git/src -I/usr/include -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/build/src/nvim/auto -I/tmp/yaourt-tmp-nikos/aur-neovim-git/src/build/include
Compiled by my-machine

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info
@RubixDev
Copy link

This there any development on this?

I just found out that in the above mentioned situations the following loop is never run, because no match is found by treesitter.

for _, match, metadata in query:iter_matches(root, bufnr, range[1], range[3] + 1) do

@RRethy
Copy link
Owner

RRethy commented Sep 24, 2022

I looked into this a while back and found the issue was on treesitter's end, you can reproduce with a minimal config that only loads nvim-ts-rainbow (iirc) but I never had time to dig further and make an issue in the nvim-treesitter repo (or maybe core?).

@yutkat
Copy link

yutkat commented Jan 16, 2023

I found a new plugin that can endwise.
https://github.com/hrsh7th/nvim-insx

@alexmozaidze
Copy link

Gus

@alexmozaidze
Copy link

The issue is not present for me with the all those plugins. Perhaps, it was already fixed?

@RRethy
Copy link
Owner

RRethy commented May 1, 2023

The issue is not present for me with the all those plugins. Perhaps, it was already fixed?

Perhaps, it's not actually an nvim-treesitter-endwise error but rather a nvim-treesitter bug. I'll try to reproduce later and maybe close the issue.

@hrsh7th
Copy link

hrsh7th commented May 12, 2023

Basically, it's very difficult to try to take advantage of treesitter while you're in the middle of your input.
This is because the AST often becomes invalid in the middle of input, and treesitter will not be able to understand the correct tree structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants