WarpScript with VS Code: pro tips

WarpScript with VSCode: pro tips

As a Warp 10 user, you already know Warp Studio. This Web editor is really convenient to use WarpScript™ everywhere. But do you know all the functionalities of VS Code + WarpScript extension?

We constantly improve this extension for power users, but we rarely communicate on changes. Here is a review of the current features, and our "pro tips" to configure VSCode for WarpScript.

We are opened to any suggestion, feel free to reach us on Twitter or Google groups if you have nice ideas to improve the extension!

WarpScript In, Json Out

If you expect a human readable result from your WarpScript, configure your keyboard to format Json easily: on my personal keyboard layout (french bépo), I choose ctrl+alt+E to run WarpScript, and ctrl+alt+I to format Json. The keys E and I are very close on this keyboard layout.

To open the shortcut editor, press ctrl K, then ctrl S

As soon as you format the json output, VSCode will keep it opened. If you run 100 times the same script, you will have 100 json on the right pane... You can set a shortcut to clean your workspace from all the json opened results. As VSCode does not provide a way to list the opened tabs, this experimental feature closes all unsaved Warp 10 json output.

Experimental, but helpful to clean up your workspace

In the shortcut menu, you can also change toggle line comment shortcut to select something you are used to.

Your personal keyboard preferences will be stored in ~/.config/Code/User/keybindings.json.

VSCode settings

VSCode will try to detect indentation. Bad idea. In the settings (ctrl+,) force indentation to the number of spaces you want.

If your computer is fast, the default completion timings could let you to type something you do not want. Rising the completion timer to 200ms or more is a good idea:

Last but not least, make WarpScript your default language! It will avoid you to painfully select the language on every new "untitled" file you create:

Recommended extension

Bracket pair colorizer from CoenraadS is helpful. Choose version 2: version 1, the most popular, does not use VScode bracket parsing engine, and won't work out of the box with WarpScript. In VScode, press Ctrl+P, then type ext install coenraads.bracket-pair-colorizer-2 .

Now you have nice colors to distinguish nested macro and lists.

Problem: this extension will also try to beautify the 20MB json you will sometimes retrieve from Warp 10... Here is the trick to exclude json from bracket colorizer:

This option is not obvious, you need to edit settings.json

Features you already master... or not!

Online help, even for remote macros

If you use WarpFleet, or some remote repos to share macros, or simply macros in your Warp 10 server "macros" directory, WarpScript extension will try to execute the macro in INFOMODE on the server, to retrieve the help from the macro.

That's the point of WarpScript documentation within WarpScript...

This feature takes into account the endpoint and the WF.ADDREPO functions within the current WarpScript.

Macro highlights and code lens

Click on a control instruction to highlight the input macros content. For example, click on IFT will highlight the "if" macro and the "then" macro (in a different color).

If a macro is too long in a control structure (more than 20 lines), a code lens appears at the beginning of the macro to help you to read the code: click on this code lens will focus on the control instruction that will consume the macro.

Both features are here to help you to read long WarpScripts files. You can disable this behavior in the extension settings.

Macro substitution

If you develop a big project, you will need to split and refactor your WarpScript into WarpScript macros. Once the macros are available on your server "macro" directory, you can call them. Pushing the macros on your server is straightforward if you are the server admin. If you're not, it means you will have to ask the sysadmin to update macros each time you fix a bug in your macro. You can of course use WarpFleet or external static repos. But the fastest way to debug macros in a big project is to use VSCode macro substitution.

This feature is activated by default in VSCode WarpScript extension. The extension will look into the project directory and sub-directories if there is the same file path: if a local file is found, the macro became a hyperlink to the local file. Each time you execute your WarpScript, the macros found as local files are automagically appended to the WarpScript. Just try with a simple example:

sum require maths/sum_numbers, which is not on the server

Special comments

At the beginning of your WarpScript, you can write several special comments that will be parsed by VSCode extension:

The extension will parse the first comment block to look for // @xx comments.

  • endpoint allow you to play with several endpoints in the same project, without changing your global extension preferences.
  • localmacrosubstitution can disable the macro substitution feature, to be sure to use the production macros, for example.
  • preview saves you a click on the preview tab you want.
  • timeunit allow you to play with a Warp 10 database configured with a different timeunit, and still having a consistent preview.

Of course, there is an automatic completion and hover help for these special comments. Note that // @endpoint is also available in WarpStudio.

Conclusion

As Warp 10 improves, tooling follow the trend! Feel free to contact us to give your feedback or push new ideas for this extension. You can also submit PR's on the extension github, we'll be happy to review them!

Waiting for the next VSCode extension good idea.
Share