boocs / ue4-intellisense-fixes

Automatically fixes VSCode/Unreal Engine Intellisense Config bugs on startup
MIT License
162 stars 9 forks source link

IntelliSense doesn’t work correctly with M1 macs #10

Closed sampattuzzi closed 2 years ago

sampattuzzi commented 2 years ago

IntelliSense doesn’t work correctly with M1 macs as seen here https://community.gamedev.tv/t/after-install-intellisense-fix-getting-worse/181116/26

The following post describes how to fix it.

Presumably all that’s really needed is to set the IntelliSense mode in the c_cpp_properties.json to “macos-clang-arm64”

A very quick gander, it looks like they’re already doing something with it.

https://github.com/boocs/ue4-intellisense-fixes/blob/master/src/extension/fixes/compilerPath.ts#L151-L165

boocs commented 2 years ago

It looks like I might be able to do this automatic using: let isM1 = cpuCore[0].model.includes("Apple M1")

https://stackoverflow.com/questions/65146751/detecting-apple-silicon-mac-in-javascript

If there are problems I could do the same thing as I do with the c++14 standard setting where you can set it in the extension settings to force it.

boocs commented 2 years ago

I released a potential fix. Let me know if it fixes the problem.

You can check the extension logs to see what it shows. If the fix still doesn't work you can post it here:

Start fix wrong intellisense mode
Found: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
Intellisense mode doesn't need to be fixed.
End fix wrong intellisense mode.
sampattuzzi commented 2 years ago

@boocs you rock. I will check with the students as I don't have the machine. Thanks for making a patch so quickly.

SuperWig commented 2 years ago

The compiler path definitely needs to be set to /usr/bin/clang. Not sure why they would default to g++ on macOS.

boocs commented 2 years ago

@SuperWig

I'll probably do a path setting that puts whatever path you want in the c_cpp_properties.json. Would that work?

I know on Windows, to get clang to work, I also have to change the compiler paths in the compile commands file as well.

SuperWig commented 2 years ago

It just needed /usr/bin/clang per this thread https://community.gamedev.tv/t/vs-code-error-bull-cow-game/189198

I assumed it would already be set to that on macOS as clang (specifically Apple Clang) is the native compiler on macOS. So it's a bit odd that it's set to g++.

boocs commented 2 years ago

@SuperWig

Ok, thanks for the info!

boocs commented 2 years ago

I updated the extension so it automatically includes the correct compiler path in c_cpp_properties for Mac M1. You can also modify the path in the extension settings if the path needs to be modified.

Unfortunately for this release I updated dependencies(security) so for some reason it made the extension only support the latest release of VSCode 1.63.1. Hopefully it's not that big a deal.

If you want to test this for me, after you install the new update close VSCode. Then right click on your project's uproject file and choose Generate Visual Studio Project Files... This will reset your project's VSCode config. Open VSCode for my extension to attempt to fix. Mac M1 users shouldn't have to change anything for it to fix it, unless you need to force c++14. You can do that in the extension settings.

SuperWig commented 2 years ago

I don't have an M1 mac so I'm unable to test, unfortunately.

ElDuderini commented 2 years ago

I just started working with unreal engine on Mac and I am still having the IntelliSense issues where the includes errors will still exist, along with the library of IntelliSense being incomplete. Here is the message I got from the fixes plugin output.

Extension "UE Intellisense Fixes" 3.0.1 is now active!

Found Unreal Engine v5.0.1

Fixing compiler path in c_cpp_properties.json.
Extension compiler path is set to: /usr/bin/clang
End fix c_cpp_properties compiler path.

Fixing compiler paths in compile commands.
Will not override compiler path in compile commands file. (Not an error)
Below is the compile commands first entry command. (WARNING) If getting errors and the compiler path is unexpected reset your UE project.
command: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" @'/Users/justin.peters/Documents/Unreal Projects/UnrealARTest/.vscode/compileCommands_UnrealARTest/UnrealARTest.222.rsp'
Compile Command Object wasn't modifed. Will not write file.
Below is the compile commands first entry command. (WARNING) If getting errors and the compiler path is unexpected reset your UE project.
command: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" @'/Users/justin.peters/Documents/Unreal Projects/UnrealARTest/.vscode/compileCommands_Default/UnrealARTest.222.rsp'
Compile Command Object wasn't modifed. Will not write file.
Done fixing compiler paths.

Fixing invalid paths in response files.
No invalid paths returned. No fixes needed.
No invalid paths returned. No fixes needed.
End fixing invalid paths in response files.

Fixing missing compile command files.
No missing file paths found. No fixes needed.
No missing file paths found. No fixes needed.
End fix missing compile commands.

Attempting to fix UE workspace(Add empty tag parser).
UE's tag parser includes are set to empty array for performance.
The setting limitSymbolsToIncludedHeaders is already set to true.
End fix UE workspace(Add empty tag parser).

