GithubHelp home page GithubHelp logo

mizlan / iswap.nvim Goto Github PK

View Code? Open in Web Editor NEW
486.0 5.0 22.0 111 KB

Interactively select and swap function arguments, list elements, and much more. Powered by tree-sitter.

License: MIT License

Lua 90.43% Scheme 9.48% Vim Script 0.09%
neovim tree-sitter hacktoberfest

iswap.nvim's People

Contributors

akinsho avatar alexmozaidze avatar bowmanmike avatar cviejo avatar indianboy42 avatar joseconseco avatar kevinhwang91 avatar liljaylj avatar loqusion avatar mizlan avatar mrcjkb avatar oliver-leete avatar ornicar avatar p00f avatar schmidma avatar she3o avatar tiagovla avatar uduse avatar weilbith avatar whythat avatar yutkat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

iswap.nvim's Issues

Feature Request: commands to swap with prev/next sibling

Hi, I'm using nvim-treesitter-textobjects which allows to define mappings to swap with prev/next parameters. But it doesn't allow to swap in arbitrary list like iswap does.

It would be nice if iswap could support this feature.

Add GIF that shows keypresses

It would be nice if the GIF showed keypresses. I think we'd have to use something other than asciicast for that to work.

[HELP] Iswap not working

Im getting this error when trying to use Iswap

E5108: Error executing lua vim/shared.lua:64: s: expected string, got nil
stack traceback:
        vim/shared.lua:64: in function 'gsplit'
        vim/shared.lua:111: in function 'split'
        ...cker/opt/nvim-treesitter/lua/nvim-treesitter/parsers.lua:719: in function 'ft_to_lang'
        ...m/site/pack/packer/opt/iswap.nvim/lua/iswap/internal.lua:19: in function 'find'
        ...m/site/pack/packer/opt/iswap.nvim/lua/iswap/internal.lua:37: in function 'get_list_node_at_cursor'
        ...share/nvim/site/pack/packer/opt/iswap.nvim/lua/iswap.lua:80: in function 'iswap_with'
        [string ":lua"]:1: in main chunk

Typed parameters in PHP only swap when cursor is on type name

    public function getAnswer(string $question, int $test)
    {
        return match ($question) {
            'starships' => $this->getStarships()
        };
    }

If the cursor is on a character in string or int on either parameter, the entire parameter and type get swapped as expected. However, if the cursor is on the variable name (not the $), then nothing happens.
Curiously, when the cursor is on the $ in int $test and I swap right, nothing happens (makes sense), but if I swap left, then the it changes places with int.

Dot repeatable

It would be nice if commands like :ISwapNodeWithLeft could be made dot repeatable.

Loop or previous error loading module 'iswap'

Part of packer.nvim set up:

   use {
      "mizlan/iswap.nvim",
      config = function()
         require("iswap").setup {
            -- The keys that will be used as a selection, in order
            -- ('asdfghjklqwertyuiopzxcvbnm' by default)
            keys = "qwertyuiop",

            -- Grey out the rest of the text when making a selection
            -- (enabled by default)
            grey = "disable",

            -- Highlight group for the sniping value (asdf etc.)
            -- default 'Search'
            hl_snipe = "ErrorMsg",

            -- Highlight group for the visual selection of terms
            -- default 'Visual'
            hl_selection = "WarningMsg",

            -- Highlight group for the greyed background
            -- default 'Comment'
            hl_grey = "LineNr",

            -- Automatically swap with only two arguments
            -- default nil
            autoswap = true,
         }
      end,
      requires = "nvim-treesitter/nvim-treesitter",
   }

leads to, upon the start of neovim:

Error detected while processing /home/derek/.local/share/nvim/site/pack/packer/start/iswap.n
vim/plugin/iswap.vim:
line    1:
E5108: Error executing lua [string ":lua"]:1: loop or previous error loading module 'iswap'
Press ENTER or type command to continue

Is this some sort of import cycle? If so, how does some start to debug?

Greying out doesn't work well

The "grey out the rest of the text" feature doesn't work. I didn't change any default configs and I have already tested several color schemes.

Before running :ISwap
image

After running :ISwap
image

Only the variable x is greyed.

Thank you very much.

โš ๏ธ Erroring on update: Git

I'm rewriting the git history to remove the assets/ folder, which contained a nontrivially-sized video and GIFs. The fix should simply to delete the plugin folder and install again; nothing should break if you do that :)

If you have a fork of this for some reason, you should not have any trouble rebasing. I've only rewritten the history for assets/.

TL;DR: delete and reinstall, and it'll work (and be faster now)

offer buffer-local and global runtime config

Instead of having to use

  ensure_installed = { 'bash', 'c', 'cpp', 'julia', 'lua', 'python', 'rust', 'typescript', 'vim', 'vimdoc', 'zig' },
  auto_install = true,
  highlight = {
    enable = true,
    additional_vim_regex_highlighting = false,
    ..
    disable = { 'c', 'cpp', 'zig' },
  },
  incremental_selection = {
    enable = true,
    keymaps = {
      ..
      disable = { 'c', 'cpp', 'zig' }, -- slow, so opt-in
    },
  },
  indent = {
    enable = true,
    disable = { 'c', 'cpp', 'python', 'zig' }, -- broken
  },
}
require('iswap').setup {}

I would prefer

  ensure_installed = { 'bash', 'c', 'cpp', 'julia', 'lua', 'python', 'rust', 'typescript', 'vim', 'vimdoc', 'zig' },
  auto_install = true,
  highlight = {
    enable = true,
    additional_vim_regex_highlighting = false,
    ..
    disable = { 'c', 'cpp', 'zig' },
  },
  incremental_selection = {
    enable = true,
    keymaps = {
      ..
      disable = { 'c', 'cpp', 'zig' }, -- slow, so opt-in
    },
  },
  indent = {
    enable = true,
    disable = { 'c', 'cpp', 'python', 'zig' }, -- broken
  },
  iswap = {
    enable = true,
    disable = { 'c', 'cpp', 'zig' },
  },
}

