Help with setting up debugging environment in VSCode please Topic is solved

Scripting and setups with Visual Studio Code (vscode) and AutoHotkey.
gaberiel__2
Posts: 14
Joined: 18 Jan 2023, 14:18

Help with setting up debugging environment in VSCode please

Post by gaberiel__2 » 23 Feb 2023, 09:42

So after reading anonymous1184 (A reddit AuotoHotkey, community member whom has saved my skin many times) excellent article,AHK Debugging with Visual Studio Code

I want to put my message box days behind me and start using a debugger.

My Test.ahk script content consists of:

Code: Select all

#Warn, All, OutputDebug
#SingleInstance, Force

;OutputDebug, Hello, World
MsgBox, Hello, World
F5::F12 ;Just to keep script active, I guess

I have covered some ground, but I am suffering from an issue.

Run without debugging
If I try to run the script without debugging (Main menu: Run> Run Without Debugging), on first run it will work but on second run I will get xxxxx error message.
  • If click on Cancel then THIS error message pops up, Vscode open a new tab titled Launch.json
  • If click on Yes, then THIS error message pops up, "Script is already running" but my script already has #SingleInstance, Force. I would much prefer if the script is just reloaded.

Start Debugging
When Start debugging (Main menu: Run> Start Debugging), on first run it will work but on second run I will get THIS error message, when I click cancel
Then THIS error message pops up, finally. Vscode open a new tab titled Launch.json

I set out to try and understand what is happening, reading the documentation for the debugging extension I am using, Zero-Plus -- vscode-autohotkey-debug, it mentions a solution for this issue:
A port to be assigned to the debugger. Basically, you don't need to change it, but if you want to debug more than one at the same time, you need to set different ports for each.
default: 9002
And also:
If a port is already in use, a confirmation message will appear asking if you want to use a different port. If this message is annoying, you can give the debug adapter permission to use the port using the "start-end" format.
e.g. "9002-9010"
but I am stuck on configuring the Launch.json file from the ground up, to use "start-end" and "9002-9010" options

Amongst the many things I tried in the Launch.json are:

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",
    "configurations": [
       "Start-end" : {"9002-9010"}
       \\ "Start-end" : "9002-9010
       \\ 9002-9010
    ]
}
I as you can tell I am not a programmer and Json is my bane. I tried looking around for an example of this Launch.json file but nothing exists on the extension repository.

Has anyone come across this issue before?

I would simply like for the script to be reloaded and avoid all this message boxes. Ironically enough, this is what I set out to avoid.

Any help would be wonderfull.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Help with setting up debugging envoiroment in VSCode please  Topic is solved

Post by swagfag » 23 Feb 2023, 16:52

here u have all valid launch.json options u can use https://github.com/zero-plusplus/vscode-autohotkey-debug/wiki/Launch-Mode
u can have a per-project/folder launch.json defined or u can have one universal config in ur settings.json (CTRL SHIFT P > Open Preferences: User Settings (JSON))
here is a sample settings.json that already includes a launch.json like config inside of it:

Code: Select all

{
    "security.workspace.trust.emptyWindow": false,
    "security.workspace.trust.enabled": false,
    "security.workspace.trust.startupPrompt": "never",
    "editor.unicodeHighlight.invisibleCharacters": false,

    "launch": {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "AHK v1 x64",
                "type": "autohotkey", 
                "request":	"launch",
                "runtime": "C:\\Program Files\\AutoHotkey\\AutoHotkeyU64.exe"
            }, 
            {
                "name": "AHK v1 x86",
                "type": "autohotkey", 
                "request":	"launch",
                "runtime": "C:\\Program Files\\AutoHotkey\\AutoHotkeyU32.exe"
            }, 
        ],
        "compounds": []
    }
}
"start-end" is meant as the key

Code: Select all

{
	...
	"port": "9000-9010",
	...
}
but there is no reason for u to mess with this. if the debuggerport is occupied either ure already debugging on that port in another debugging session(possibly with a different editor entirely) or a previously debugged script could not be killed. shut everything down, kill any rogue ahk/vscode processes and restart

markwiemer
Posts: 3
Joined: 13 Mar 2023, 23:59
Contact:

Re: Help with setting up debugging environment in VSCode please

Post by markwiemer » 14 Mar 2023, 00:18

Maintainer of AutoHotkey Plus Plus (AHK++) here. If you're still having issues, I can help you get started with just AHK++ and not Zero-Plus's extension. AHK++ supports basic debugging scenarios and should serve as a good transition from MsgBox for sure :)

You're welcome to open a discussion on the GitHub page where I'm a bit more active!

gaberiel__2
Posts: 14
Joined: 18 Jan 2023, 14:18

Re: Help with setting up debugging environment in VSCode please

Post by gaberiel__2 » 01 Apr 2023, 10:48

swagfag wrote:
This was perfect Thanks allot!

gaberiel__2
Posts: 14
Joined: 18 Jan 2023, 14:18

Re: Help with setting up debugging environment in VSCode please

Post by gaberiel__2 » 01 Apr 2023, 10:50

markwiemer wrote:
I did not know of this, very kind of you mark, I will take a look at your program then. Much appreciated

Post Reply

Return to “Visual Studio Code”