71/dance

Use of dance.run

Closed this issue · 3 comments

I'm struggling to understand dance.run, and I can't find any examples for Dance v0.5. I tried the following in keybindings.json. I'm trying to update this extension to work with Dance v0.5.

This first one (q) works, but the second one (') (use in a menu) fails with Found non-callable @@iterator.

[
    {
        "key": "q",
        "command": "dance.run",
        "args": {
            "commands": [
                "dance.select.right.extend",
                "dance.selections.changeDirection",
                "dance.select.left.extend",
                "dance.selections.changeDirection",
            ]
        },
        "when": "editorTextFocus && dance.mode == 'normal'"
    },
    {
        "key": "'",
        "command": "dance.openMenu",
        "args": {
            "menu": {
                "items": {
                    "c": {
                        "text": "column",
                        "command": "dance.run",
                        "args": {
                            "commands": [
                                "dance.selections.copy",
                                "dance.selections.changeDirection",
                                "dance.selections.copy.above",
                                "dance.selections.changeDirection",
                            ]
                        }
                    },
                }
            }
        },
        "when": "editorTextFocus && dance.mode == 'normal'"
    },
]

I also don't know how to pass arguments to commands if needed, and I don't know how to use more generic JavaScript.

More examples of dance.run would help in general, too.

71 commented

The issue is that VS Code implicitly converts "args": { ... } into "args": [{ ... }] (since "args" can be an array). dance.openMenu is less tolerant. Right now, you can simply write "args": [{ ... }], but a commit will be added soon which makes dance.openMenu more tolerant.

As for dance.run, I'll upload examples when I have interesting ones to share!

71 commented

451a510 adds a few examples for using dance.run.

Those examples are awesome. Thanks Grégoire! Looks like there's lots of flexibility and power with that.