Justification:
nvim gcc/c-family/c-common.cc from git://gcc.gnu.org/git/gcc.git freezes editor due to treesitter and generally one must be able to workaround not well written parsers via run-time opt-in until nvim-treesitter can handle those cases of treesitter misbehaving.
The user could hack around via checking file types, but that is a not good user experience.

Error: Column value outside range

The following option is set: move_cursor = true

Now I'm editing a lua file with the following content (cursor is at the | position):

cmd = {
    'ISwap',
    'ISwapWith',
    'ISwapNode',
|   'ISwapNodeWith',
    'ISwapWithLeft',
    'ISwapWithRight',
    'ISwapNodeWithLeft',
    'ISwapNodeWithRight',
}

Then I run the ex command :ISwapNodeWithLeft and I get the following error:

E5108: Error executing lua /Users/tummetott/Projects/iswap.nvim/lua/iswap/internal.lua:160: Column value outside range
stack traceback:
        [C]: in function 'nvim_win_set_cursor'
        /Users/tummetott/Projects/iswap.nvim/lua/iswap/internal.lua:160: in function 'swap_nodes_and_return_new_ranges'
        /Users/tummetott/Projects/iswap.nvim/lua/iswap.lua:155: in function 'iswap_node_with'
        [string ":lua"]:1: in main chunk

It seems like the nvim_win_set_cursor() errors because the range is not sanity checked. Running it silent could also solve the error. What do you think?

x Tummetott

Rust queries are broken

They probably updated the parser and now the nodes are named something different. I'll take a stab at fixing it tomorrow.

[Feature Request] Add highlight like vim.highlight.on_yank

If autoswap = true and the item size of the list is 2, I hardly know whether the items have been swapped.

I want to highlight the swapped items like vim.highlight.on_yank. Maybe IncSearch and Search group for the swapped items are not bad:)

LspRestart: bad argument #1 to 'ipairs'

Sometimes my lsp serveur crash and I have to restart it with LspRestart. When I do, I get this following error in my messages.

Error executing vim.schedule lua callback: ...pack/paqs/start/nvim-lspconfig/lua/lspconfig/configs.lua:253: bad argument #1 to 'ipairs' (table expected, got
 nil)
stack traceback:
        [C]: in function 'ipairs'
        ...pack/paqs/start/nvim-lspconfig/lua/lspconfig/configs.lua:253: in function 'try_add_wrapper'
        ...pack/paqs/start/nvim-lspconfig/lua/lspconfig/configs.lua:103: in function 'launch'
        ...im/site/pack/paqs/start/nvim-lspconfig/lua/lspconfig.lua:58: in function 'fn'
        vim.lua:415: in function 'cb'
        vim.lua:285: in function <vim.lua:285>

Move cursor after swap

Thanks for this great extension!
It would be nice if we could change the cursor position to the new position of the node. So for example when you start with:

a, b
(
shows the cursor position)
and swap right, it would result in:

b, _a
instead of

_b, a
For reference vim-swap works like this.

Feature: fallback to swapping lines if not in a list

I think it just makes sense, and I have found myself wanted to swap lines of code sometimes.

Could also fallback ISwap -> ISwapNode and ISwapWith -> ISwapNodeWith instead but I think this has much less utility.

Feature: moving node

I wonder if it would be possible to add an IMove command that has a similar interface but moves the node before or after another node. We might want to add labels in between nodes rather than on, including on at the end and beginning of the 'list'

Feature/bug?: working better with nested lists

local blah = {
  { 2, 1, 6 },
  { 3, 4, 6 },
  { 3, 4, 6 },
}

If i have nested lists like this, I don't think there is anywhere to place the cursor that would make ISwapWith work with the outer list. In fact, placing the cursor on the braces of one of the inner lists makes iswap think we're trying to work on the inner list (because technically the cursor is contained within the inner list.

Even if this is fixed to work I think the nicer solution is to allow ISwapWith from visual mode and then ISwapWith will try its best to treat the visual range as the cur_node. Basically ignore lists that are contained within the visual range, or if the visual range covers multiple children of a list then we shouldn't operate within that list.

I've actually already started the implementation for a PR but I wanted to post this for discussion and if you agree with the solution?

Add more languages

Either add on to existing queries or add support for new languages. Relevant queries can be found using playground. See existing queries for examples (Rust is a good example).

Support for R

I would like to use your plugin with R, but when calling :ISwapWith it tells me "Cannot query this filetype".
Is it possible to extend this to R?

Extra comma for lua nested table

Look at this piece of lua code

t = {
  { "abc"	-- (0)
  },	-- (1)
  { "def" 
  },	-- (2)
}

(1) and (2) have }, on a separate line.

Then position cursor at line (0), execute :ISwap,
image

Then we swap them,
image

See, extra commas are put there.

Thanks you.

Move cursor: stick to where it was?

When using move_cursor option with :ISwap*With*, it should be preferred to stick to the original cursor location of the node instead of going to the beginning.
It should be possible to remember to the relative location of the cursor of the node and apply that later on.

[Feature Request]: Delete argument

Hi. Thanks for this useful plugin.
I would like to have a similar functionality to delete an argument, element in the list or parameter.
Would it be possible to implement something like this ?
Thanks.

Command not repeatable on the same line

Hello there,

Thanks for that plugin, I love it.
Only problem I have is I cannot execute the command more than once per line.
I have to reload the file every time I want to do a swap on the same line. Is that expected?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.