folke / ts-comments.nvim

Tiny plugin to enhance Neovim's native comments
Apache License 2.0
351 stars 23 forks source link

bug: failed to uncomment /** %s */ in typescript #41

Closed niuiic closed 4 months ago

niuiic commented 4 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

v0.10.0

Operating system/version

arch linux

Describe the bug

Try to config like this.

return {
    config = function()
        require("ts-comments").setup({
            lang = {
                typescript = { "// %s", "/* %s */", "/** %s */" },
                javascript = { "// %s", "/* %s */", "/** %s */" },
            },
        })
    end,
    keys = {
        { "<C-a>", "<cmd>normal gcc<cr>", mode = { "n", "x" } },
    },
}

Steps To Reproduce

Failed to uncomment the first line. Instead, it became ///** console.log('hello') */.

/** console.log('hello') */
// console.log('hello')
/* console.log('hello') */

Expected Behavior

console.log('hello')
// console.log('hello')
/* console.log('hello') */

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  { "folke/ts-comments.nvim", opts = {} },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
niuiic commented 4 months ago

This appears to be the issue of the built-in comment function. Close it.

TymekDev commented 1 month ago

I believe #55 is the root cause for this. Uninstalling jsdoc parser makes uncommenting work.

It's a matter of configuring jsdoc. See my comment in the other issue for a longer explanation.

opts = {
  lang = {
    jsdoc = "/** %s */",
  },
}

As soon as you are inside a jsdoc block its parser takes over. There is no default config for jsdoc, so it ends up using Neovim's default commentstring.