Shougo / dein.vim

:zap: Dark powered Vim/Neovim plugin manager
MIT License
3.42k stars 197 forks source link

caw.vim can't works well with treesitter when using dein.vim #495

Closed krisfans closed 1 year ago

krisfans commented 1 year ago

Description

caw.vim can't works well with treesitter when using dein.vim.

To Reproduce

Steps to reproduce the behavior:

  1. start nvim with nvim -u mini.vim test.c
  2. type gcc (toggle commet key definede by caw.vim) On the line that is commented by //
  3. See error

Expected behavior

The hotkey gcc should toggle comment normally.

Screenshots

Snipaste_2022-12-25_12-47-40

Desktop:

Please complete the following information, when reporting bugs related to the Dein.vim.

Minimal Config

See the minimal config example at README#Config Example, you can remove comments unrelated to the issue.

if &compatible
  set nocompatible               " Be iMproved
endif

" Disable Vim's native pack feature
set packpath=

let $CACHE = expand('~/.cache_test/nvim')
if !isdirectory(expand($CACHE))
    call mkdir(expand($CACHE), 'p')
endif
let s:dein_dir = expand('$CACHE/dein')
let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'
if &runtimepath !~# '/dein.vim'
    if !isdirectory(s:dein_repo_dir)
        execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo_dir
    endif
    execute 'set runtimepath+='.substitute(
                \ fnamemodify(s:dein_repo_dir, ':p') , '/$', '', '')
endif

let g:dein#auto_recache = 1
if dein#load_state(s:dein_dir)
    call dein#begin(s:dein_dir)
    " Required:

    call dein#add('tyru/caw.vim')
    call dein#add('nvim-treesitter/nvim-treesitter')
    " Required:
    call dein#end()
    call dein#save_state()
endif
    " Update or install plugins if a change detected
if dein#check_install()
    if ! has('nvim')
        set nomore
    endif
    call dein#install()
endif
call dein#call_hook('source')
call dein#call_hook('post_source')

if has('filetype')
  filetype indent plugin on
endif
" Enable syntax highlighting
if has('syntax')
  syntax on
endif
set termguicolors

lua << EOF
require'nvim-treesitter.configs'.setup {
    ensure_installed = {"c", "cpp","python","lua"}, -- one of "all", "maintained" (parsers with maintainers), or a list of languages
    ignore_install = { "glsl" }, -- List of parsers to ignore installing
    highlight = {
        enable = true,              -- false will disable the whole extension
        disable = { "vim", "latex" ,"json","jsonc"},  -- list of language that will be disabled
        -- additional_vim_regex_highlighting = false,
    },
    indent = {
        enable = true
    },
    refactor = {
        highlight_definitions = {
            enable = true
        },
        highlight_current_scope = {
            enable = false
        },
    },
}
EOF

Additional context

Add any other context about the problem here.

Shougo commented 1 year ago

It is not the error of dein.vim.

https://github.com/tyru/caw.vim/blob/master/lua/caw.lua#L26

It is incompatible with current neovim treesitter.

Shougo commented 1 year ago
function M.has_syntax(lnum, col)
  local bufnr = vim.api.nvim_get_current_buf()
  for _, capture in pairs(vim.treesitter.get_captures_at_pos(bufnr, lnum - 1, col - 1)) do
      for _, cap in pairs(capture) do
          if string.match(cap, 'comment') then
              return true
          end
      end
  end

  return false
end

It works for me.