JoosepAlviste / nvim-ts-context-commentstring

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

Vue comment js/ts using html comment tags #96

Closed bachirelkhoury closed 9 months ago

bachirelkhoury commented 10 months ago

Minimal reproducible full config

  { 'JoosepAlviste/nvim-ts-context-commentstring' },

  { 'numToStr/Comment.nvim',
    config = function()
      require('Comment').setup {
        pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(),
      }
    end,
  },

Description

When commenting inside the script tag, a html comment tags <!-- --> are being used instead of //

2024-02-02 08-06-34 2024-02-02 08_08_14

Steps to reproduce

I can see in the animated gif in the repo that you are successfully doing that in a vue file, but I haven't been able to do so.

Expected behavior

I expected the ts/js section to use valid comments.

Actual behavior

Typescript and javascript section is treated as html and getting commented with <!-- -->

Additional context

No response

JoosepAlviste commented 10 months ago

Hey! Sorry to hear that you're having problems. Here are a couple things you could try:

  1. Set the enable_autocmd command to false:
  {
    'JoosepAlviste/nvim-ts-context-commentstring',
    opts = {
      enable_autocmd = false,
    },
  },

I doubt that this would fix the issue, but it at least makes sure to call the setup function and does not set up the autocmd on CursorHold.

  1. Make sure that you have installed the Treesitter parsers (:TSInstall vue and :TSInstall typescript)
  2. What does :=require('ts_context_commentstring').calculate_commentstring() return in the TypeScript block? It should return // %s
  3. Try adding a print to the pre_hook to make sure that it's actually called:
  { 'numToStr/Comment.nvim',
    config = function()
      require('Comment').setup {
        pre_hook = function()
          vim.print('hello')
          return 'hehe %s'
        end,
      }
    end,
  },
  1. Try out the minimal config here to make sure that nothing in your own config is breaking the plugin.

Maybe some of those things help to figure out what's going wrong.

bachirelkhoury commented 9 months ago

Thanks for your prompt response and help @JoosepAlviste!

I was missing Treesitter vue parser. :TSInstall vue has indeed fixed the issue. Not sure how I've managed working with vue for so long without having that parser...

require('nvim-treesitter.configs').setup {
    ensure_installed = {  ... 'javascript', 'typescript', 'vue'  },
}

thanks again for your help and great plugin!