Tip
Check out Typed HaasScript, which brings type annotations, type checking, and code hints to HaasScript in VS Code and JetBrains editors. It should ideally make this project obsolete.
This project generates Luanalysis Type Definitions for the HaasScript Language so code editors can autocomplete and type check your scripts. If you do not want to run the project, you can simply download the zip files of the output.
Warning
Only use 1 of the zip files of lua definitions, or Luanalysis will error about duplicates.
- Install IntelliJ IDEA or PyCharm from JetBrains. Their core features are free. Or use any paid JetBrains product.
- In the settings, install the Luanalysis plugin.
- Open a folder containing your haas scripts.
- Copy the (unzipped) lua definitions into the same folder or a sub folder. Use only one of the zip files.
- The Luanalysis plugin should pick them up automatically. You will now see code hints and type errors in your scripts.
- If the JetBrains code editor freezes, force kill and increase its memory limit in its settings in JetBrains Toolbox.
Note
Normally, JetBrains products will alert you that you need to give it more memory. But it seems to not be able to track memory used by Luanalysis.
-
Clone the git repository.
-
Install Node 26 or greater.
-
Install pnpm 12.18.0 or greater.
-
Open a terminal in the project root.
-
Run
pnpm install. -
Run
pnpm start. -
Read and follow the help output in the console.
Show the help output
This script requires 3 parameters: environment, file extension, HAR file. Environment may be "production" or "staging". It only changes where the output is saved. Anything other than "staging" (case-insensitive) assumes "production". File extension may be anything, but "lua" or "hs" is recommended. The HAR file is exported from a logged-in web browser. The README explains how. Example: pnpm start prod lua "app.haasbot.com.har"
The script does not connect to the Haas server. It reads a HAR file, which is a record of network traffic that you export from your own logged-in browser.
These steps should work in Chromium-based browsers, including Google Chrome, Microsoft Edge, Brave, Opera, and Vivaldi. Mozilla Firefox and Apple Safari should have a similar feature in the Network tab of their developer tools, but the exact steps will differ.
-
Open Haas cloud server in your browser and log in.
-
Open your browser's developer tools.
-
Select the Network tab of the developer tools.
-
In the filter box of the Network tab, enter
/GET_COMMANDS|INIT_DATA/so that only the two needed requests are listed. -
In Haas cloud server, open the Web Editor. (or reload the page if the Web Editor is already open)
-
Click the Export HAR icon, a small down arrow at the top of the Network tab, and save the file.
-
Pass the path of the file to
pnpm start, with double quotes around the path so that spaces work:pnpm start prod lua "app.haasbot.com.har"
Note
If you need staging definitions, do these steps again on the staging server.
Many of the number parameters of functions can also take a list of numbers. But it is not clear which do and which do not. So each run generates two versions of the definitions.
| Version | Numbers are typed as | When you assign a list of numbers |
|---|---|---|
Without flex-numbers |
number |
Gives errors, even though it might be valid |
With flex-numbers |
number | number[] |
Does not error, even though it might be invalid |
I'm not sure which is better or worse. So you have to decide for yourself which you prefer.
Tip
Typing HaasScript's numbers correctly takes special handling in the parser, and this project relies on the Luanalysis parser, which we do not control. Typed HaasScript has its own parser with that handling built in, so it needs only one version of its definitions, with number parameters typed based on behavior verified on the TradeServer.