Attempting to fix wrong cppStandard.
This extension set main workspace c_cpp_properties.json's cppStandard to c++17
This extension set main workspace c_cpp_properties.json's cppStandard to c++17
This extension set ue4 workspace c_cpp_properties.json's cppStandard to c++17
This extension set ue4 workspace c_cpp_properties.json's cppStandard to c++17
End fix wrong cppStandard.

Fixing launch.json.
launch.json didn't need to be changed.
End fix launch.json.

Start fix wrong intellisense mode
Cpu: Apple M1 Pro
This extension set main workspace c_cpp_properties.json's intellisenseMode to macos-clang-arm64
This extension set main workspace c_cpp_properties.json's intellisenseMode to macos-clang-arm64
This extension set ue4 workspace c_cpp_properties.json's intellisenseMode to macos-clang-arm64
This extension set ue4 workspace c_cpp_properties.json's intellisenseMode to macos-clang-arm64
End fix wrong intellisense mode.

Attempting to fix UE workspace optimization.
Current Main workspace file's forced includes are already fixed.
End fix UE optimization.

No need to write UnrealARTest CCppProperties. It was unchanged.
No need to write UE5 CCppProperties. It was unchanged.

Extension is done.

One thing to note is when I try right-clicking on my uproject file on mac, I get no option to generate the vscode files. The only way I am able to do this is by refreshing the vscode project file within the unreal engine editor itself.

boocs commented 2 years ago

First thing is you should change it back to force C++14. I only have the C++17 option there because if you have the full source you can add a C++17 flag to force UE to compile with it.

The right-click thing is weird but you can run this command inside VSCode itself. You need to have the Microsoft C# extension installed with the correct things installed. Not sure if MacOS can or not though. If you get it working go to the Run/Debug window (left side of VSCode) and choose the option Generate Project Files and run it.


The C++14 fix probably isn't the bug though. I have been running into a bug where the .generated.h files path isn't being added to the .rsp file.

I'm not sure which option you choose when Building when, in VSCode, you choose Terminal->Run Build Task...?

I choose MyProjectNameEditor (note the Editor suffix) and also Win64 Development Build. If .generated.h files don't get created choose Rebuild. When I choose the above options the .generated.h files get created in the Intermediate\Build\Win64\UnrealEditor\Inc\MyProjectName directory.

The bug comes with the Intellisense .rsp files the compile command uses. The .generated.h directory won't be included in the list of include paths.

After you Build, creating genrated.h, you'll have to run Generate Project Files again to add the *.generated.h path to the rsp files.

Edit: I am looking into a warning and fix for this.

boocs commented 2 years ago

@ElDuderini

I've tested this and it seems correct. You have to Build with the Editor suffix and then Generate Project Files to fix the Intellisense bugs.

Screenshot 2022-05-08 165619

This is how I usually build. With editor suffix and Development. I don't know if Win64 is different on Mac but just choose whatever is appropriate.


I forgot to mention you can also Refresh Visual Studio Project in the Tools menu of UE5. So if you can Build and Run your project then you can also refresh your project. If you can it's more convenient to do it from VSCode though:

gpfCapture

boocs commented 2 years ago

@ElDuderini

It also could be that the extension automatically sets the M1 compiler path to /usr/bin/clang yet in the log it says the compile command uses /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

You can force the compiler path, in my extension settings, so that everything will use: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

or set it to whichever clang path you want.

boocs commented 2 years ago

Whoa, I guess I'm wrong about c++14. UE5 now uses c++17 stuff?

I had an error in one of my project files about align_val_t not being in namespace std and setting Intellisense to c++17 fixed it.

Strange that this isn't more widely reported!

ElDuderini commented 2 years ago

@ElDuderini

It also could be that the extension automatically sets the M1 compiler path to /usr/bin/clang yet in the log it says the compile command uses /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

You can force the compiler path, in my extension settings, so that everything will use: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

or set it to whichever clang path you want.

This makes a lot more sense. I thought the /usr/bin/clang was the right path since that is what came up when I type in "where clang" in my terminal. Thank you for all of the other advice, especially since I didn't know you could generate project files within the visual studio code itself. I am experimenting with different platforms for creating AR content for work, so I will let you know when I end up testing it again and see if the fixes you suggested worked.

boocs commented 2 years ago

@ElDuderini

Sorry for the spam. Last one!

I forgot to mention in my extension it's the 'strict path' setting you have to enable. With it enabled, my extension's path setting will be copied over to the compile command files.

ElDuderini commented 2 years ago

Well, I tried building to mac, generating new files, and setting the clang compile path to be different things still with no luck, along with changing several c++ extension settings. I am thinking I might just use the unreal engine on my windows laptop instead since this has been giving me so many problems. Was just hoping to have it work on the M1 macs since that is what all of my colleges use.

