ue4-intellisense-fixes icon indicating copy to clipboard operation
ue4-intellisense-fixes copied to clipboard

#pragma once errors with simple first person UE5 project

Open max-cis opened this issue 2 years ago • 66 comments

Hi, I have used your extension to remove most of the problems but I am still getting a few. Unfortunately, I am required to use macos for this and I am not particularly familiar with various things.

My current setup is an i7 iMac so not on the M1 or anything. I was hoping I have set up the cppproperties for intelli sense to "macos-clang-x64". I left the compiler path to the default. Also, I am only using the option from your extension "UEIntellisenseFixes.enableFixes": true, "UEIntellisenseFixes.cppStandard": "c++17"`.

Any ideas on what I could do to fix this? I have attached a picture of the errors. Maybe it helps.

Thanks, M Screenshot 2022-08-29 at 11 34 31

max-cis avatar Aug 29 '22 10:08 max-cis

Some things to try:

Make sure you can build successfully first with the 'Editor' suffix config like so: image

This is a VSCode Build Task. TestFps is the project name and notice the 'Editor' suffix. Win64 might be Mac for you.

This will create some files needed for Intellisense if they're missing.

Now you'll need to reset your project which will add the new file paths to Intellisense configs. image

Right click on your *.uproject file and choose Generate Visual Studio Project Files (or something similiar). If you can't find it you can also do this by loading your project in to the UE5 Editor and choose this option from the Tools menu. It's called 'Refresh Visual Studio Code Project'. It's also possible inside VSCode. One of the debug configs is called Generate Project Files. You do need to install the Microsoft C# extension for it to work though.

Restart VSCode and see if it works.

Another thing to try, maybe the config you're using is bugged. image

You can click the Win32 which is the name of one of the intellisense configs. Yours will probably be named something different. When you click it you'll get a menu with two choices. Click the opposite config that's currently active. image

boocs avatar Aug 29 '22 11:08 boocs

Thanks for getting back so quickly. I managed to figure out the reason behind the problems.

I am not sure if it is because I didn't set up the compiler in your extension properly, but I needed to add the following two parameters to the c_cpp_properties.json file to ensure that all the errors went away.

  "includePath": ["${workspaceFolder}/**"],
  "compilerPath": "/usr/bin/clang",

I am not sure if you think it is worth adding this to the extension so it includes these two parameters when it corrects the file.

I don't know how to do it, but I think could be marked as a workaround in GitHub. May help other MacOS users.

max-cis avatar Aug 30 '22 13:08 max-cis

I do have a compiler path setting in my extension but the includePath making it work is weird.

It would mean that it's not using the compile commands file for Intellisense and instead using the cpptools includePath setting.

This could also mean you're not using the 'smart' Intellisense and instead using the other intellisense called 'Tag Parser'.

Pretty strange. Are you sure you need the includePath setting for it to work?

boocs avatar Aug 30 '22 17:08 boocs

I'm running on a Mac M1 and I've been using the extension to fix a few IntelliSense problems (thanks by the way), but the whole discovery of files was really really slow. The loading of the symbols and suggestions would take ages. But, after reading the official docs of VSCode about C++ and seeing this issue thread, I decided to add the includePath property in the c_cpp_properties.json. I have to say it worked like a treat! Now the whole discovery of files and IntelliSense is super fast.

As a reference, my compiler path is: "compilerPath": "/usr/bin/clang++"

leonfs avatar Aug 30 '22 20:08 leonfs

@leonfs I think that means you're using the Tag Parser Intellisense(which is fine). The latest UE4/UE5 use compile commands which override the includePath setting so includePath shouldn't be affecting anything.

The compile commands must have include errors which forces VSCode to fall back to instead use Tag Parser Intellisense.

boocs avatar Aug 30 '22 21:08 boocs

You might be right, actually. How do you find those include errors @boocs? For some reason, navigating with IntelliSense the UE code is super fast, but when I have to navigate my project's code, it is super slow.

There is clearly something not right.

leonfs avatar Aug 30 '22 21:08 leonfs

Tag Parser Intellisense is super fast but not as smart as the default Intellisense which is fast with cpp files but slow with header files because of how it works(updates too often whenever you type).

You should be able to look at the cpptools(C_CPP) extension logs. The setting is called Logging Level. Set it to debug. I actually should just make a guide because it's really easy to check with the cpptools log. It'll take some time but let me do that.

boocs avatar Aug 30 '22 23:08 boocs

Also - In the logs of the C++ extension I see this:

[8/31/2022, 9:17:18 AM] For C source files, IntelliSenseMode was changed from "macos-clang-x64" to "macos-clang-arm64" based on compiler args and querying compilerPath: "/opt/homebrew/opt/llvm@12/bin/clang"
[8/31/2022, 9:17:18 AM] IntelliSenseMode was changed because it didn't match the detected compiler.  Consider setting "compilerPath" instead.  Set "compilerPath" to "" to disable detection of system includes and defines.
[8/31/2022, 9:17:18 AM] For C++ source files, IntelliSenseMode was changed from "macos-clang-x64" to "macos-clang-arm64" based on compiler args and querying compilerPath: "/opt/homebrew/opt/llvm@12/bin/clang"
[8/31/2022, 9:17:18 AM] IntelliSenseMode was changed because it didn't match the detected compiler.  Consider setting "compilerPath" instead.  Set "compilerPath" to "" to disable detection of system includes and defines.
[8/31/2022, 9:17:19 AM] For C++ source files, IntelliSenseMode was changed from "macos-clang-x64" to "macos-clang-arm64" based on compiler args and querying compilerPath: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"

leonfs avatar Aug 31 '22 08:08 leonfs

@leonfs just to make you aware that I am running an older i7 iMac so my compiler settings will differ from yours. Make sure you are not confusing the settings. There is another thread regarding M1 settings.

@boocs I will have a look and report back. Sorry, got caught up in other things.

max-cis avatar Aug 31 '22 10:08 max-cis

@leonfs I created a new issue for you called M1 Mac issues

boocs avatar Aug 31 '22 10:08 boocs

@boocs I started a brand new project and set the path in your extension. The settings are as follows:

    "UEIntellisenseFixes.compiler.path": "/usr/bin/clang",
    "UEIntellisenseFixes.compiler.strictPath": true,

There were no immediate errors, but it was stuck on Loading... for ages. I then got an error with the include path and then it found things. It did take very long in comparison to when the includepath was set before.

As far as I can tell, I am using the Default intelliSense. Is that not the proper one? The setting is set as follows:

"C_Cpp.autocomplete": "Default"

Any way to check if it is using the correct IntelliSense? Also, I haven't switched on your optimisation setting.

max-cis avatar Aug 31 '22 12:08 max-cis

I don't know if you have have my latest extension version 3.2.0. But I changed the strict setting documentation to say only use it if the extension's path setting is the full compiler path.

Make sure to change it to the full xcode/clang or clang++ path.

Makes me think I should just detect if it's a full path and error if it's not(when using the strict setting).

If you decide to remove the strict setting you should do a Generate Project File on your project.

boocs avatar Aug 31 '22 14:08 boocs

I did read that in your extension. However, when you read the output it states that it is better to actually have the box ticked. When you say full path you mean absolute rather than relative, right?

max-cis avatar Aug 31 '22 15:08 max-cis

Yep, I guess my extension change wouldn't have worked if /user/bin/clang is also an absolute path on some systems. Maybe I'll just detect it on Mac and make sure if you use the strict setting that xcode is in the path somewhere.

So basically on Mac if using the strict setting your path setting should look something like this: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang or clang++ since clang++ is what ue5 default compiles with on Mac.

boocs avatar Aug 31 '22 15:08 boocs

You can also remove the strict setting and Generate Project Files to get back the full xcode clang path in your compile commands file.

After you Generate Project Files, you can also check my extension log to see what the compile commands compiler path is being set to by the Unreal Engine.

Below is the compile commands first entry command. (WARNING) If getting errors and the compiler path is unexpected reset your UE project.
command: "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\cl.exe" @"D:\EJ\Documents\Unreal Projects\CPPTest\.vscode\compileCommands_CPPTest\CPPTest.211.rsp"

For example, my project's extension log above it says it's using "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\cl.exe"

boocs avatar Aug 31 '22 15:08 boocs

Once you figure out the full path that Unreal chooses you can just copy and paste that into the path setting and reenable the strict setting. Actually since they're going to be the same anything I guess you don't need to use the strict setting if you don't want lol.

I'm thinking that maybe the strict setting was a bad idea and just reading the compile commands compiler setting and auto pasting it into the path setting would be better. That way it's up to you to install the correct clang and up to Unreal to detect and use the correct clang.

boocs avatar Aug 31 '22 15:08 boocs

Here's how I'll fix this.

  • Recommend not using strict setting anymore. (Keep it for Windows users who want to compile with clang or future compiler bugs)
  • Without the strict path setting it will default pull Unreal's clang path it uses in the compile commands and copy it to the extension's path setting. Now VSCode's compilerPath and compile commands setting will be in parity.

boocs avatar Aug 31 '22 16:08 boocs

I released 3.3.0 with the path fixes. You can remove the strict setting and reset your project(Generate Project Files) to fix it.

The path setting will now be auto set based on what compiler Unreal chooses.

boocs avatar Sep 01 '22 02:09 boocs

I've released my guide on how to check for VSCode config bugs. This is just a partial Include Errors release. Note: This will get reorganized and changed.

https://github.com/boocs/Unreal-VSCode-diy-config-check-github

boocs avatar Sep 01 '22 06:09 boocs

Ok, so I downloaded your latest version. Removed the strict flag and refreshed the project twice from Unreal 5. Restarted VSCode, got the extension to fix things and then I got errors with the includePath. See image below: Screenshot 2022-09-01 at 15 17 11

I checked c_cpp_properties.json and it is set up as follows:

 {
            "name": "Test3Editor Editor Mac Development (Test3)",
            "intelliSenseMode": "clang-x64",
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compileCommands": "/Users/lmnicosia/CIS/Projects/UE5/Test3/.vscode/compileCommands_Test3.json",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "compilerPath": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"
 }

I tried adding "includePath": ["${workspaceFolder}/**"] to c_cpp_properties.json but that didn't fix anything. I set the strict flag and that made the error on Test3.h go away but the other two include errors stayed.

The current config in settings.json is:

  "UEIntellisenseFixes.enableFixes": true,
    "UEIntellisenseFixes.cppStandard": "c++17",
    "C_Cpp.default.intelliSenseMode": "macos-clang-x64",
    "workbench.editor.untitled.hint": "hidden",
    "UEIntellisenseFixes.compiler.path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++",
    "C_Cpp.loggingLevel": "Debug",
    "UEIntellisenseFixes.compiler.strictPath": true,

Any ideas?

max-cis avatar Sep 01 '22 14:09 max-cis

Ok, so it appears that I managed to find a stable configuration.

I removed the strict flag and left the compilerPath in your extension blank and restarted VSCode. I checked and it was auto-completed with: "UEIntellisenseFixes.compiler.path": "/usr/bin/clang", So far no errors. The output of your extension is as follows:

Extension "UE Intellisense Fixes" 3.3.0 is now active!

Found Unreal Engine v5.0.3

Fixing compiler path in c_cpp_properties.json.
Auto updating extension's compiler setting to /usr/bin/clang
End fix c_cpp_properties compiler path.

Fixing compiler paths in compile commands.
Below is the compile commands first entry command. (WARNING) If getting errors and the compiler path is unexpected reset your UE project.
command: "/usr/bin/clang" @/Users/XXXXXX/CIS/Projects/UE5/Test3/.vscode/compileCommands_Test3/Test3.206.rsp
Compile Command Object wasn't modifed. Will not write file.

I have no idea why it doesn't like "UEIntellisenseFixes.compiler.path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++".

Any ideas what's happening?

max-cis avatar Sep 01 '22 14:09 max-cis

Seems like the project reset isn't working properly. It still has the /usr/bin/clang from the previous time.

Would it be possible to create a new project and see what compiler Unreal chooses for the compile commands (by checking extension log)?

(remember to leave the strict setting unchecked)

I'm also going to update my guide today for different ways to reset your project. Maybe one won't be broken. It'll be funny if it turns out your reset isn't broken and Unreal chooses usr/bin/clang for the compiler.

boocs avatar Sep 01 '22 16:09 boocs

I’ll quickly create a project and report back. Let’s see what’s happening!

On 1 Sep 2022, at 17:14, boocs @.***> wrote:

Seems like the project reset isn't working properly. It still has the /usr/bin/clang from the previous time.

Would it be possible to create a new project and see what compiler Unreal chooses for the compile commands (by checking extension log)?

(remember to level strict setting unchecked)

I'm also going to update my guide today for different ways to reset your project. Maybe one won't be broken. It'll be funny if it turns out your reset isn't broken and Unreal chooses usr/bin/clang for the compiler.

— Reply to this email directly, view it on GitHub https://github.com/boocs/ue4-intellisense-fixes/issues/22#issuecomment-1234496754, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALL3UBUXDYUXAEWGRDDIKWLV4DI5HANCNFSM575IWEFA. You are receiving this because you authored the thread.

max-cis avatar Sep 01 '22 16:09 max-cis

Ok, so I created a new project and let it do its thing. It seems that Unreal is using /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++. However, that gives a lot of errors! See extension output below and screenshot.

Searching for *.uproject file...
Searching with fast-glob found nothing. (Sometimes isn't bug)
*.uproject file was found!

Extension "UE Intellisense Fixes" 3.3.0 is now active!

Found Unreal Engine v5.0.3

Fixing compiler path in c_cpp_properties.json.
End fix c_cpp_properties compiler path.

Fixing compiler paths in compile commands.
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/XXXX/CIS/Projects/UE5/MyProject2/.vscode/compileCommands_MyProject2/MyProject2.204.rsp
File write: /Users/XXXX/CIS/Projects/UE5/MyProject2/.vscode/compileCommands_MyProject2.json
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/XXXX/CIS/Projects/UE5/MyProject2/.vscode/compileCommands_Default/MyProject2.204.rsp
File write: /Users/XXXX/CIS/Projects/UE5/MyProject2/.vscode/compileCommands_Default.json
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/Shared/Epic Games/UE_5.0/.vscode/compileCommands_MyProject2/MyProject2.204.rsp'
File write: /Users/Shared/Epic Games/UE_5.0/.vscode/compileCommands_MyProject2.json
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/Shared/Epic Games/UE_5.0/.vscode/compileCommands_Default/MyProject2.204.rsp'
File write: /Users/Shared/Epic Games/UE_5.0/.vscode/compileCommands_Default.json
Done fixing compiler paths.

Fixing invalid paths in response files.
MyProject2.204: Fixed paths count(50), Unfixed paths count(0)
MyProject2.204: Fixed paths count(50), Unfixed paths count(0)
End fixing invalid paths in response files.

Fixing *.generated.h files!
Searching with fast-glob found nothing. (Sometimes isn't bug)
Correct *.generated.h files are found! Note: This extension doesn't test if all *.generated.h files have been created.
For Intellisense, you'll need to Build any newly created project files with the 'Editor' suffix config (e.g. MyProjectNameEditor (platform) Development Build).
All response files have the correct *.generated.h path!
End fixing *.generated.h

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.

Warning about Public/Private directory
Searching with fast-glob found nothing. (Sometimes isn't bug)
Searching with fast-glob found nothing. (Sometimes isn't bug)
You do not have this directory structure so no warning needed.
End warn Public/Private Directory

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.
Info : UE4 should be default c++14 (it can be c++17 with some special configuration)
Info : UE5 should be c++17
Current VSCode/cpptools cppStandard is:  (Can be blank)
Current c_cpp_properties.json's cppStandard is: c++17 (Overrides VSCode/cpptools if not undefined)
MAIN workspace c_cpp_properties.json's cppStandard is already set.
Current c_cpp_properties.json's cppStandard is: c++17 (Overrides VSCode/cpptools if not undefined)
MAIN workspace c_cpp_properties.json's cppStandard is already set.
Current VSCode/cpptools cppStandard is:  (Can be blank)
Current c_cpp_properties.json's cppStandard is: c++17 (Overrides VSCode/cpptools if not undefined)
UE workspace c_cpp_properties.json's cppStandard is already set.
Current c_cpp_properties.json's cppStandard is: c++17 (Overrides VSCode/cpptools if not undefined)
UE workspace c_cpp_properties.json's cppStandard is already set.
End fix wrong cppStandard.

Fixing launch.json.

Attempting to fix the json of launch.json...
There was nothing to fix!
End fix launch.json.

Start fix wrong intellisense mode
Cpu: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
Didn't need to set intellisenseMode.
End fix wrong intellisense mode.

Attempting to fix UE workspace optimization.
Optimization of UE is disabled.
End fix UE optimization.


Writing /Users/XXXX/CIS/Projects/UE5/MyProject2/.vscode/c_cpp_properties.json to file.

Writing /Users/Shared/Epic Games/UE_5.0/.vscode/c_cpp_properties.json to file.

*** Number of error messages: 0
*** Number of warning messages: 0
If you get any errors you can try restarting VSCode to check if they've been fixed.

Extension is done.
Screenshot 2022-09-01 at 17 23 31

I don't know why, but the only way to get it to not fail is to use usr/bin/clang. It makes no sense!

max-cis avatar Sep 01 '22 16:09 max-cis

Temporarily you can go into the path setting of the extension. It should now have to full xcode/clang++ path there.

Remove the ++ from the path and enable strict.

Restart VSCode and see if the errors go away with the new project. Enabling strict copies the path setting to your compile commands file overwriting the compiler choice that Unreal chose.

boocs avatar Sep 01 '22 16:09 boocs

I'm wondering if this is a version issue?

Unreal requires specific XCode version for developing. It's XCode 12.4 for Mac development on UE5. It's weird because I thought after the release of 5.0.2 it required XCode 13 but it says only IOS projects require that.

https://docs.unrealengine.com/5.0/en-US/hardware-and-software-specifications-for-unreal-engine/

Do you know what version you have?

I know diffferent clang or xcode versions can cause problems. On Windows I can't use clang 14 to compile because it has a new warning and Unreal treats warnings as errros. I had to use clang 13 to compile on Windows.

boocs avatar Sep 01 '22 16:09 boocs

So, I did that and the errors keep on coming back. However, going to definition (F12) works! I checked XCode and I have 13.4.1. I am planning on deploying to iOS so I had to upgrade to whatever the latest version was.

I wonder why usr/bin/clang works though.

max-cis avatar Sep 01 '22 17:09 max-cis

When you Build your project you're building with with XCode/clang++ so it does work. Pretty strange that Intellisense can't use the same compiler path.

stdlib.h is a system include and there are a lot of issues people have with them and clang. It could be Unreal isn't including something it should be. It also could be VSCode is failing at polling for system includes. Actually I know they auto poll system includes on Windows but with Mac maybe they don't and use what is listed in the compile commands/rsp(response) files.

If you put it back to what works can you check for system includes using my guide? https://github.com/boocs/Unreal-VSCode-diy-config-check-github

Also feel free to bail and get back to creating Unreal projects lol

boocs avatar Sep 01 '22 17:09 boocs

I am happy to help, however, I will try it tomorrow.

While I have done lots of development experience in Windows, I am totally new to MacOS/iOS. Without your extension, I would have wasted a lot of time trying to figure all this out. Also, kind of keen on understanding how all of these tools are talking to each other!

max-cis avatar Sep 01 '22 17:09 max-cis

I wonder why usr/bin/clang works though.

Do you have more than one version of clang installed? Maybe that version is being used with usr/bin/clang and is more compatible with Intellisense.

Unreal does use the C version of stdlib.h so maybe there's some clang or 'VSCode Intellisense' auto detection there which says you need to use clang and not clang++

boocs avatar Sep 01 '22 17:09 boocs