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

Doesn't work ootb with mini.comment / Comment.nvim (React) #99

Open StitiFatah opened 5 months ago

StitiFatah commented 5 months ago

Minimal reproducible full config

https://github.com/nvim-lua/kickstart.nvim/blob/master/init.lua + add 'JoosepAlviste/nvim-ts-context-commentstring' inside require('lazy').setup({})

Description

The README says that it works ootb, I tried with comment.nvim and mini.comment and it didn't. I had to add this configuration to mini.comment :

{
  "echasnovski/mini.comment",
  event = "VeryLazy",
  opts = {
    options = {
      custom_commentstring = function()
        return require("ts_context_commentstring.internal").calculate_commentstring() or vim.bo.commentstring
      end,
    },
  },
}

and this to comment.nvim :

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

Steps to reproduce

Expected behavior

Should work ootb as per the README

Actual behavior

Doesn't work ootb

sarmong commented 3 months ago

Should work ootb as per the README

No it shouldn't, and the readme clearly lists steps to make it work for all popular commenting plugins.

As I understand the author, Defaults work out of the box. means that it works without requiring .setup() call as many plugins do and sets up the default config automatically.

JoosepAlviste commented 1 month ago

Hey! The set up instructions are a little bit out of date, it looks like. It used to be that Comment.nvim and mini.comment only used the commentstring setting when commenting, but they now have some extra logic. Comment.nvim doesn't use commentstring by default but has its own logic. Mini.nvim uses Treesitter (if available) to get the commentstring of the corresponding filetype, not the buffer's commentstring option that this plugin sets.

This means that it won't work OOTB with these plugins like it does with the native Neovim commenting, for example. I improved the setup docs a little bit here: https://github.com/JoosepAlviste/nvim-ts-context-commentstring/commit/6b5f95aa4d24f2c629a74f2c935c702b08dbde62. How does it look now?

Also, I was thinking of moving away from the autocmd approach to the approach discussed here: https://github.com/JoosepAlviste/nvim-ts-context-commentstring/issues/109. I think that that might make the initial set up of the plugin a bit easier.