Skip to content

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

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

Closed
krisfans opened this issue Dec 25, 2022 · 2 comments
Closed

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

krisfans opened this issue Dec 25, 2022 · 2 comments

Comments

@krisfans
Copy link

krisfans commented Dec 25, 2022

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.

  • OS: [Ubuntu 22.04]
  • Vim or Neovim version: [NVIM v0.8.0-1210-gd367ed9b2]
  • Commit/Version: [e.g. full SHA1 signature 2d61e0f]

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
Copy link
Owner

Shougo commented Dec 25, 2022

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 Shougo closed this as completed Dec 25, 2022
@Shougo
Copy link
Owner

Shougo commented Dec 25, 2022

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.

dshoreman added a commit to dshoreman/caw.vim that referenced this issue Feb 2, 2023
Fixes an issue where trying to uncomment will result in "attempt to
index field 'hl_map' (a nil value)..." when used with treesitter.

Based on the code in [this comment][1] and tyru#185, but tweaked
slightly to avoid messing with indentation of the existing code.

[1]: Shougo/dein.vim#495 (comment)
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

2 participants