boocs / ue4-intellisense-fixes

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

Editing any code for project causes CoreMinimal.h to go "missing" #7

Open ZornTaov opened 2 years ago

ZornTaov commented 2 years ago

I'm attempting to use this extension with VSCode, and for the most part it's been working. However, whenever I change any line of code (for example, adding or removing any code in https://github.com/ZornTaov/TopDownCPP/blob/master/Source/TopDownCPP/Public/Character/MyPaperCharacter.h ) I get the error that "'CoreMinimal.h' file not found" with intellisense. Clearing out the Tag Parser database didn't fix it, telling Unreal to "Refresh Visual Studio Code Project" fixes it temporarily.

Possibly unrelated, but the VSCode complains about the #pragma once in the same file with the warning "#pragma once in main file [-Wpragma-once-outside-header]"

boocs commented 2 years ago

I downloaded your project and didn't get the same behavior. No CoreMinimal or #pragma once messages.

It could be the wrong cppStandard set. In my extensions settings, try forcing the cppStandard to c++14.
Just note that this is set in the VSCode user(global) config. In your non-Unreal projects you'll have to set the cppStandard in a project config to change it. It's bad to change VSCode project configs in Unreal since the configs will get overwritten.

Also in header files if you add any lines above the GENERATED_BODY() macro you will get errors until you Build again. This is because the GENERATEDBODY() macro uses the __LINE_\ preprocessor macro.

ZornTaov commented 2 years ago

I changed your extensions settings to use c++14, but I'm still getting that fake error about coreminimal. Want me to upload my settings and/or logs that might give a clue?

boocs commented 2 years ago

Yeah that would be fine. Open the file that gives the CoreMinimal message and click the Sprocket Button on the lower left of VSCode. Choose Command Pallette from the menu and search for Log Diagnostic and choose it. The Diagnostic will appear in the console window below. It might take a few seconds to fully run. It might be better to use pastebin.com instead of pasting it here.

Make sure to search/replace anything from the logs you don't want e.g. names in paths.

Can you Build without errors? Is the fake error still there after you Build?

ZornTaov commented 2 years ago

https://pastebin.com/SQV7sMh6 here you go. Yeah I can build without errors, both regular and Editor build tasks, and I can compile in the editor just fine, which is why I'm thinking it's just an IntelliSense not collecting all the right information. I'm wondering if it's because I THINK I should be using "C_Cpp.default.intelliSenseMode": "windows-clang-x64" instead of the "intelliSenseMode": "msvc-x64" your extension or unreal seems to enforce. I know I installed clang for this project using.... someones tutorial, but after jumping through so many different tutorials or setup guides just to get things to work I have no idea which tutorial that was. xD

boocs commented 2 years ago

Must be Unreal. This seems like a recent change because I've tried clang on windows with no problems in the past.

You can try switching Unreal to Build with clang. This might switch UE to force the correct clang intelliSenseMode.

You basically create a BuildConfiguration.xml file in your YourWindowsUsersDirectory/Documents/Unreal Engine/UnrealBuildTool directory.

Here's what I had in mine when I was using clang on Windows:

<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
    <ProjectFileGenerator>
        <Format>VisualStudioCode</Format>
    </ProjectFileGenerator>
    <WindowsPlatform>
    <Compiler>Clang</Compiler>
    </WindowsPlatform>
</Configuration>

Of course I could create a extension option like I did with cppStandard...

Also I think I lied and I do put the cppStandard setting in the local project config and not the global user VSCode config. I can get away with that since the extension always runs at startup. If it gets overwritten it'll just fix itself.

ZornTaov commented 2 years ago

So I tried the changes to buildconfiguration, and I don't think that actually changed anything. My c_cpp_properties still says "intelliSenseMode": "msvc-x64", BUT I don't consistently get the 'CoreMinimal.h' file not found fake error, and I can use F12 to go to the file, so I'm not sure what changed. I've been doing dev even with the error, but the problem is I'm not getting the live error handling of things like missing a ; or trying to access something private, I only find out I did something wrong when I tell VSCode or Unreal to compile code. I'm open to suggestion for other things I could change or try, but as it is this setup is WAY less frustrating than trying to use Visual Studio with UE4.....

boocs commented 2 years ago

Yeah I tried it out and it doesn't work.

But I have cl.exe installed too so VSCode automatically switches to use cl.exe based on the UE compiler flags located in the response file the project is using.

Changing my BuildConfiguration to Clang did allow me to Build with it but Intellisense still didn't use it because UE doesn't add clang compiler flags to the response file. At least on Windows it doesn't. So VSCode detects this and sets the Intellisense compiler to cl.exe.

So I'm wondering if you uninstall all cl.exe compilers then change your VSCode compiler path to clang-cl.exe if it would work? clang-cl.exe is compatible with cl.exe flag options. Don't know if VSCode will allow clang to try to work now that there is no cl.exe to auto switch to.

Something to try.

You can also download Visual Studio Build tools (standalone cl.exe) if it doesn't work and just want the errors to go away.

ZornTaov commented 2 years ago

I did a search for cl.exe and the only real occurances of it are from my installs of VS2017 and VS2019, along with the install of LLVM's clang-cl.exe. So I tried to set "C_Cpp.default.compilerPath": "\"C:\\Program Files\\LLVM\\bin\\clang-cl.exe\"" in my settings.json, but I don't think it worked. Every time I load up VSCode after telling unreal to refresh the project files, the C/C++ Compiler Warnings output spams [11/28/2021, 1:55:13 AM] Unable to resolve configuration with compilerPath "C:\Program". Using "cl.exe" instead. so really I don't know what is going on....

boocs commented 2 years ago

The VSCode cpptools extension is made by Microsoft so it knows where all the cl.exe are installed. It will use them even if you have the compilerPath option set.

This is because cpptools autodetects that the Unreal project's Intellisense is using cl.exe option flags. When it detects this it auto switches the compiler back to cl.exe.

ZornTaov commented 2 years ago

I was never able to figure out why the "missing coreminimal.h" fake error kept happening, but I've moved on from VSCode to Rider for Unreal since it's in a "free to use" preview period, so unless you want me to try anything else I'm going to just use it since it seems to just work. I do thank you for all your hard work, because if it weren't for this extension I may have given up trying to do C++ code with unreal.

boocs commented 2 years ago

I looked again at the pastebin and you're not using the Default Intellisense for the file you logged. You're using the Tag Parser Intellisense.

Are you using my other extension that removes Default Intellisense from header files? If so you should disable it temporarily or set the extension to All Files Use Default Intellisense to see if the error changes. You can then redo the log and use pastebin.

If you're not using my extension then you need the change the VSCode cpptools extension's Intellisense Engine setting to use Default Intellisense.

That said I still don't get there error in either Intellisense Engine mode so it must be some setting that's causing it.

boocs commented 2 years ago

I'll fix Windows clang use in the next release.

Not sure if it'll help your bug though. Hopefully Rider is treating you well.

The fix won't be automatic. It'll be a command you run after the extension is done loading.

It detects a blank, cl.exe, or clang.exe from the VSCode compiler path setting.

Changes the intellisenseMode to the correct setting. Will check CPU to set correct 32bit/64bit setting. Will change compile commands file to use the correct compiler name. Will change response file to use the correct compiler flags.

No ETA when it'll be done.

Edit: I just realized that if I modify the compile commands I'll have to run this fix on startup instead of making it a command. Will try to see if it works without modifying compile commands first.