JoosepAlviste / nvim-ts-context-commentstring

Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.
MIT License
1.16k stars 34 forks source link

Can't get the plugin to work #18

Closed mawkler closed 3 years ago

mawkler commented 3 years ago

I can't seem to get this plugin to work. This is my minimal config (not sure if nvim-lspconfig is necessary but I included it just in case):

call plug#begin('~/.config/nvim/packages/')
Plug 'neovim/nvim-lspconfig'
Plug 'kabouzeid/nvim-lspinstall'
Plug 'nvim-treesitter/nvim-treesitter', { 'do': ':TSUpdate' }
call plug#end()

lua << EOF
require('lspinstall').setup()
local servers = require('lspinstall').installed_servers()
for _, server in pairs(servers) do
  require'lspconfig'[server].setup({})
end

require('nvim-treesitter.configs').setup {
  ensure_installed = 'maintained',
  highlight = {
    enable = true,
  },
  context_commentstring = {
    enable = true
  }
}
EOF

Here's a file that I've tested the plugin on:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Test</title>
    <style>
      h1 {
        color: red;
      }
    </style>
  </head>
  <body>
    <script>
      console.log("hello");
    </script>
  </body>
</html>

On every line in the file, :echo &commentstring outputs <!--%s-->.

:TSInstallInfo says that html, javascript and css are installed.

JoosepAlviste commented 3 years ago

Hey @Melkster!

It looks like you're not including nvim-ts-context-commentstring with Plug. Another thing that might make it seem like the commentstring updating is not working, is the high default updatetime setting.

Could you try a minimal config like this and see if it fixes the problem for you?

call plug#begin('~/.config/nvim/packages/')
Plug 'nvim-treesitter/nvim-treesitter', { 'do': ':TSUpdate' }
Plug 'JoosepAlviste/nvim-ts-context-commentstring'
call plug#end()

set updatetime=100  " Or some other small value (Vim default is 4000)

lua << EOF
require('nvim-treesitter.configs').setup {
  ensure_installed = 'maintained',
  highlight = {
    enable = true,
  },
  context_commentstring = {
    enable = true
  }
}
EOF
mawkler commented 3 years ago

@JoosepAlviste Thank you that solved it. I think it was a combination of me forgetting to include nvim-ts-context-commentstring in my minimal config file and some other plugin causing the autocmd CursorHold to dissapear in my full config for some reason.