Improde ahk error window

Propose new features and changes
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Improde ahk error window

Post by AHK_user » 31 Mar 2023, 16:51

As a lot of V2 users use VS code, It would be very helpfull if the Edit button on the Warning message would check if code.exe is open to do an action to go to the line of the error.

In vs code, you can go to the line by:
Sendinput("^p")
Sendinput( filepath ":" linenumber "{Enter}")

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Improde ahk error window

Post by AHK_user » 31 Mar 2023, 17:06

Correction, this is cleaner:

Run(A_ComSpec ' /c "Code --goto "' filepath ':' linenumber '"" ',,"Hide")

neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: Improde ahk error window

Post by neogna2 » 02 Apr 2023, 06:39

The edit button executes the "edit" verb. You can modify its effect in the registry. see this post with notes on such a change plus a script to jump to the error line in Notepad++.
viewtopic.php?p=490440#p490440
You can customize it to use VS Code instead.

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Improde ahk error window

Post by AHK_user » 03 Apr 2023, 14:22

neogna2 wrote:
02 Apr 2023, 06:39
The edit button executes the "edit" verb. You can modify its effect in the registry. see this post with notes on such a change plus a script to jump to the error line in Notepad++.
viewtopic.php?p=490440#p490440
You can customize it to use VS Code instead.
@neogna2 Thanks for the tip, this was exactly what I was looking for. :dance: :dance: :dance:

Here is the version that works for VS code, in the comments is mentioned how to set the registry.
This is cool, even when you not run in debug mode, it is easy to jump to the file on the correct line.

I modified it a little bit so that it also keeps the normal Edit function.

Code: Select all

#SingleInstance Force
#Requires AutoHotkey v2.0

; Modify the registry:
; Computer\HKEY_CLASSES_ROOT\AutoHotkeyScript\shell\edit\command "<AutohotkeyDirectory>\AutoHotkey32.exe" "<DirectoryErrorEditVSC>\ErrorEditVSC.ahk" "%1"
; RegWrite Format('"{1}" "{2}" "%1"', A_AhkPath, A_ScriptFullPath), "REG_SZ", "HKCR\AutoHotkeyScript\Shell\Edit\Command"

if A_Args.Has(1)
  {
      ScriptFile := A_Args[1]

      SplitPath(ScriptFile, &Filename)
      ErrorHwnd := WinExist(Filename " ahk_class #32770")
      Try CtlText := ControlGetText("RichEdit20W1", "ahk_id " ErrorHwnd)
      if IsSet(CtlText){
        if RegExMatch(CtlText, "\R▶\t(\d+):", &oMatch) or RegExMatch(CtlText, "\RLine:\t(\d+)\R", &oMatch)
        {
          Line := LTrim(oMatch.1, "0")
          ;edit next line with preferred text editor path and cli goto line syntax
          ;   Run('notepad++.exe "' ScriptFile '" -n' Line)
          Run(A_ComSpec ' /c "Code --goto "' ScriptFile ':' Line '"" ',,"Hide")
          ExitApp
        }
      }
      Run( '"' StrReplace(A_AppData,"Roaming","") 'Local\Programs\Microsoft VS Code\Code.exe" '  '"' ScriptFile '"')
      ExitApp
  }
  Run( '"' StrReplace(A_AppData,"Roaming","") 'Local\Programs\Microsoft VS Code\Code.exe"')
  ExitApp

neogna2
Posts: 591
Joined: 15 Sep 2016, 15:44

Re: Improde ahk error window

Post by neogna2 » 03 Apr 2023, 16:25

Nice improvements!

Post Reply

Return to “Wish List”