boocs commented 2 years ago

@ElDuderini

Can you post a pastebin link of some c++ logs? You don't need to sign up: https://pastebin.com/

Switch to one of your project's cpp files that's giving an error. Now go to VSCode's Command Palette and type Log and choose this option:

image

Select all the text, from the log, and paste it into pastebin and post the link. Note: Some paths may contain your name so if you want to copy it into a word processor and find/replace your name then you should do that first.

ElDuderini commented 2 years ago

https://pastebin.com/mW7kbngz Here you go, hopefully it helps. Appreciate you taking the time to look into this.

boocs commented 2 years ago

I guess I'll remember to do the diagnostic earlier. Looking at the pastebin it shows the wrong c++ standard.

In my extension's settings force the cpp standard to c++14 for UE 4.2# and force it to c++17 for UE 5.0+

Hopefully that's the only thing wrong!

ElDuderini commented 2 years ago

I just tried setting it to c++17 and c++14 on your extensions settings but neither of them fixes the issues I am having. I check the logs after I generate project files and then restart vscode. One thing I notice is that cStandard stays at c17 regardless of when I set it to cpp 14 or 17. Unsure if it is related to the issues or not.

boocs commented 2 years ago

cStandard shouldn't matter.

So when you force c++17, since you're using UE5, and you run Log Diagnostic again does the correct Cpp standard show up in both log spots?

Your previous pastebin has these two lines: "cppStandard": "c++98", ... Standard Version: c++03

What do both lines say after you force c++17?


Another weird thing in your log. if I'm reading it correct, says the Intellisense is mapping UnrealARTest.cpp with VisualStudioCodeTest.h as one translation unit. This is weird as it should be mapping it to it's own UnrealARTest.h.


Does AR mean alternate reality like a VR project? This could mean your missing some dependencies in your ProjectName.Build.cs file. Can your paste your *.Build.cs file here?


When you did the log did you strip out all the include paths to make it fit inside pastebin?

If so, can you run a test inside VSCode with the log. Use this Regex to search the log and see how many results come up. Do you see in search widget where ".*" is highlighted. You need to turn this option on for a Regex to work: Like so: image

This Regex is the same one I'm using in my upcoming update:

(?<!Engine)[\/|\\]Intermediate[\/|\\]Build[\/|\\]\w+[\/|\\]UnrealEditor[\/|\\]Inc

Does it find anything?

ElDuderini commented 2 years ago

After I force c++ 17, all of the cpp standard variables switched to c++ 17 as intended.

I created the template using the AR example to test see if building AR apps on mac would work well for us. It didn't give an option to create the project using c++, so I assume it started off with just blueprints? I later then generated a random character c++ document to test to see if IDE would work well with unreal c++ code. And yes, UnrealARTest is the name of the project. I have also created a c++ project using the FPS base to test to see if it would work better, but I got the same results. Also, I actually didn't strip out the included paths, the log I showed you is what I got. Do I need to manually add all of the include paths from the engine and where would I find those?

Here is the Pastebin of a new project I created with the FPS c++ template https://pastebin.com/eyCTcJiE

and here are the contents of the Build.cs file for this project

using UnrealBuildTool;

public class CPPTest : ModuleRules
{
    public CPPTest(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });
    }
}
boocs commented 2 years ago

Thanks for the info! You shouldn't add those manually, Unreal should have done it for you. There are a lot of include paths.

The log says it's using: "/Users/name/Documents/Unreal Projects/CPPTest/.vscode/compileCommands_Default.json"

Open that file up and go to the entry for CPPTestProjectile.cpp and paste the 'command:' for that entry here.

The command should have a compiler path listed and an @path with an .rsp file. Can you post the pastebin of the .rsp file contents? (remember to find/replace names if you want)

ElDuderini commented 2 years ago

Here is the command I got for CPPTestProjectile.cpp

"command": "\"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++\" @'/Users/name/Documents/Unreal Projects/CPPTest/.vscode/compileCommands_Default/CPPTest.204.rsp'",

and here is that pastebin for that rsp file https://pastebin.com/WpePMn6b

boocs commented 2 years ago

@ElDuderini

Up above in your new log it says it's using "intelliSenseMode": "macos-clang-arm64" which is correct.

Down farther is says it's really going to use IntelliSense Mode: macos-clang-x64 which is wrong. (in your previous version both were correct)

My extension should automatically set the correct "intelliSenseMode" for M1 macs.

ElDuderini commented 2 years ago

In both cases, it looks like it is being changed. For some reason, the log file now is using clang-arm64 in both cases now, which seems to be working as intended. Though intelisense is still broken

Screenshot 2022-05-13 at 09 17 53 Screenshot 2022-05-13 at 09 22 45
boocs commented 2 years ago

So just to be sure, you've closed/reopened VSCode and reran the log command and it still shows the wrong intellisense mode?

