Run & debug v1 and v2 in the same instance of VSCode

Scripting and setups with Visual Studio Code (vscode) and AutoHotkey.
DaveT1
Posts: 225
Joined: 07 Oct 2014, 11:23

Run & debug v1 and v2 in the same instance of VSCode

Post by DaveT1 » 10 Mar 2023, 06:28

I have a project where I'm porting some v1 script to v2. I also use vscode. So it's going to be really useful to be able to run both v1 and v2 interpreters within the same instance of vscode. Here’s a summary of what I do in case it’s useful to others / someone can advise a better way:

Firstly, I use the following ahk-specific extensions in vscode:
  • "AutoHotkey v2 Language Support(v1.9.2)" by thqby, and
  • "vscode-autohotkey-debug(v1.11.0)" by zero-plusplus.
and massive thanks to those guys for producing these :bravo:.

Secondly, I uninstalled AutoHotkey and re-installed a fresh version of v1.1 from the website. This gave me the following directory structure:

Untitled.png
Untitled.png (24.82 KiB) Viewed 3023 times

For v1, use Run & Debug from the vscode context menu (mouse right click)
This runs the interpreter specified in the Auto Hotkey2: Interpreter Path setting of thqby's extension. I’ve set this to C:\Program Files\AutoHotkey\AutoHotkeyU64.exe.

For v2, use Run & Debug from the vscode Run menu
By default this runs the interpreter specified in zero-plusplus' extension, ie: C:/Program Files/AutoHotkey/v2/AutoHotkey.exe. So, first making backups of both files, I renamed AutoHotkey64.exe as AutoHotkey.exe. Obviously this will need to be re-done each time there is a new release of v2!

Other notes:
  • In all cases, file extensions are “.ahk”. Never any variant of this.
  • If you accidentally run v1 the v2 way, or vice versa, vscode reports errors in the Panels (see code.visualstudio.com/docs/getstarted/userinterface). These errors make it obvious something’s gone wrong!
  • To simply run the *.ahk file outside of vscode, double click it in file explorer. The fresh install above, provides a script launcher (configured through the new Dash utility). This checks the script for clues as to which version of ahk should be used to run it. But if you include #Requires (eg #Requires AutoHotkey v1.1, or #Requires AutoHotkey v2.0) as appropriate at the head of each script, then that’s best.
OK, HTHs! And, obviously, more than happy to have any improvements pointed out to me :thumbup:.

User avatar
RaptorX
Posts: 386
Joined: 06 Dec 2014, 14:27
Contact:

Re: Run & debug v1 and v2 in the same instance of VSCode

Post by RaptorX » 10 Mar 2023, 07:40

I use the AutoHotkey Plus Plus extension for v1 and the AutoHotkey v2 Language Support extension for v2.

Then configure each accordingly. That way i just have to select the language in vscode:

Image

Image

That way you never have the issue of "running the wrong one" because the language selected will highlight correctly and will run with the correct interpreter.

I also agree with using vscode-autohotkey-debug as the debugger as it allows for advanced options when debugging.

thats my goto for vscode + autohotkey. :)
Projects:
AHK-ToolKit

DaveT1
Posts: 225
Joined: 07 Oct 2014, 11:23

Re: Run & debug v1 and v2 in the same instance of VSCode

Post by DaveT1 » 17 Mar 2023, 10:11

Oh man, thanks @RaptorX - learnt so much from you from your vids with Joe :bravo: :thumbup:.

I'm sure anyone who needs this will follow your advice.

