numToStr / Comment.nvim

:brain: :muscle: // Smart and powerful comment plugin for neovim. Supports treesitter, dot repeat, left-right/up-down motions, hooks, and more
MIT License
3.84k stars 152 forks source link

error on JSON files #124

Closed shaeinst closed 2 years ago

shaeinst commented 2 years ago

throws the following error when commenting on any json files.

E5108: Error executing lua Vim(lua):E5108: Error executing lua ...te/pack/packer/start/Comment.nvim/lua/Comment/opfunc.lua:155: Vim:Co
mment :: Invalid commentstring: "". Run ':h commentstring' for help.
stack traceback:
        [C]: in function 'nvim_buf_set_lines'
        ...te/pack/packer/start/Comment.nvim/lua/Comment/opfunc.lua:155: in function 'linewise'
        ...te/pack/packer/start/Comment.nvim/lua/Comment/opfunc.lua:82: in function 'opfunc'
        .../site/pack/packer/start/Comment.nvim/lua/Comment/api.lua:25: in function 'toggle_current_linewise_op'
        [string ":lua"]:1: in main chunk
        [C]: at 0x5648a929b921
stack traceback:
        [C]: at 0x5648a929b921

my config:

require('Comment').setup({

    mappings = {
        basic = true, ---Includes `gcc`, `gcb`, `gc[count]{motion}` and `gb[count]{motion}`
        extra = true, ---Includes `gco`, `gcO`, `gcA`
        extended = false, ---Includes `g>`, `g<`, `g>[count]{motion}` and `g<[count]{motion}`
    },

    ---LHS of toggle mapping in NORMAL
    ---@type table
    toggler = {
        line = 'cc', ---line-comment keymap
        block = 'gcb', ---block-comment keymap
    },

    ---LHS of operator-pending mapping in VISUAL mode
    ---@type table
    opleader = {
        line = 'gc', ---line-comment keymap
        block = 'gb', ---block-comment keymap
    },
})
numToStr commented 2 years ago

Set the filetype to jsonc as json doesn't support comments.

shaeinst commented 2 years ago

oh yes..

zhengpd commented 2 years ago

The error could be better handled like saying "Unsupported filetype to comment." It's a little confusing when first saw this error. @numToStr