Coder Social home page Coder Social logo

mini.comment integration pre hook - require("ts_context_commentstring.internal").update_commentstring() requires 1 argument about nvim-ts-context-commentstring HOT 5 CLOSED

joosepalviste avatar joosepalviste commented on August 18, 2024
mini.comment integration pre hook - require("ts_context_commentstring.internal").update_commentstring() requires 1 argument

from nvim-ts-context-commentstring.

Comments (5)

krishna-bala avatar krishna-bala commented on August 18, 2024

Update: it appears I am calling the pre hook correctly, as I am able to print out a debug message when I attempt to comment a message. Here's what my mini.comment plugin looks like:

-- lua/plugins/minicomment.lua
return {
  "echasnovski/mini.comment",
  dependencies = {
    "nvim-treesitter/nvim-treesitter",
  },
  opts = {
    hooks = {
      pre = function()
        print("Successfully calling pre hook function...")
        require("ts_context_commentstring.internal").update_commentstring()
      end,
    },
  },
}

and here is my nvim-treesitter plugin customization:

-- lua/plugins/nvim-treesitter.lua
return {
  "nvim-treesitter/nvim-treesitter",
  dependencies = {
    "JoosepAlviste/nvim-ts-context-commentstring",
  },
  opts = {
    context_commentstring = {
      enable = true,
      enable_autocmd = false,
      config = {
        c = "// %s",
        cpp = "// %s",
      },
    },
  },
}

So I am inclined to think my call to require("ts_context_commentstring.internal").update_commentstring() isn't working as intended.

from nvim-ts-context-commentstring.

JoosepAlviste avatar JoosepAlviste commented on August 18, 2024

Hey @krishna-bala! The configuration looks correct to me. I haven't used LazyVim though, so I'm not sure if there are any special steps that need to be taken.

update_commentstring() does accept 1 argument with extra options, but it isn't required. I think that we should update the function docs to set it as optional. The code docs could be improved in general.

Here are some questions and things to try:

  1. What file type are you trying this out in?
  2. If you manually call :=require('ts_context_commentstring.internal').calculate_commentstring(), then does that output the correct commentstring?

from nvim-ts-context-commentstring.

krishna-bala avatar krishna-bala commented on August 18, 2024

Hi @JoosepAlviste, thanks for the reply. I'm trying this on cpp files (*.h, *.cc). Manually calling :=require('ts_context_commentstring.internal').calculate_commentstring() in a *.cc file outputs the desired commentstring, // %s. However, when I use mini.comment to comment out a line it still implements the "default" commentstring that comes with mini.comment, which is /* %s */. I suspect I don't fully understand how the plugins are loaded in LazyVim and am implementing this incorrectly.

That being said, the mini.comment maintainer suggested a workaround for my use case (described below).

Create a file after/ftplugin/<some-filetype>.lua inside your Neovim config (e.g. ~/.config/nvim/) and put this line there: vim.bo.commentstring = '<some-commentstring>'

e.g.

-- ~/.config/nvim/after/ftplugin/c.lua
vim.bo.commentstring = '<some-commentstring>'

from nvim-ts-context-commentstring.

victornswd avatar victornswd commented on August 18, 2024

Not really sure if this is helpful for this situation, but I was having issues with mini.comment in the past weeks as well. It changed to commentstring from tree-sitter which caused some issues with some filetypes. I opened an issue on this and I got a recommended a new way of setting up nvim-ts-context-commentstring: echasnovski/mini.nvim#342

from nvim-ts-context-commentstring.

JoosepAlviste avatar JoosepAlviste commented on August 18, 2024

Thanks for letting me know, @victornswd! I've updated the integration instructions in the wiki: https://github.com/JoosepAlviste/nvim-ts-context-commentstring/wiki/Integrations#minicomment

Hopefully this solves the issue. Feel free to re-open if there are still problems with this.

from nvim-ts-context-commentstring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.