71 / dance

Make your cursors dance with Kakoune-like modal editing in VS Code.
https://marketplace.visualstudio.com/items?itemName=gregoire.dance
ISC License
435 stars 55 forks source link

Better explanation on how to script Dance #293

Open sucrecacao opened 1 year ago

sucrecacao commented 1 year ago

Hi,

I was not able to write a script for dance. My goal is to port https://github.com/occivink/kakoune-vertical-selection to codium.

From the readme I understand that in order to do so I should create a new extension and to import dance api. However, I couldn't include const { api } = await vscode.extensions.getExtension("gregoire.dance").activate(); on top my extension.ts ( from the "hello world" extension example from https://code.visualstudio.com/api/get-started/your-first-extension ). I got the following error:

Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.

And:

Object is possibly 'undefined'

Also, I was wondering if creating a new extension was the only option.

Is there a simpler way where I can just map a key to a simple javascript function that leverage Dance api ?

71 commented 1 year ago

Hi there!

Oh, that's a good idea! Making an extension is possible, but indeed since you have few commands to make you can just add a keybinding. See the run documentation for more information.

As for the error you had, it's unrelated to Dance. You probably configured TypeScript to emit code targeting a particular version of JavaScript, and that version doesn't support using await at the top level of your file, so TypeScript is complaining. Similarly, getExtension(...) may return undefined (if the extension isn't installed), in which case you can't directly call activate(), and therefore TypeScript is complaining.

sucrecacao commented 1 year ago

Thanks @71 for the quick answer

In which file json file should I put the snippet from https://github.com/71/dance/tree/master/src/commands#run ?

71 commented 1 year ago

In keybindings.json, the standard VS Code file for configuring key bindings. There is a VS Code command that brings it up, but I don't remember exactly what it is (and I don't have my laptop right now so I can't check).