new vscode extension allows advanced AHK V1/V2 debugging

Scripting and setups with Visual Studio Code (vscode) and AutoHotkey.
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

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

10 Apr 2021, 16:18

SAbboushi wrote:
19 Jun 2020, 10:22
Some screen shots:
vscodeAHKV2.pngvscodeAHKV2_folders.png
How do you get the side panels to show?

Also how might I collapse all brackets in my script?

I have a lot of:

{
gui, add
...
...
..
}

and i like to keep all of these collapsed but none of the commands for vscode seem to collapse any non function/label brackets

oh... and how do we get the output/debug console to show? I have a bunch of fileappends everywhere to use the stdout but nothing shows in vscode
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

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

10 Apr 2021, 17:28

doubledave22 wrote: How do you get the side panels to show?
Click on the icons on the side of the window. They are typically on the left side of the window, but they are on they are on the right side in SAbboushi's screenshot (setting was obviously changed).

doubledave22 wrote: Also how might I collapse all brackets in my script?
Use the shortcut Ctrl+K followed by Ctrol+0 (that's the number 0, not the letter O). Then you can expand them with Ctrl+K followed by Ctrol+J. Here is a VS Code keyboard shortcut reference.

doubledave22 wrote: oh... and how do we get the output/debug console to show? I have a bunch of fileappends everywhere to use the stdout but nothing shows in vscode
Under the View menu, select Output, or press Ctrl+Shift+U (as seen on the menu item and on the keyboard shortcut reference). If you want to use the debug console, you need to have an extension with a debugger for AHK installed. AutoHotkey Plus by cweijan might be the only one that provides that capability.
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

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

10 Apr 2021, 20:07

boiler wrote: If you want to use the debug console, you need to have an extension with a debugger for AHK installed. AutoHotkey Plus by cweijan might be the only one that provides that capability.
If you look at my original post, I started this thread to highlight vscode-autohotkey-debug which offers some cool features related to Debug Console. I've identified some already in this thread; read the extension's documentation for the rest.
Last edited by SAbboushi on 10 Apr 2021, 21:09, edited 1 time in total.
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

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

10 Apr 2021, 20:32

SAbboushi wrote:
10 Apr 2021, 20:07
If you look at my original post, I started this thread to highlight vscode-autohotkey-debug which offers some cool features related to Debug Console. I've identified some already in this thread; read the extension's documentation for the rest.
Yes, sorry. I neglected to look at the context of the thread and forgot about this extension since I’ve been using the one I mentioned.

Btw, you might want to edit your post above as you’ve mistakenly attributed text from my post to doubledave22. I wouldn’t wish defending my words on anyone. It’s bad enough I have to do it. :D
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

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

10 Apr 2021, 21:10

boiler wrote:
10 Apr 2021, 20:32
Btw, you might want to edit your post above as you’ve mistakenly attributed text from my post to doubledave22.
Oops! Done - thanks
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

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

11 Apr 2021, 13:31

boiler wrote:
10 Apr 2021, 17:28
Click on the icons on the side of the window. They are typically on the left side of the window, but they are on they are on the right side in SAbboushi's screenshot (setting was obviously changed).
Thanks! I got it looking the same. I think on the right feels a bit nicer.
boiler wrote:
10 Apr 2021, 17:28
Use the shortcut Ctrl+K followed by Ctrol+0 (that's the number 0, not the letter O). Then you can expand them with Ctrl+K followed by Ctrol+J. Here is a VS Code keyboard shortcut reference.
So the issue here is unless the { is followed by some indentation in the code below, vscode wont allow the brackets to collapse. I can throw in a bunch of indentation I suppose.

Example:


* cant be collapsed *
{
gui,add, text ...
gui,add, text ...
gui,add, text ...
}


* can collapse *
{
( tab ) gui,add, text ...
( tab ) gui,add, text ...
( tab ) gui,add, text ...
}

If you know a trick here let me know.
boiler wrote:
10 Apr 2021, 17:28
Under the View menu, select Output, or press Ctrl+Shift+U (as seen on the menu item and on the keyboard shortcut reference). If you want to use the debug console, you need to have an extension with a debugger for AHK installed. AutoHotkey Plus by cweijan might be the only one that provides that capability.
Problem for me was I wasnt running vscode as admin. I have a runas command in script to elevate and I think this always causes stdout issues.
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

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

11 Apr 2021, 14:07

doubledave22 wrote:
11 Apr 2021, 13:31
So the issue here is unless the { is followed by some indentation in the code below, vscode wont allow the brackets to collapse. I can throw in a bunch of indentation I suppose.
I don’t know a way around that. It appears the only options are by indenting, by language-specific folding rules, or based on comments you would have to insert to define code-folding regions. None of those are really helpful to you for this issue. Perhaps you could write your own language extension that would define folding regions the way you’d like, but I doubt that’s something you’re looking to take on.

You might find you come to like the indentation if you decide to add it. I find it really helps me follow the logic of my code.
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

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

11 Apr 2021, 17:46

@doubledave22 & @boiler Don't know if this is what you're looking for - the extension vscode-autohotkey-plus-plus provides the ability to create folding blocks of code and collapsing block comments without the need for indentation.

Code: Select all

;region
These tags will create a
folding region of code
that doesn't require
indentation
;endregion

Code: Select all

/* ;region
Prefixing with /* and */
will create a folding
block comment
*/ ;endregion
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

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

11 Apr 2021, 19:00

@fade2gray - Yes, that approach should work with any extension for AHK that properly identifies comments, as it does with the one I use called AutoHotkey Plus, which AutoHotkey Plus Plus was forked from. That’s one of the available approaches to code folding I mentioned that I didn’t expect to be very useful to @doubledave22 in the cases he was asking about because then his example would have to look like this:

Code: Select all

{ ; region
gui,add, text ...
gui,add, text ...
gui,add, text ...
} ; endregion
...but maybe he would find that to be acceptable. He could even use hotkeys or hotstrings to automatically expand { to { ; region and } to } ; endregion, so maybe that’s not so bad.
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

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

12 Apr 2021, 10:53

I ended up just indenting... didnt take long.

I am so happy i found this thread. I really wanted to use vscode and now I can :D:D:D

I have my console, all the closing/opening bracket hotkeys i could even dream of, I updated the scroll speed and added "bookmarks" extension. I will finally be able to step through code and be able to view objects without specific console calls. This is awesome thanks guys!
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

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

12 Apr 2021, 11:29

This would be the correct method for a folding region (without the brackets if not required).

FoldingRegion.png
FoldingRegion.png (2.85 KiB) Viewed 8381 times

...but if inserting multiple indents is preferred, using Shift+Ctrl+Alt with up/down arrow keys to create multiple cursors (column mode) might help.
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

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

12 Apr 2021, 12:17

Actually, it works the way I showed it as well, and I purposely chose that way to show it because it doesn’t add extra lines (assuming he wanted the braces for code reasons, which sounded like it was the case).

You can create multiple indents simply by highlighting multiple lines and pressing the Tab key.
DaveT1
Posts: 218
Joined: 07 Oct 2014, 11:23

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

13 Apr 2021, 04:10

...I found the same 'problem' - ie., I use alot of zero-indented {}s to group sections of code together. After much digging and :headwall: I found somewhere a statement that Vscode doesn't do folding on zero-indents, but will on indented braces (as has been pointed out).

This really ticked me off - so much goodness in vscode, but this drawback.

But, FYI, I use this extension: AutoHotkey Plus by cweijan. If you look in C:\Users\Dave\.vscode\extensions\cweijan.vscode-autohotkey-plus-2.6.2 and open the file ahk.configuration.json you can edit the text which marks the "regions" alluded above. So, for me, the end of this file looks like:

Code: Select all

    // Folding regions marked by ";region" and ";endregion" comments.
    "folding": {
      "markers": {
          "start": "\\s*\\;\\s*Region\\b",
          "end": "\\s*\\;\\s*endRegion\\b"
      }
    },
    // Changed folding regions. These only apply to zero indent lines, as folding applies to indented lines.
    "folding": {
      "markers": {
          "start": "\\s*\\;\\s*sReg\\b",
          "end": "\\s*\\;\\s*eReg\\b"
      }
    }
}
where the second definition seems to trump the first. So for me a grouping of code using zero-indented braces looks like:

Code: Select all

{ ;sReg
...some code...
} ;eReg
I'd love to understand more about how to get this flexibility without going the whole hog and learning (and probably failing!) to write my own extensions. Better still to get vscode to have some built-in way of folding zero-indented {}s. Of course, if there were an update to AutoHotkey Plus I'd lose this hack - so I'll figure out how to keep a copy in case!

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

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

13 Apr 2021, 06:37

@DaveT1 The regular expressions \\s*\\;\\s*Region\\b and \\s*\\;\\s*endRegion\\b are, for all intents and purposes, 'identical' to \\s*\\;\\s*sReg\\b and \\s*\\;\\s*eReg\\b, the only difference being the 'names' of the tags have been changed.

if you to change them to...

Code: Select all

"folding": {
    "markers": {
        "start": "(\\/\\*)?\\s*\\;\\s*sReg\\b",
        "end": "(\\*\\/)?\\s*\\;\\s*eReg\\b"
    }
}
...this would also allow you to create folding block comments.

Code: Select all

/* ; sReg
block
comment
*/ ; eReg
User avatar
fade2gray
Posts: 85
Joined: 21 Apr 2015, 12:28

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

13 Apr 2021, 06:42

boiler wrote:
12 Apr 2021, 12:17
You can create multiple indents simply by highlighting multiple lines and pressing the Tab key.
Well, I never... 👍
DaveT1
Posts: 218
Joined: 07 Oct 2014, 11:23

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

13 Apr 2021, 11:57

fade2gray wrote:
13 Apr 2021, 06:37
@DaveT1 The regular expressions \\s*\\;\\s*Region\\b and \\s*\\;\\s*endRegion\\b are, for all intents and purposes, 'identical' to \\s*\\;\\s*sReg\\b and \\s*\\;\\s*eReg\\b, the only difference being the 'names' of the tags have been changed.
Yup, I got that by trial and error! By you naming them as RegExs, you're demonstrating you know far more than me about these things :thumbup: .
if you to change them to...

Code: Select all

"folding": {
    "markers": {
        "start": "(\\/\\*)?\\s*\\;\\s*sReg\\b",
        "end": "(\\*\\/)?\\s*\\;\\s*eReg\\b"
    }
}
...this would also allow you to create folding block comments.
Ah, that's interesting. I tend to use many fewer block comments, but not none. I need to check those I have! What would be really worthwhile is to know whether the block tag names can be used in addition to the non-indented brace-folding? In other words could I add this code to the end of the ahk.configuration.json file and have both non-zero-indented-braces and the block-code-folding?
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

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

03 May 2021, 13:23

SAbboushi wrote:
19 Jun 2020, 10:17
Sweet!

Can easily run/debug (concurrently) multiple AHK versions (e.g. a108, a111...) with scripts associated with those versions (e.g. LibV2, LibV2_a108). I'm finding that very useful when I need to update scripts to make them compatible with new V2 updates like v2.0-a111-06d0a13b that has "numerous compatibility-breaking changes".

And I'm loving being able to code/debug in vscode. Although I much prefer the syntax highlighting I've got in SciTE4AutoHotkey...
SciTE4AutoHotkey.png

dudelmoser.png
That first one looks like Plastic Code Wrap. I haven't ported it VScode but it looks like someone already has! Looks pretty good to me! :+1:
https://marketplace.visualstudio.com/items?itemName=thunderblaster.theme-plasticcodewrap
Screenshot 2021-05-03 142241.png
Screenshot 2021-05-03 142241.png (452.22 KiB) Viewed 8111 times
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
DaveT1
Posts: 218
Joined: 07 Oct 2014, 11:23

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

26 Nov 2021, 12:21

@zero-plusplus / @SAbboushi - I'm wondering if I could ask you for some advice on setting up this extension?

I'm currently using AutoHotKey2 Language Support by thqby. It's extension settings point to vscode-autohotkey-debug by zero-plusplus and this extension is also installed.

But all the running and debugging of scripts seems to use AHKv1. I've found this on the vscode-autohotkey-debug repo:
This extension will work without configuration as long as you follow the steps above.
Presumably this means that it will run and debug scripts with AHKv1?
However, if you want to use a different version of AutoHotkey for which no installer is provided, you will need to configure it separately.

By default, the runtime is configured for each file extension as shown below, so please place the runtime in the same path.

ahk - C:/Program Files/AutoHotkey/AutoHotkey.exe
ahk2 or ah2 - C:/Program Files/AutoHotkey/v2/AutoHotkey.exe

If you want to place the runtime in a specified folder, you need to set the runtime attribute in launch.json.
I assume that this is what I need to do to get AHKv2 run with the vscode-autohotkey-debug extension? But I'm afraid that I don't understand what this is asking me to do - apologies for this - I've just switched to vscode and don't understand how to work with vscode extensions.

Also, I think I saw @SAbboushi that you use .ahk as your file extension for both AHKv1 and AHKv2 files? This is great and exactly what I want to do. But the advice quoted above seems to suggest that for AHKv2 we need .ahk2 or .ah2 file extensions?

Hope you don't mind the noob questions.
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

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

26 Nov 2021, 23:47

@DaveT1 I use that combination of extensions. I found it necessary to set "runtime_v2" in launch.json to the path of the desired AutoHotkey.exe. It is also possible to add multiple launch configurations which use different exe files.
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

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

28 Nov 2021, 11:12

@DaveT1

Instead of launch.json, I use Workspaces (specifically, Multi-Root Workspaces).

I'm really buried right now and wish I could be more helpful; for now, I've attached some of my notes with screenshots from non-current versions of vscode and vscode-autohotkey-debug (i.e. screenshots may not exactly match). Hopefully that will give you options to consider/research.

[The extension pdf has been deactivated and can no longer be displayed.]


Return to “Visual Studio Code”

Who is online

Users browsing this forum: No registered users and 4 guests