folke / ts-comments.nvim

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

bug: commentstring is comming from ftplugin instead of this plugin #23

Closed AgentCosmic closed 4 months ago

AgentCosmic commented 4 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0 Build type: Release LuaJIT 2.1.1713484068

Operating system/version

Debian 12

Describe the bug

The commentstring is being set by ftplugin instead of this plugin. When I run :verbose set commenstring I get this:

 commentstring="%s                                                                                                                                                                                                                                                                                
        Last set from /tmp/.mount_nvimX7ovMu/usr/share/nvim/runtime/ftplugin/vim.vim line 56

When I open the file, it's the built-in ftplugin https://github.com/vim/vim/blob/master/runtime/ftplugin/javascript.vim

Sometimes is works fine but sometimes it doesn't.

Steps To Reproduce

  1. Open a .js file
  2. Comment. It will be //%s instead of // %s as defined by this plugin.

Expected Behavior

The plugin commentstring should be used at all times.

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",
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

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

This plugin does not change the commentstring, but will still honor any options set. Did you actually try commenting?

Are you sure the plugin is loaded?

AgentCosmic commented 3 months ago

Yes I tried commenting. I used the repro.lua to test it with the native comment plugin that came with nvim v0.10. Here's a screenshot as proof. You can see I commented the code. image

I'm confused by the purpose of this plugin. I see the project description: "Easily override the comment string for a given treesitter language". For example, I see that javascript is using // %s. But when I comment it doesn't use it. So what is this plugin supposed to do if I can't use the commenstring?

folke commented 3 months ago

The repro does not call setup, so the plugin won't work.

You need to add opts = {} to it's plugin spec, or call setup() explicitely

AgentCosmic commented 3 months ago

That seems to fix it. Thanks!