vscode-extension-transformer
vscode-extension-transformer copied to clipboard
Macro Scripts
VSCode currently does not support recordable macros. We also can not implement this as an extension since the API's don't let us track all user activity.
This is an attempt at hopefully providing the next best option, macros as scripts.
Feature ideas:
- Write a macro script which can invoke any vscode command
- Provide intellisense for commands for quicker authoring
- Preview in near realtime the script transformation as applied to a document while authoring a script
- Allow to play macro script step by step, forwards and backwards in preview
- Save scripts for reuse
- Provide command which can rerun last macro, useful for repeating via key binding
Preview of the macro script authoring
- Intellisense provided for all commands
- Cursor location is highlighted in preview editor for each step
- Each command is executed in right most preview editor
- Using the cursor to navigate up and down in the script, we can step backwards or forwards through each command in the macro and see the effect.
- When script authoring is complete, the user will be able to save the macro or run it in any other document
Hi @dakaraphi , how can I test this, it seems great, can we use for example the search capabilities as part of a script?
@jpsala I am planning to support search; however, I will need to write some helper functions, since invoking search through the normal vscode commands is not going to work so well.
As far as testing, It is still a bit too early. I expect within a week or two I will have something that is useful enough to play around with. I will probably just publish an update for this extension to the marketplace at that time.
Thanks a lot @dakaraphi , I'll be waiting :)
Progress update:
- I'm going to publish a preview. Consider it experimental.
-
Issues:
- Moving the cursor up and down in the script editor causes flickering
- Sometimes focus might shift from the script editor to the preview editor when moving cursor up and down
- There are probably lots of vscode commands that aren't going to work as a script. Many are simply not useful in that context. I haven't had time to trim the list of intellisense provided commands down to only those that both work and will be useful
- Which vscode commands work?
- Most vscode commands that move the cursor, alter a selection or perform some edit on text in the editor
Features overview
-
Write a script of vscode commands which can be recalled and executed
-
Intellisense for vscode commands
- Currently I've broken some commands into groups.
-
t
- types literal text. -
c
- cursor commands -
s
- selection commands -
v
- all vscode commands unfiltered -
x
- macro script helper commands
-
Saving of scripts. Currently saved as
macros.json
in the workspace.vscode
folder -
Live Preview of Script
-
Macro Preview
opens when editing a script - The preview will open with whatever text was selected when the macro create command was issued
- The preview can also be set to any text using the code lens at the top
Set current text as starting point for macro test
- The cursor starting point for running the macro will be set from the current cursor position in the preview editor when the code lens is clicked
-
-
Script must be saved using the
Save Script:
code lens in the script editor -
A macro can be executed repeatedly for multiple lines by first making a selection over multiple lines. The macro will then be executed on each line and the cursor will start at the beginning of each line
Future Considerations
- Running vscode commands as a script has a number of challenges
- There is no API to directly execute a command against a particular editor
- Focus must be shifted to the preview editor, commands executed, focus returned to script editor. This causes some flickering and flashing
- Executing commands are not very fast. Might not work so well for large documents
- Without some helper commands, the vscode commands will not be very useful
- There is currently one helper command to perform a search like function to move the cursor forward until finding matching text.
x cursorForwardUntil sometext
- There is currently one helper command to perform a search like function to move the cursor forward until finding matching text.
- We might can provide better experience using only helper functions
- Likely filtering and performance issues could be eliminated
- However, we would need to implement ourselves all of the useful cursor, selection etc vscode functions
@jpsala just wanted to follow up to see if you had a chance to try the macros and if you have any feedback in regards to https://github.com/dakaraphi/vscode-extension-transformer/issues/13#issuecomment-378413367

@sonenko @aaronmyatt
The macro script is not actually a file. So you have to click on the code lens
- Save Script:
to save the script.

Related extension here: https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command&WT.mc_id=vscodecandothat-dotcom-team
This is great work so far. A couple of points:
-
I am unable to use the mouse in the quick open panel (or whatever it is called) to select which macro script to run, I can only use the arrow and enter keys to choose which script to run. [Not a big deal.]
-
There are a some more complex commands, see https://code.visualstudio.com/docs/extensionAPI/vscode-api-commands that could be implemented - they all take arguments though - especially the cursor move since it is more powerful, although I suppose all its actions can be replicated in a much more verbose way with the existing simple commands. The macros/macrosRe extensions do support at least some of these complex commands.
-
This extension's own commands, like "dakara-transformer.sortLines" do work in the macros scripts although they do not show up in the "v" command intellisense.
-
Is there a way to assign an individual macro script to a keybinding?
Thanks.
@ArturoDent Thanks for the feedback.
- This seems to work ok for me. This is not something I actually control. I'm just using vscode's provided pickers. Not sure what the issue is in your case.
- I'm still uncertain which direction I want to take macro commands. See https://github.com/dakaraphi/vscode-extension-transformer/issues/13#issuecomment-378413367 Future considerations
- I've noticed this issue, although haven't had a chance to look into it yet.
- Not currently, but I think I could provide a command that accept a parameter for script that you could configure in keybindings