new vscode extension allows advanced AHK V1/V2 debugging

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

Re: new vscode extension allows advanced AHK V1/V2 debugging

Post by DaveT1 » 29 Nov 2021, 14:33

Lexikos and Sabboushi, thanks so much for getting back.

Thus far I've understood better what a workspace is, now have a .vscode folder in my workspace root folder, have a launch.json file and have figured out how to add a multiple configurations to it! So far so good. My launch.json file looks like:

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": [
      {
         "name": "AutoHotkey v1 Debug",
         "type": "autohotkey",
         "request": "launch",
         "runtime": "D:/AutoHotKey/ahk-pi-master/versions/AutoHotkey_1.1.33.10/AutoHotkeyU64.exe",
         "program": "${file}",
         "args": []
      },
      {
         "name": "AutoHotkey v2 Debug",
         "type": "autohotkey",
         "request": "launch",
         "runtime": "D:/AutoHotKey/ahk-pi-master/versions/AutoHotkey_2.0-beta.3/AutoHotkey64.exe",
         "program": "${file}",
         "args": []
      },
      {
         "type": "pwa-node",
         "request": "launch",
         "name": "Launch Program",
         "skipFiles": [
            "<node_internals>/**"
         ],
         "program": "${file}"
      }
   ]
}
But, when i run / debug this simple script with (either the v1 or v2 configuration selected in the vscode configuration):

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2 ;this allows comparison of substrings of Window Titles, rather than the full text.
#SingleInstance force ; This suppresses the warning dialogue that a newly launched script is already running.
DetectHiddenWindows On

MsgBox "hello world"
MsgBox, Current version of AHK = %A_AhkPath%\%A_AhkVersion%

ExitApp
The message box always reports:
image.png
image.png (3.16 KiB) Viewed 5688 times

In other words I don't seem to have the right syntax in the launch.json file to point to the version of autohotkey.exe I want to use to debug!

Hopefully someone can point out where I've gone wrong!

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

Re: new vscode extension allows advanced AHK V1/V2 debugging

Post by DaveT1 » 01 Dec 2021, 04:05

