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

Project aware #213

Open vanowm opened 7 months ago

vanowm commented 7 months ago

I'm trying to simplify my script by splitting it into multiple files. Each file may access global variables/function from other files. For example, main.au3 file:

Global $myVar = "foo"
#include "secondary.au3"

secondary.au3:

ConsoleWrite($myVar)

The code works fine when main.au3 executed, but when I edit secondary.au3 vscode complains that $myVar is not declared.

What could we do about this?

Possible solutions:

Sven-Seyfert commented 7 months ago

Hi @vanowm,

I am confronted with such behavior all the time, because my projects often consists of different folders where the code is separated. As I remenber correctly, we had such requirement few years ago here in the project. I thought it was fixed at a certain time, but then the issue appeared again.

It would be wonderful if you or the other maintainers here see a good solution for it 🤗 .


Only as a show-case: example-project-structure

grafik

I decide which file needs to have access (#include) to a specific file (to the functions inside the file). So I can avoid issues with global variables for example.


Besides the situation of the warnings, it's also not possible to "jump to function definition" in case of such structure. Which makes me crazy sometimes. But to be honest, I am not able to extend the VSCode extension by a proper handling of this.

Best regards Sven (SOLVE-SMART)

Comemhome commented 6 months ago

You can do like this. Always save both files before editing

In Main.au3 :

#include-once
Global $MainVar = "This is $MainVar"
#include "secondary.au3"

Func FuncOfMain()
    ConsoleWrite("This is FuncOfMain" & @CRLF )
EndFunc

Func InMain_ShowVarOfSecondary()
    ConsoleWrite($SecondaryVar & @CRLF )
EndFunc

Func InMain_CallFuncOfSecondary()
    FuncOfSecondary()
EndFunc

In Secondary.au3 :

#include-once
Global $SecondaryVar = "This is $SecondaryVar"
#include "main.au3"

Func FuncOfSecondary()
    ConsoleWrite("This is FuncOfSecondary" & @CRLF )
EndFunc

Func InSecondary_ShowVarOfMain()
    ConsoleWrite($MainVar & @CRLF)
EndFunc

Func InSecondary_CallFuncOfMain()
    FuncOfMain()
EndFunc
loganch commented 2 months ago

The issue seems to be with Au3Check and its limitation of simply checking syntax and not running the scripts. I tried the syntax check in SciTE and got the same result.

SkyEmie commented 2 months ago

Hi all,

My workaround is this one:

pragma compile(Console, true)

pragma compile(Out, udCheck.exe)

consolewrite( runWaitStdout( '"C:\Program Files (x86)\AutoIt3\Au3Check.exe" D:\emie\dev\yetanotherprojekt\app\main.au3' ) )

func runWaitStdout($cmd) $process_pid = Run(@ComSpec &' /c ' & $cmd, @ScriptDir, @SW_HIDE, $STDERR_MERGED) processWaitClose($process_pid) return stdoutRead($process_pid) endfunc


- Then i modify the workspace config in vscode, changing the value "Check path" to point to my wrapper

![image](https://github.com/user-attachments/assets/edce0e5e-8fc2-401b-8eb4-2151f8a7f153)

Now in this workspace, no matter what file is open, au3check will be called with the "entrypoint" of the project