Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better explanation on how to script Dance #293

Open
sucrecacao opened this issue Mar 12, 2023 · 3 comments
Open

Better explanation on how to script Dance #293

sucrecacao opened this issue Mar 12, 2023 · 3 comments

Comments

@sucrecacao
Copy link

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
Copy link
Owner

71 commented Mar 12, 2023

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
Copy link
Author

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
Copy link
Owner

71 commented Mar 12, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants