ikatyang / tree-sitter-vue

Vue grammar for tree-sitter
https://ikatyang.github.io/tree-sitter-vue/
MIT License
77 stars 25 forks source link

neovim + treesitter + vue.js + tcomment_vim not working in JS section #8

Open eduardoarandah opened 3 years ago

eduardoarandah commented 3 years ago

Comments aren't working fine with treesitter with comment plugins

I'm not sure if this is an issue to be reported here or in https://github.com/tomtom/tcomment_vim so I'll post in both sites

neovim + treesitter commenting the same in html, js

image

Debug info:

:echo tcomment#debug#CollectInfo()

on template section:

TCOMMENT: &ft = vue => vue
TCOMMENT: stx =  => 
TCOMMENT: ct  = {'_args': {'beg': 98, 'fallbackFiletype': '', 'end': 98, 'filetype': 'vue', 'comment_mode': ''}, 'commentstring': '/*%s*/', 'mode': '', 'whitespace': 'both'}

on js section:


TCOMMENT: &ft = vue => vue
TCOMMENT: stx =  => 
TCOMMENT: ct  = {'_args': {'beg': 115, 'fallbackFiletype': '', 'end': 115, 'filetype': 'vue', 'comment_mode': ''}, 'commentstring': '/*%s*/', 'mode': '', 'whitespace': 'both'}

vim + polyglot works fine!

image

on template part:

TCOMMENT: &ft = vue => vue
TCOMMENT: stx = htmlTag => htmlTag
TCOMMENT: ct  = {'_args': {'beg': 55, 'fallbackFiletype': '', 'end': 55, 'filetype': 'vue', 'comment_mode': ''}, 'commentstring': '<!-- %s -->', 'replacements': {'&': '&#38;', '-': '&#45;'}, 'mode': '', 'filetype': 'html'}

on js part:

TCOMMENT: &ft = vue => vue
TCOMMENT: stx = jsObjectSeparator => javascriptObjectSeparator
TCOMMENT: ct  = {'rxmid': '', 'rxend': '', '_args': {'beg': 76, 'fallbackFiletype': '', 'end': 76, 'filetype': 'vue', 'comment_mode': ''}, 'commentstring': '// %s', 'commentstring_rx': '\%%(// %s\|/* %s */\)', 'mode': '', 'filetype': 'javascript', 'replacements': {'*/': {'subst': '|)}>#', 'guard_rx': '^\s*/\?\*'}, '/*': {'subst': '#<{(|', 'guard_rx': '^\s*/\?\*'}}, 'rxbeg': '\*\+'}
eduardoarandah commented 3 years ago

Issue also reported on https://github.com/tomtom/tcomment_vim/issues/284

eduardoarandah commented 3 years ago

If you're here with same issue, you can use non-treesitter syntax with:

if (has("nvim"))
  " Treesitter
  Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}  " We recommend updating the parsers on update
endif

" also install Vue syntax
Plug 'posva/vim-vue', { 'for': ['vue' ] }

and later, add disable to vue

" treesitter enable
if (has("nvim"))
lua <<EOF
require'nvim-treesitter.configs'.setup {
  ensure_installed ={ "javascript", "json", "css", .... here others....  }, -- one of "all", "maintained" (parsers with maintainers), or a list of languages
  highlight = {
    enable = true,
    disable = { "vue" }
  },
  indent = {
    enable = false
  },
}
EOF
endif
ikatyang commented 3 years ago

Hi, I don't quite understand what's the issue here. Can you use the playground to reproduce the issue? And if it's reproducible there, can you post your input as text and the desired output? As a side note, tree-sitter-vue is a parser that only parses the vue-specific parts, the embedded parts are not parsed here, e.g., the content in <script>/<style> and the js expression/statement in the <template> section.