I'm currently sticking with the setup I have as I'm chicken to change it, break it and not know how to revert it (vscode still mighty new to me)!! Here's a graphic I made ('cos I was bored), that might just show it a little more clearly - all in the same instance of vscode:
VScode v1&v2.png
VScode v1&v2.png (299.55 KiB) Viewed 2827 times
(though note that ctrl+F5 only runs the v1 interpreter!!

User avatar
RaptorX
Posts: 386
Joined: 06 Dec 2014, 14:27
Contact:

Re: Run & debug v1 and v2 in the same instance of VSCode

Post by RaptorX » 17 Mar 2023, 10:53

DaveT1 wrote:
17 Mar 2023, 10:11
Oh man, thanks @RaptorX - learnt so much from you from your vids with Joe :bravo: :thumbup:.

I'm sure anyone who needs this will follow your advice.

I'm currently sticking with the setup I have as I'm chicken to change it, break it and not know how to revert it (vscode still mighty new to me)!! Here's a graphic I made ('cos I was bored), that might just show it a little more clearly - all in the same instance of vscode:
VScode v1&v2.png
(though note that ctrl+F5 only runs the v1 interpreter!!
hey Dave!

you are not changing the language before trying to run it...
image.png
image.png (63.21 KiB) Viewed 2825 times
Notice that you are #Requiring v1 but your language selected is v2, thats the reason you are having issues... you have to change the language on the bottom right as I showed on the previous post.
Projects:
AHK-ToolKit

DaveT1
Posts: 225
Joined: 07 Oct 2014, 11:23

Re: Run & debug v1 and v2 in the same instance of VSCode

Post by DaveT1 » 17 Mar 2023, 11:29

Hello :wave: - honoured to be chatting with you :D.

Sorry, maybe I was being unclear - the approach I have does work with the extensions set up as described in the 1st post. This allows ahk v2 run and debug from the vscode Run menu and ahk v1 run and debug from the vscode context menu. No need to switch languages or any such.

There are 2 caveats: (1) if you try to run and debug a v2 script via the run and debug commands on the context menu (or vice versa), the panel will report errors - but that just means you didn't select as described in above para - so simply select the right approach, and (2) there's a bit of work to rename interpreters on subsequent releases of autohotkey.

Otherwise working good so far. However, still need to use this approach for real, and if I trip across any issues with the setup I'll report those back here!

Thanks again :thumbup.

ericmil8
Posts: 2
Joined: 14 Aug 2023, 10:32

Re: Run & debug v1 and v2 in the same instance of VSCode

Post by ericmil8 » 14 Aug 2023, 10:41

This is my configuration to use 1 launcher for both types versions in VS Code. It works well, the only issue i have had is the Debugger stops in common.ahk every time I launch a debug, so I need to click continue. "F5" Twice. But that is easyer then forgetting to switch interpreters.

Then i just add the following to each script:

Code: Select all

#Requires AutoHotkey v2+
#Requires AutoHotkey v1.1+

}

Code: Select all

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "Start-end" : "9002-9010",
    "configurations": [
        {
            "type": "autohotkey",
            "request": "launch",
            "name": "AutoHotkey UX Debugger",
            "runtime":"C:\\Users\\eric.miller\\AppData\\Local\\Programs\\AutoHotkey\\UX\\AutoHotkeyUX.exe",
            "runtimeArgs": ["C:\\Users\\eric.miller\\AppData\\Local\\Programs\\AutoHotkey\\UX\\launcher.ahk",
                "/ErrorStdOut"
            ],
            //"args": ["C:\\Users\\eric.miller\\AppData\\Local\\Programs\\AutoHotkey\\UX\\launcher.ahk"],
            "program": "${file}",
            "stopOnEntry": true,
            "suppressMultipleSessionWarning": true
        }
        
    ]

}

[Mod edit: Fixed broken codebox.]

DaveT1
Posts: 225
Joined: 07 Oct 2014, 11:23

Re: Run & debug v1 and v2 in the same instance of VSCode

Post by DaveT1 » 16 Aug 2023, 02:47

Just an update to all this:

It seems that the vscode extension AutoHotkey Plus Plus v5.0.2 (11-Aug-23) by Mark Wiemer now supports both v1 and v2 without changing any settings. :superhappy:

I have to say that I've not fully tried this, but a quick test shows good stuff. If it continues to look good then this is my setup of choice.

Post Reply

Return to “Visual Studio Code”