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.76k stars 147 forks source link

Python comments are broken #329

Closed eelkeh closed 1 year ago

eelkeh commented 1 year ago

Previously it would comment out lines and blocks with a prepended hash #, now every line is treated as a docstring with """" I'm not sure in what commit this broke but I suspect it's a fairly recent change.

Expected behaviour (filetype=python)

a = 1
# a = 1

Actual behaviour:

a = 1
""" a = 1 """
numToStr commented 1 year ago

Working just fine for me. Make sure you are on 0.9 stable.

detroyejr commented 1 year ago

I also had this issue and it seems to be a configuration/plugin related problem. Disabling "JoosepAlviste/nvim-ts-context-commentstring" and using a generic require('Comment').setup() solved it for me.

crzdg commented 1 year ago

Yes seems to be related to nvim-ts-context-commentstring and its configuration breaking some things. Had to disable it as well to get the Comment to work as expected.

EDIT: Nevermind, turns out the config of pre-hooks for Comments, using nvim-ts-context-commentstring broke it for me. This was my previous config for Comment.

local status_ok, comment = pcall(require, "Comment")
if not status_ok then
  return
end

comment.setup {
  pre_hook = function(ctx)
    local U = require "Comment.utils"
    local location = nil
    if ctx.ctype == U.ctype.block then
      location = require("ts_context_commentstring.utils").get_cursor_location()
    elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then
      location = require("ts_context_commentstring.utils").get_visual_start_location()
    end
     return require("ts_context_commentstring.internal").calculate_commentstring {
       key = ctx.ctype == U.ctype.line and "__default" or "__multiline",
       location = location,
     }
  end,
}

Change it to acording to the ongoing doc-improvements in nvim-ts-context-commentstring. See the open branch for better docs here: https://github.com/JoosepAlviste/nvim-ts-context-commentstring/tree/feature/docs Could be that I used an old basic setup method for this combination of Comment and nvim-tx-context-commentstring.

require('Comment').setup {
  pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(),
}

Everything, seems to work fine again.