Skip to content

Inline comments (e.g., gcw) in Python #234

Closed

Description

@IamGianluca

Hi,

I just discovered the plugin and getting up to speed. I've seen that with some languages, the plugin is smart enough to comment out an argument in a function call:

-- from this
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
-- to this
vim.keymap.set('n',--[[  '<space>e' ]], vim.diagnostic.open_float, opts)

In Python, however, the plugin doesn't return a valid syntax if we comment out an argument.

# from this
def my_function(a, b):
    return b
# to this
def my_function( #a, b):
    return b

I would have expected it to return something like this...

def my_function(b):  #a):
    return b

I'm assuming this is because Python doesn't have inline comments, but I was wondering if there was a way to achieve something similar to what I described. It would be particularly useful when refactoring code.

Activity

  1. numToStr commented on Sep 8, 2022

    @numToStr
    Owner

    Yes, this is expected because python doesn't have block commentstring. And I am not sure, how is this achievable? Maybe using treesitter? But that being said, this is certainly out of scope for the plugin to support this OOTB.

  2. IamGianluca commented on Sep 8, 2022

    @IamGianluca
    Author

    I thought this could have been possible by leveraging treesitter. I'm not super familiar with what treesitter exposes and how comment.nvim interfaces with it. Perhaps I can look into that and resume the discussion later on. Thank you for now!

  3. Repository owner locked and limited conversation to collaborators on Sep 8, 2022
  4. converted this issue into a discussion #235 on Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions