folke / ts-comments.nvim

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

bug: wrong comments for different context #32

Closed timsofteng closed 5 months ago

timsofteng commented 5 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

Macos sonoma 14.1.2

Describe the bug

In case you want to comment blocks with different comments at once you get only one time of comments instead of different comment types for different blocks.

Steps To Reproduce

  1. nvim test.tsx
  2. paste it
    
    import React from "react";

const Logo = "https://logrocket-assets.io/static/home-hero-c97849b227a3d3015730e3371a76a7f0.svg";

const FirstComponent: React.FC<{}> = () => { return (

A Simple React Component Example with Typescript

Logo

This component shows the Logrocket logo.

For more info on Logrocket, please visit https://logrocket.com

); };

export default FirstComponent;

3. `gg` `V` `G` `gc`

### Expected Behavior

Different blocks shoud be commented with different types accroding to readme

tsx = { "// %s", -- default commentstring when no treesitter node matches "/ %s /", call_expression = "// %s", -- specific commentstring for call_expression jsx_attribute = "// %s", jsx_element = "{/ %s /}", jsx_fragment = "{/ %s /}", spread_element = "// %s", statement_block = "// %s", }


### Repro

```Lua
-- Clone 'mini.nvim' manually in a way that it gets managed by 'mini.deps'
local path_package = vim.fn.stdpath("data") .. "/site/"
local mini_path = path_package .. "pack/deps/start/mini.nvim"
if not vim.loop.fs_stat(mini_path) then
    vim.cmd('echo "Installing `mini.nvim`" | redraw')
    local clone_cmd = { "git", "clone", "--filter=blob:none", "https://github.com/echasnovski/mini.nvim", mini_path }
    vim.fn.system(clone_cmd)
    vim.cmd("packadd mini.nvim | helptags ALL")
    vim.cmd('echo "Installed `mini.nvim`" | redraw')
end

-- Set up 'mini.deps' (customize to your liking)
require("mini.deps").setup({ path = { package = path_package } })

local add = MiniDeps.add
local now, later = MiniDeps.now, MiniDeps.later

-- Safely execute immediately
now(function()
    add("folke/ts-comments.nvim")
    require("ts-comments").setup()

    add("nvim-treesitter/nvim-treesitter")
    require("nvim-treesitter.configs").setup({
        ensure_installed = {
            "tsx",
            "typescript",
        },
    })
end)
folke commented 5 months ago

That's indeed a limitation to NEovim's commenting which is always line wise and only gets the commentstring for the first line that it then uses for all the lines