loganch / AutoIt-VSCode

AutoIt Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=Damien.autoit
MIT License
74 stars 25 forks source link

Separate output for each running script #99

Closed vanowm closed 2 years ago

vanowm commented 2 years ago
vanowm commented 2 years ago

When multiple scripts are running, CTRL+Break will kill one running script per press in reverse order they were launched.

I was thinking about making it only stop scripts that run from currently active document, however first forced stop seems to be done by Autoit itself, not killScript() function? Like it's registering global CTRL+Break hotkey...

vanowm commented 2 years ago

In f975734 restartScript() and killScript() only kill currently focused in the editor script, however if killScript is mapped to CTRL+Break, then first hotkey press will kill first launched script, regardless which script is currently focused in the editor. This is due to CTRL+Break and CTRL+ALT+Break are hardcoded into Autoit3Wrapper

TODO:

vanowm commented 2 years ago

In 3911f7b killScript reverted to original behaviour: it kills last running script regardless which editor is in focus. Added new killScriptOpened command which kills only running scripts from currently opened editor.

By default, Autoit3Wrapper.au3 registers its own hotkey CTRL+Break and CTRL+ALT+Break, because of that killScript and killScriptOpened might now work properly, so far the only solution I could find is to create Autoit3Wrapper.ini file next to Autoit3Wrapper.au3 and add to it:

[Other]
SciTE_STOPEXECUTE=
SciTE_RESTART=

This will prevent Autoit3Wrapper.au3 from registering hotkeys, however it will also affect when script launched from SciTE

vanowm commented 2 years ago

https://github.com/loganch/AutoIt-VSCode/pull/99/commits/09c99f62d393b82054f6c5b910f0fd927bd2def6 Fixed Autoit3Wrapper.au3 hotkeys issue

Danp2 commented 2 years ago

I get the following error when AutoIt3Wrapper.ini doesn't exist and I attempt to run a script with F5 --

Error: ENOENT: no such file or directory, open 'C:\Users\danpo\AppData\Local\AutoIt v3\SciTE/AutoIt3Wrapper/AutoIt3Wrapper.ini'
    at Object.openSync (node:fs:585:3)
    at Object.func [as openSync] (node:electron/js2c/asar_bundle:5:1812)
    at Object.readFileSync (node:fs:453:35)
    at Object.readFileSync (node:electron/js2c/asar_bundle:5:9160)
    at fileData (c:\Users\danpo\OneDrive\Documents\GitHub\AutoIt-VSCode\dist\extension.js:100:67)
    at Object.disable (c:\Users\danpo\OneDrive\Documents\GitHub\AutoIt-VSCode\dist\extension.js:137:23)
    at procRunner (c:\Users\danpo\OneDrive\Documents\GitHub\AutoIt-VSCode\dist\extension.js:380:18)
    at runScript (c:\Users\danpo\OneDrive\Documents\GitHub\AutoIt-VSCode\dist\extension.js:443:5)
    at o._executeContributedCommand (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:62521)
    at o.$executeContributedCommand (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:63225)
    at s._doInvokeHandler (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:86:13828)
    at s._invokeHandler (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:86:13512)
    at s._receiveRequest (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:86:12173)
    at s._receiveOneMessage (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:86:10843)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:86:8949
    at g.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:58:145)
    at b.deliver (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:58:2265)
    at v.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:58:1843)
    at a.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:66:19025)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:102:34863
    at g.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:58:145)
    at b.deliver (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:58:2265)
    at v.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:58:1843)
    at a.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:66:19025)
    at r._receiveMessage (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:66:23606)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:66:21140
    at g.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:58:145)
    at b.deliver (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:58:2265)
    at v.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:58:1843)
    at v.acceptChunk (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:66:15856)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:66:14986
    at Socket.R (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:102:13798)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:199:23)
    at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) {errno: -4058, syscall: 'open', code: 'ENOENT', path: 'C:\Users\danpo\AppData\Local\AutoIt v3\SciTE/AutoIt3Wrapper/AutoIt3Wrapper.ini', stack: 'Error: ENOENT: no such file or directory, ope…Trampoline (node:internal/async_hooks:130:17)', …}
vanowm commented 2 years ago

only in the debug console? I left console.log in the try-catch for some reason .

Danp2 commented 2 years ago

No. The following error is displayed and the script doesn't execute.

The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined

vanowm commented 2 years ago

Fixed. Thanks for testing.

vanowm commented 2 years ago

Colors based on https://www.autoitscript.com/forum/topic/125490-does-anyone-know-how-to-customize-the-scite-output-color-scheme/

loganch commented 2 years ago

This is pretty cool!

I'm seeing an issue where the outputs created weren't closing in the right order. Granted, one of the scripts (IncludeTestter.au3/#1/#3/#5) I ran to test it was a loop with message boxes to see what happens if it starts before another script and closes after it. Here's the output from the AutoIt channel:

#1: Starting process #1
    "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "c:\dev\AutoItIncludeTest\TryingNewOutput.au3" [PID 24768]
    +>18:34:14 Starting AutoIt3Wrapper (21.316.1639.1) from:Code.exe (1.69.2.0)  Keyboard:00000409  OS:WIN_10/2009  CPU:X64 OS:X64  Environment(Language:0409)
    >Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:c:\dev\AutoItIncludeTest\TryingNewOutput.au3
    "c:\dev\AutoItIncludeTest\TryingNewOutput.au3"(38,11) : warning: $iErr: possibly used before declaration.
        If $iErr Then
        ~~~~~~~~~^
    "c:\dev\AutoItIncludeTest\TryingNewOutput.au3"(38,11) : error: $iErr: undeclared global variable.
        If $iErr Then
        ~~~~~~~~~^
    c:\dev\AutoItIncludeTest\TryingNewOutput.au3 - 1 error(s), 1 warning(s)
    !>18:34:14 AU3Check ended.rc:2
    +>18:34:14 AutoIt3Wrapper Finished.
    !>Exit code 2 Time: 0.565
#2: Starting process #2
    "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "c:\dev\AutoItIncludeTest\TryingNewOutput.au3" [PID 2608]
    +>18:34:26 Starting AutoIt3Wrapper (21.316.1639.1) from:Code.exe (1.69.2.0)  Keyboard:00000409  OS:WIN_10/2009  CPU:X64 OS:X64  Environment(Language:0409)
    >Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:c:\dev\AutoItIncludeTest\TryingNewOutput.au3
    +>18:34:26 AU3Check ended.rc:0
    >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "c:\dev\AutoItIncludeTest\TryingNewOutput.au3"  /errorstdout
    False--> SetHotKey Restart failed, SetHotKey Stop failed.
    @@ Debug(17) : $sTest = Test
    >Error code: 0
    Blah
    ! Red (Error)?
    - Orange (Debug)?
    > Blue (Running)
    @@ Debug(1) :
    @@ Debug(11) : Testtest??????test
    ! Red
    - Orange
    > = 1
#3: Starting process #3
    "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "c:\dev\AutoItIncludeTest\IncludeTester.au3" [PID 15276]
    +>18:34:36 Starting AutoIt3Wrapper (21.316.1639.1) from:Code.exe (1.69.2.0)  Keyboard:00000409  OS:WIN_10/2009  CPU:X64 OS:X64  Environment(Language:0409)
    >Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:c:\dev\AutoItIncludeTest\IncludeTester.au3
    +>18:34:36 AU3Check ended.rc:0
    >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "c:\dev\AutoItIncludeTest\IncludeTester.au3"  /errorstdout
    False@@ Debug(17) : $sTest = Test
    >Error code: 0
    Blah
    ! Red (Error)?
    - Orange (Debug)?
    > Blue (Running)
    @@ Debug(1) :
    +>18:34:36 AutoIt3.exe ended.rc:0
    +>18:34:36 AutoIt3Wrapper Finished.
    >>Exit code 0 Time: 0.339
#4: Starting process #4
    "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "c:\dev\AutoItIncludeTest\IncludeTester.au3" [PID 11212]
    +>18:36:13 Starting AutoIt3Wrapper (21.316.1639.1) from:Code.exe (1.69.2.0)  Keyboard:00000409  OS:WIN_10/2009  CPU:X64 OS:X64  Environment(Language:0409)
    >Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:c:\dev\AutoItIncludeTest\IncludeTester.au3
    +>18:36:13 AU3Check ended.rc:0
    >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "c:\dev\AutoItIncludeTest\IncludeTester.au3"  /errorstdout
    False@@ Debug(17) : $sTest = Test
    >Error code: 0
    Blah
    ! Red (Error)?
    - Orange (Debug)?
    > Blue (Running)
    @@ Debug(1) :
    +>18:36:13 AutoIt3.exe ended.rc:0
    +>18:36:13 AutoIt3Wrapper Finished.
    >>Exit code 0 Time: 0.358
#2: +>18:37:37 AutoIt3.exe ended.rc:0
    +>18:37:37 AutoIt3Wrapper Finished.
    >>Exit code 0 Time: 190.776
#5: Starting process #5
    "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "c:\dev\AutoItIncludeTest\TryingNewOutput.au3" [PID 20336]
    +>18:38:10 Starting AutoIt3Wrapper (21.316.1639.1) from:Code.exe (1.69.2.0)  Keyboard:00000409  OS:WIN_10/2009  CPU:X64 OS:X64  Environment(Language:0409)
    >Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:c:\dev\AutoItIncludeTest\TryingNewOutput.au3
    +>18:38:10 AU3Check ended.rc:0
    >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "c:\dev\AutoItIncludeTest\TryingNewOutput.au3"  /errorstdout
    False@@ Debug(17) : $sTest = Test
    >Error code: 0
    Blah
    ! Red (Error)?
    - Orange (Debug)?
    > Blue (Running)
    @@ Debug(1) :
    @@ Debug(11) : Testtest??????test
    ! Red
    - Orange
    > = 1
    + 1
    + 2
    + 3
    +>18:38:32 AutoIt3.exe ended.rc:0
    +>18:38:32 AutoIt3Wrapper Finished.
    >>Exit code 0 Time: 21.632

And here are the output channels that still exist:

image
vanowm commented 2 years ago

@loganch It's by design. cleaning up process sorts scripts by finished date not by started date. So in your case #2 and #5 scripts finished last.

loganch commented 2 years ago

Oh, did I not give it enough time for #2 and #5 to close out?

vanowm commented 2 years ago

It depends on autoit.multiOutputFinishedTimeout setting. If it's set to 0 (default), then these outputs won't automatically close