Wansmer / sibling-swap.nvim

Neovim plugin for swaps closest siblings with Tree-Sitter
MIT License
155 stars 1 forks source link

Swapping doesn't work when JSX props are on separate lines #4

Closed Jeaciaz closed 1 year ago

Jeaciaz commented 1 year ago

Hi, thank you for the plugin! It feels really good, however the swapping of JSX props doesn't work when they're on separate lines, even with allow_interline_swaps enabled:

// Page.tsx

export const Component = () => {
  return (
    <div
      className="123"
      style={{
        |w|idth: 100,
//      | it correctly swaps width and height when the cursor is on 'w'
        height: 100,
      }}
      |d|ata-one=""
//    | however when the cursor is on 'd' there, I cannot swap 'data-one' and 'data-two' attributes
      data-two=""
    ></div>
  )
}

Edit: for clarity, it works perfectly when the attributes are on the same line.

My packer and treesitter setup:

```lua use { 'Wansmer/sibling-swap.nvim', requires = { 'nvim-treesitter' }, config = function () require'sibling-swap'.setup {} end } use { 'Wansmer/sibling-swap.nvim', requires = { 'nvim-treesitter' }, config = function () require'sibling-swap'.setup {} end } -- in a separate file local status, ts = pcall(require, 'nvim-treesitter.configs') if (not status) then return end ts.setup { highlight = { enable = true, disable = {} }, indent = { enable = true, disable = {} }, ensure_installed = { "markdown", "markdown_inline", "lua", "tsx", "json", "yaml", "css", "html", }, autotag = { enable = true }, context_commentstring = { config = { javascript = { __default = '// %s', jsx_element = '{/*%s*/}', jsx_fragment = '{/*%s*/}', jsx_attribute = '// %s', comment = '// %s' }, typescript = { __default = '// %s', __multiline = '/* %s */' } } } } local parser_config = require 'nvim-treesitter.parsers'.get_parser_configs() parser_config.tsx.filetype_to_parsername = { "javascript", "typescript.tsx" } ```

Wansmer commented 1 year ago

Thanks for the feedback!

I've added a fix to the PR #5, but I won't merge it into the main for now because I found a few things that go against the concept of the plugin. (in cases where there are no separators like a comma between siblings on different lines, as is the case with jsx and html). For now, you can use PR #5.

Wansmer commented 1 year ago

To move attributes, now you need to set the option "interline_swaps_witout_separator" to true