Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project aware #213

Open
vanowm opened this issue Feb 11, 2024 · 4 comments
Open

Project aware #213

vanowm opened this issue Feb 11, 2024 · 4 comments

Comments

@vanowm
Copy link

vanowm commented Feb 11, 2024

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:

  • setting where we can specify "root" files
  • a comment inside included file with a name of the parent file
@sven-seyfert
Copy link

sven-seyfert commented Feb 11, 2024

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
Copy link

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
Copy link
Owner

loganch commented Jul 3, 2024

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
Copy link

SkyEmie commented Jul 13, 2024

Hi all,

My workaround is this one:

  • create a kind of wrapper (whatever the language used) to call au3check with the "entrypoint" of the project
#noTrayIcon
#Include <AutoItConstants.au3>

#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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants