JoosepAlviste / nvim-ts-context-commentstring

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

trouble getting this to work with jsx #67

Closed michael-odonovan closed 1 year ago

michael-odonovan commented 1 year ago

This is my config:

  {
    'nvim-treesitter/nvim-treesitter',
    dependencies = {
      'JoosepAlviste/nvim-ts-context-commentstring',
    },

    build = function()
      pcall(require('nvim-treesitter.install').update { with_sync = true })
    end,

    config = function()
      require('nvim-treesitter.configs').setup {
        ensure_installed = {
          'json', 'query', 'tsx', 'yaml', 'c', 'html', 'javascript', 'lua', 'cpp', 'go', 'lua', 'python', 'rust', 'typescript', 'vimdoc', 'vim', 'regex', 'bash', 'css', 'scss',
        },

        -- Install parsers synchronously (only applied to `ensure_installed`)
        sync_install = false,

        -- Automatically install missing parsers when entering buffer
        -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
        auto_install = false,

        highlight = {
          enable = true,

          ------------------------------------------------------------------------------
          -- !!! THIS IS WHAT MAKES MARKDOWN HEADINGS H1 ABLE TO BE DIFFERENT COLORS: !!
          ------------------------------------------------------------------------------
          disable = { "markdown" },

          additional_vim_regex_highlighting = false,

        },

        context_commentstring = {
          enable = true,
        },

      }
    end
  },

Is there something I am missing?

JoosepAlviste commented 1 year ago

Hey @michael-odonovan! The configuration seems correct. Here are a few questions and things to try:

  1. Which commenting plugin are you using? How are you checking whether or not this plugin works?
  2. Which file type are you testing this on?
  3. It looks like you're using the default CursorHold autocommand. Have you configured your updatetime to be smaller? E.g., vim.opt.updatetime = 100
  4. To check if this plugin is set up correctly, you can try running :=require('ts_context_commentstring.internal').calculate_commentstring(). This should return the correct commentstring based on your cursor location.
michael-odonovan commented 1 year ago

Hey Joosep, Thanks for getting back to me, your suggestions were really helpful. After reading your README I realised I was missing the config that points Comment.nvim to you ts-context plugin. My dumb. Very cool plugin, thanks

JoosepAlviste commented 1 year ago

Glad to hear it! Although it should still work without the integration. Oh well 😄