vscode-extension-transformer icon indicating copy to clipboard operation
vscode-extension-transformer copied to clipboard

Macro Scripts

Open d-akara opened this issue 6 years ago • 11 comments

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

d-akara avatar Mar 26 '18 00:03 d-akara

Preview of the macro script authoring

  1. Intellisense provided for all commands
  2. Cursor location is highlighted in preview editor for each step
  3. Each command is executed in right most preview editor
  4. 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.
  5. When script authoring is complete, the user will be able to save the macro or run it in any other document

macro_preview

d-akara avatar Mar 26 '18 00:03 d-akara

Hi @dakaraphi , how can I test this, it seems great, can we use for example the search capabilities as part of a script?

jpsala avatar Mar 26 '18 12:03 jpsala

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

d-akara avatar Mar 26 '18 13:03 d-akara

Thanks a lot @dakaraphi , I'll be waiting :)

jpsala avatar Mar 26 '18 14:03 jpsala

Progress update:

  1. I'm going to publish a preview. Consider it experimental.
  2. Issues:
    1. Moving the cursor up and down in the script editor causes flickering
    2. Sometimes focus might shift from the script editor to the preview editor when moving cursor up and down
    3. 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
  3. Which vscode commands work?
    1. Most vscode commands that move the cursor, alter a selection or perform some edit on text in the editor

Features overview

  1. Write a script of vscode commands which can be recalled and executed

  2. Intellisense for vscode commands

    1. Currently I've broken some commands into groups.
    2. t - types literal text.
    3. c - cursor commands
    4. s - selection commands
    5. v - all vscode commands unfiltered
    6. x - macro script helper commands
  3. Saving of scripts. Currently saved as macros.json in the workspace .vscode folder

  4. Live Preview of Script

    1. Macro Preview opens when editing a script
    2. The preview will open with whatever text was selected when the macro create command was issued
    3. 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
      1. 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
  5. Script must be saved using the Save Script: code lens in the script editor

  6. 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
  • 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

d-akara avatar Apr 03 '18 22:04 d-akara

@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

d-akara avatar Apr 11 '18 19:04 d-akara

screenshot at jun 16 00-39-27 Hi thanks a lot for contributing here. But is seems it does not works for OSX. Please see error in attachment.

sonenko avatar Jun 15 '18 21:06 sonenko

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

image

d-akara avatar Jun 28 '18 23:06 d-akara

Related extension here: https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command&WT.mc_id=vscodecandothat-dotcom-team

faustinoaq avatar Jul 17 '18 11:07 faustinoaq

This is great work so far. A couple of points:

  1. 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.]

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

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

  4. Is there a way to assign an individual macro script to a keybinding?

Thanks.

ArturoDent avatar Aug 02 '18 06:08 ArturoDent

@ArturoDent Thanks for the feedback.

  1. 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.
  2. 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
  3. I've noticed this issue, although haven't had a chance to look into it yet.
  4. Not currently, but I think I could provide a command that accept a parameter for script that you could configure in keybindings

d-akara avatar Aug 02 '18 23:08 d-akara