Right, I've made a little more progress. By fiddling at random :roll: I've discovered:
  • By changing "name" in the launch.json file:

    Code: Select all

     "configurations": [
          {
             "name": "AHK v1 Dbg",
             ...
    this updates immediately in vscode. So obviously vscode is 'seeing' the launch.json file.
  • However, no amount of changes to the "runtime" setting:

    Code: Select all

    "configurations": [
          {
             "name": "AHK v1 Dbg",
             "type": "autohotkey",
             "request": "launch",
             "runtime": "D:/AutoHotKey/ahk-pi-master/versions/AutoHotkey_1.1.33.10/AutoHotkeyU64.exe",
             ...
    makes run/debug see anything other than "C:\Program Files\AutoHotkey\AutoHotkey.exe".
  • However, by altering the settings of the extension AutoHotKey2 Language Support by @thqby I seem to be able to 'force' things to work. The last extension setting is:
    image.png
    image.png (10.53 KiB) Viewed 5637 times
    The target path is editable, so if I change this to, for example: D:/AutoHotKey/ahk-pi-master/versions/AutoHotkey_1.1.33.10/AutoHotkeyU64.exe, then the run/debugger sees this different version of AHK to use. And if I change it to D:/AutoHotKey/ahk-pi-master/versions/AutoHotkey_2.0-beta.3/AutoHotkey64.exe then it will run AHKv2! So I seem to have a way to 'force' this combination of extensions to do what i want.
Ultimately though, this doesn't seem to be the intended way. But it at least gets me going. And now I know, I can manually switch between AHKv1 and AHKv2 by changing the extension settings.

In the meantime if anyone can spot why runtime in my launch.json file is not working as expected, I'd very gratefully receive that help.

lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: new vscode extension allows advanced AHK V1/V2 debugging

Post by lexikos » 01 Dec 2021, 04:11

lexikos wrote:
26 Nov 2021, 23:47
@DaveT1 ... I found it necessary to set "runtime_v2" in launch.json
I don't know how the extension decides whether to use "runtime" or "runtime_v2", but it is definitely not by filename extension. I use ".ahk" exclusively.

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

Re: new vscode extension allows advanced AHK V1/V2 debugging

Post by DaveT1 » 01 Dec 2021, 05:53

Thanks Lexikos.
lexikos wrote:
01 Dec 2021, 04:11
lexikos wrote:
26 Nov 2021, 23:47
@DaveT1 ... I found it necessary to set "runtime_v2" in launch.json
I don't know how the extension decides whether to use "runtime" or "runtime_v2", but it is definitely not by filename extension. I use ".ahk" exclusively.
Agreed - I too use ".ahk" for both v1 and v2.

By 'extension' in my previous post I was referring to the extensions that vscode uses to add extra functionality, not file extensions. Sorry for any confusion.

User avatar
thqby
Posts: 398
Joined: 16 Apr 2021, 11:18
Contact:

Re: new vscode extension allows advanced AHK V1/V2 debugging

Post by thqby » 01 Dec 2021, 06:13

For debugging started through AutoHotKey2 Language Support, the setting item Interpreter path will overwrite the configuration of the debugging plug-in.

You can also switch the debugging interpreter in the lower left corner.
image.png
image.png (6.71 KiB) Viewed 5560 times

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

Re: new vscode extension allows advanced AHK V1/V2 debugging

Post by DaveT1 » 01 Dec 2021, 07:47

Thanks so much for helping - as you can see I'm struggling with vscode!
thqby wrote:
01 Dec 2021, 06:13
For debugging started through AutoHotKey2 Language Support, the setting item Interpreter path will overwrite the configuration of the debugging plug-in.
Is the "debugging plug-in" you mention above the same as the Auto Hotkey2: Default Debugger in your extension settings?
But even if Auto Hotkey2: Default Debugger and Interpreter path are left as the default values for your extension, there is still no way to get different versions of AHK to be used via the launch.json file. @SAbboushi seems to show that this should be possible via launch.json. :?
You can also switch the debugging interpreter in the lower left corner.
image.png
Err, this is grade 1 gold-dust :thumbup: How strightforward is that! Still better to do it through launch.json, but this is an even better work-around.

Thank you for those thoughts.

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

Re: new vscode extension allows advanced AHK V1/V2 debugging

Post by DaveT1 » 01 Dec 2021, 08:32

Right, I think I may understand what's going on. Explained here in case I'm wrong / it's helpful to anyone else:

1. When using the AutoHotKey2 Language Support extension by thqby, the extension settings define which interpreter is used when Run script and Debug script are selected from the context menu. This extension adds these items to the context menu.

however,

2. When using Start debugging and Run without debugging from vscode's Run menu, it uses the interpreter selected from the launch.json file!

So my mistake was not seeing that "AutoHotKey2 Language Support"'s context menu and "vscode"'s Run menu behave differently.

Many thanks for all the help - really appreciated.

User avatar
kdaube
Posts: 86
Joined: 02 Nov 2015, 03:11

How to step through a script?

Post by kdaube » 19 Feb 2022, 07:47

Dear all,
I'm trying to get familier with AHK debugging using this new extension:
Name: vscode-autohotkey-debug
Id: zero-plusplus.vscode-autohotkey-debug
Description: Advanced debugging support for AutoHotkey(includes H) v1 and v2
Version: 1.11.0
Publisher: zero-plusplus
My test sript runs (by measn of F5), but for debugging - ans view of the variables - I would like to be able to step through statements. These options however are greyed out:
Image

→ How to achieve stepping?

When I start debugging with the trianle in the editor title row, I get the message "command 'ahk++.debug' not found"
→ Where do I need to define what? in launch.json I have only this:

Code: Select all

{
    "name": "AHK Debug",
    "type": "autohotkey",
    "request": "launch",
    "program": "${file}",
    "args": []
  },
Klaus Daube, Zürich, CH

User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

Re: new vscode extension allows advanced AHK V1/V2 debugging

Post by fade2gray » 19 Feb 2022, 09:55

You could try asking in the extension's GitHub repository.

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

Re: How to step through a script?

Post by DaveT1 » 29 Aug 2022, 13:20

kdaube wrote:
19 Feb 2022, 07:47

→ How to achieve stepping?
I'm no expert - so sorry to ask the obvious but did you set any breakpoints in the code before starting the debugger?

I use that extension, but also this extension: AutoHotkey v2 Language Support by thqby. The latter allows you to specify v1 interpreter and, in a v2 subfolder to the v1 interpreter folder, you can put your v2 interpreter. I think :? that the debugger settings for the thqby extension take precedence over the zero-plusplus.vscode-autohotkey-debug extension.

Note that with these two extensions enabled, the Start debugging and Run without debugging in vscode's Run menu use the v2 interpreter, whilst Run Script and Debug Script in the context menu runs the v1 interpreter. Hmm, note to self - I wonder if I actually need the zero-plusplus.vscode-autohotkey-debug extension?????

HTHs.

david8u8
Posts: 6
Joined: 03 Nov 2022, 10:43

Re: new vscode extension allows advanced AHK V1/V2 debugging

Post by david8u8 » 05 Nov 2022, 10:29

Following can do that, or press F5 to debug AHK in VsCode, work fine.

Code: Select all

// Global launch.json
"launch": {
    // 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": [
        {
            // 必须按F5或Ctrl+F5才能运行,否则报找不到运行环境的错误
            "name": "Debug AHK", // 配置名称
            "type": "ahk", // 配置类型,cppdbg对应cpptools提供的调试功能;可以认为此处只能是cppdbg
            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
            "runtime": "D:/Program Files/AutoHotkey/v2.0-beta.12/AutoHotkey64.exe",
            "program": "${fileDirname}/${fileBasenameNoExtension}.ahk", // 将要进行调试的程序的路径
            //"program": "${workspaceRoot}/main/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径
            "args": [], // 程序调试时传递给程序的命令行参数,这里设为空即可
            "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,相当于在main上打断点
            "cwd": "${workspaceFolder}", // 调试程序时的工作目录,此处为源码文件所在目录,${workspaceRoot}
            "environment": [], // 环境变量,这里设为空即可
            "externalConsole": false, // 为true时使用单独的cmd窗口,跳出小黑框;设为false则是用vscode的内置终端,建议用内置终端
            "internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,新手调试用不到
            "MIMode": "ahk", // 指定连接的调试器,gdb是minGW中的调试程序
            "miDebuggerPath": "D:/Program Files/AutoHotkey/v2.0-beta.12/AutoHotkey64.exe", // 指定调试器所在路径,绝对路径
            // "preLaunchTask": "cppBuild", // 调试开始前执行的任务,我们在调试前要编译构建。与tasks.json的label相对应,名字要一样
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb", // 为gdb启用整齐打印
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
},

Post Reply

Return to “Visual Studio Code”