fdefelici / vs-funreal

Visual Studio extension to smooth the workflow of Unreal Engine C++ developers
MIT License
27 stars 7 forks source link

Extension options #15

Closed DrizztDoUrden closed 3 months ago

DrizztDoUrden commented 1 year ago

Some people (like me) use <> include notation everywhere UHT allows (everything other than *.generated.h include line). It would be very cool to have extension settings in Tools->Options like other ppl do with stuff like this.

fdefelici commented 1 year ago

I try with an example to clear the "include" directive needs (configuration by tools->options is clear enough)

When creating any source file from FUnreal menu, you would like that include directive will be written using < > as delimeter instead of " " (except for .geneated.h file).

So using Actor class creation as an example, currently it will be generated like this:

/* MyActor.h */
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

UCLASS()
class AMyActor : public AActor
{
    //...
};

/* MyActor.cpp */
#include "MyActor.h"
//...

And instead the desired result would be like this:

/* MyActor.h */
#pragma once

#include <CoreMinimal.h>
#include <GameFramework/Actor.h>
#include "MyActor.generated.h"

UCLASS()
class AMyActor : public AActor
{
    //...
};

/* MyActor.cpp */
#include <MyActor.h>
//...

Then < > will be used for both engine sources and application related sources in .h and .cpp files.

Is my understanding good?

DrizztDoUrden commented 1 year ago

Yes. To be fair at least 5.2 allows to use < > for .generated.h files, but considering people use different versions it's safer to always generate them as "", while leaving the rest configurable.

My reasoning for using <> is because it's safer in general and it's quite easy to have header name collision with multiple modules otherwise. So when using "" you can accidentally include something from current directory (it has priority) rather than from include search paths, which is usually hard to notice when they have similar API.

fdefelici commented 1 year ago

mmmh....don't know if < > will save you from names clash. Infact in the example above I'm using < > for applicative include (like #include in .cpp file and it is properly resolved during the build (AFAIK doesn't raise error because UBT add Public and Private folder automatically to the include path for the module).

This should be the reason (my speculation) why in the Engine sources, < > are never used for include directive or at least they use < > only for c++ standard library and third party library (so maybe another reason is to distinguish UE sources from others. Again my speculation :) ).

Probably < > could save you only by chance, because Engine include paths are added before the applicative ones, but I would avoid to depends on this mechanism, because you could have regression just in case include order is changed by unreal build system.

Eventually you could adopt < > and " " as for general C++ standard where you should use < > for "external" sources (C++ standard lib and third party lib. UE lib could fall in this scenario) and use " " for applicative sources (for me, generated.h fall in this scenario, because generated adhoc for applicative sources). This just to "visually" recognize them in source code. (and possibly this could be made configurable in FUnreal)

Anyhow, IMHO, the only way to be protected from wrong include resolution when developing for UE, is to avoid name clashing :)

fdefelici commented 3 months ago

@DrizztDoUrden now that custom templates feature has been released in v0.2.0 (see #16), I think you could implement your own templates adopting your preferred include directive style.

So I'm going to close this issue.