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

onDidChangeVisibleTextEditors runtime errors #180

Closed Danp2 closed 1 year ago

Danp2 commented 1 year ago

The changes made in https://github.com/loganch/AutoIt-VSCode/commit/2ab9aeb695cd79ba5b78da894dd397169a7819ff result in a runtime error --

2023-03-29 10:48:31.006 [error] TypeError: Cannot read properties of undefined (reading 'call')
    at f.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:145)
    at m.deliver (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:2066)
    at d.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:1704)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:98:153994
    at f.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:145)
    at m.deliver (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:2066)
    at d.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:1704)
    at m.acceptDocumentsAndEditorsDelta (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:98:13859)
    at m.$acceptDocumentsAndEditorsDelta (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:98:12249)
    at a.N (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:106:11223)
    at a.M (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:106:10941)
    at a.H (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:106:10034)
    at a.G (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:106:9015)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:106:7803
    at f.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:145)
    at m.deliver (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:2066)
    at d.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:1704)
    at p.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:72:14907)
    at c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:122:16556
    at f.invoke (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:145)
    at m.deliver (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:2066)
    at d.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:63:1704)
    at p.fire (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:72:14907)
    at MessagePortMain.<anonymous> (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:122:14682)
    at MessagePortMain.emit (node:events:526:28)
    at MessagePortMain._internalPort.emit (node:electron/js2c/utility_init:5:364)

Changing this line https://github.com/loganch/AutoIt-VSCode/blob/f5b762314df2f44a7d08730dab4dfd534bb8dea6/src/ai_commands.js#L165 to

window.onDidChangeVisibleTextEditors(() => { trimOutputLines() }); eliminates this error.

Two questions --

loganch commented 1 year ago

Hmmmm, for window.onDidChangeVisibleTextEditors, the first parameter is a listener, which means that VSCode expects the parameter to return a function for it to call when the event happens. Setting the parameter to be trimOutputLines() directly means that when the event happens, VSCode attempts to call undefined -- the "nothing" that trimOutputLines() is currently built to return.

vanowm commented 1 year ago

Ummm...trimOutputLines should be passed to window.onDidChangeVisibleTextEditors not executed...:

 window.onDidChangeVisibleTextEditors(trimOutputLines); 

No need for an extra wrapper.

loganch commented 1 year ago

Ah, so my inclusion of the parens was the mistake?

vanowm commented 1 year ago

Yes, you basically executed the function one time instead of letting window.onDidChangeVisibleTextEditors execute it each time output console changed.