The only thing I see is that the ops link above does show that they changed the compiler path to /usr/bin/clang to fix the m1 mac problem. You can leave out enabling the extensions strict path setting for now. Just see if changing the setting affects the log's 2nd intellisense mode. You can also try /usr/bin/clang++ and check again.

Edit: I use clang++ on Window but try clang as well.

If both don't work you can try forcing both compiler paths but with the strict setting. Just remember that if you use the strict setting and want to revert back you'll have to Generate Project Files.

There is another way to get real time logs for the C++ extension. Maybe it'll show why it's reverting the intellisense mode. I'll put the info on how to do it in a separate post.

boocs commented 2 years ago

Now that we are done with the Tag Parser log we can check the default Intellisense log.

ElDuderini commented 2 years ago

Thanks for telling me all of these steps for setting up the proper way to send the logs. I ended up trying both /usr/bin/clang and /usr/bin/clang++, both toggling the force paths on and off for them while also generating the project files again and reloading vscode.

Here is the pastebin of the log https://pastebin.com/sS7tHXpi

boocs commented 2 years ago

Yeah the log shows the correct Intellisense mode. It still shows that it's not reading the rsp file from the compile commands file.

For the previous test I meant to do these four tests. You don't have to give logs for each. Just see if any of the settings below fixes anything.

After changing each setting, make sure to restart VSCode, and open CPPTestProjectile.cpp, and wait for the default Intellisense, fire symbol, to disappear.

1


2


3


4

ElDuderini commented 2 years ago

I have tried all of these, and they haven't worked for me. After this, I tried compiling some code with just raw c++ with one external library, raylib. The strange thing about it was that while the IDE said that the library file could not be found, it was possible to find the definition of those classes within that h file, and then it had the specific IntelliSense working for that library. So that made me think that maybe all external libraries are not being recognized by the IDE. As I tried it with Unreal, I tried hovering over variables but it would just show them as "error types" like this.

< error-type > ProjectileMovement

boocs commented 2 years ago

@ElDuderini

You do have the mac framework path in the c_cpp_properties.json so it should be working. Pretty strange.

Maybe there's some .NET SDK that needs to be installed that wasn't? Is this your first time using the Unreal Engine?


1. One thing you did is you forgot to include your Tag Parser logs from these instructions https://github.com/boocs/ue4-intellisense-fixes/issues/10#issuecomment-1125946126

Here's an example what both should look like: I'm using Clang 12 on Windows and I mimicked your project: Tag Parser: https://pastebin.com/5gdB0uZt Default (CPPTestProjectile.cpp): https://pastebin.com/GR8GAEQP


2. One thing that might have been lost above was to make sure to try a Rebuild image

Make sure it has the 'Editor' suffix and it's the 'Development' config. 'Win64' will probably be different for you.


  1. We are getting down to the end of things to try so I'll throw out some stuff.

It seems like it's not reading the rsp file and this extension does modify the rsp line: This is what you posted above from your compile commands file:

"command": "\"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++\" @'/Users/name/Documents/Unreal Projects/CPPTest/.vscode/compileCommands_Default/CPPTest.204.rsp'",

This extension adds escape quotes to the compiler path \"

You'd think more M1 Mac users would be complaining if this was the case though.


  1. Another dumb suggestion

Maybe your MacM1/Clang version doesn't like the spaces for the -I flag in your rsp file. You can try a find/replace to test this. Note: I have spaces and use Clang 12 and it works.

Jut replace all -I " with -I"

-I "/Users/Shared/Epic Games/UE_5.0/Engine/Source" -I"/Users/Shared/Epic Games/UE_5.0/Engine/Source"

The Clang docs show it with no space


  1. I'm dumb and never asked for a pic of your VSCode 'Problems' window image

7. Does this OUTPUT have any interesting messages? image

ElDuderini commented 2 years ago

Needed to take a break from trying to get unreal engine to work on mac to work on some 3D art, but after trying some of my own stuff, I finally got it to work today! The engine automatically tries to set up project directories with spaces in them, so I decided to start fresh, remove all of the sample projects and create a new, fresh project again but making sure that the directory was UnrealProjects instead of Unreal Projects. Surprisingly enough doing this got IntelliSense to work.

boocs commented 2 years ago

@ElDuderini Thanks for explaining how you fixed it. Hopefully it helps others!

Weirdly I didn't get notification of your latest message.

boocs commented 2 years ago

I released a new version 3.4.0. I also rented a cloud M1 Mac to test.

All I had to do was set the extension's path to /usr/bin/clang++ and I also forced a c++ standard and Intellisense worked.

There is some problem with Intellisense when first booting VSCode. It's very slow trying to get compiler defaults from clang. After that though Intellisense seems to work as normal.

I'm going to close this. Feel free to open another post if you have any more problems.