unreal-clangd
unreal-clangd copied to clipboard
UE 5.5+ support
It would be great to support UE 5.5. It is my daily engine and not having a reliable problem panel in VSCode is a real drag.
@tyen901 I'm not sure what you mean by "support UE 5.5", because I use the extension to fix problems when using VS Code + Clangd for Unreal Engine 5.5.4 on Ubuntu. However, there might be some problems with the extension, and that's due to the failure when I was trying to realize this on Windows.
Which OS are you using and what errors are you getting?
Based on the descriptions on the youtube videos and some of the documentation I was under the impression that 5.5 wasn't yet supported as there were issues with it.
Environment:
- Launcher installed UE 5.5.4
- OS: Windows_NT x64 10.0.19045
- Visual Studio Code 1.100.0-insider (user setup)
-
- C/C++ Extensions Pack
-
- C# Dev Kit
-
- clangd
-
- CMake tools
-
- Unreal clangd 2.6.1
- Visual Studio 2022 Community (.vsconfig attached)
- LLVM 18.1.0 and clangd.exe is available on my paths.
The problems I am encountering are that I get numerous false reports of errors. Such as in this example code.
#pragma once
#include "CoreMinimal.h"
#include "Interface/InterfaceBaseActor.h"
#include "Animation/AnimInstance.h"
#include "BaseActorAnimInstance.generated.h"
UCLASS()
class SIM_API UBaseActorAnimInstance : public UAnimInstance, public IInterfaceBaseActor
{
GENERATED_BODY()
};
The problems get these errors appearing.
message": "Unknown type name 'FID_sim_Source_Sim_Public_Entity_Actor_Animation_BaseActorAnimInstance_h_9_PROLOG'",
message": "Base class 'UAnimInstance' has private copy constructor",
message": "In implicit copy constructor for 'UBaseActorAnimInstance' first required here",
message": "Base class 'UAnimInstance' has private move constructor",
message": "In implicit move constructor for 'UBaseActorAnimInstance' first required here",
message": "A type specifier is required for all declarations",
Occasionally simple lines like this which are valid will report errors like
ULevelSequence* CopySequence = DuplicateObject<ULevelSequence>(SequenceTemplate, GetTransientPackage());
message": "No matching function for call to 'DuplicateObject'",
message": "Candidate function template not viable: cannot convert argument of incomplete type 'UPackage *' to 'UObject *' for 2nd argument",
message": "Candidate function template not viable: cannot convert argument of incomplete type 'UPackage *' to 'UObject *' for 2nd argument",
Hrm I'm dumb, I thought I had installed 5.5.4 and been testing that version but I still had 5.5.3!
Downloading and testing now. Sorry about that.
Just a note though. I've changed the recommened clangd version for Windows on the short docs page. Windows users should use clang-cl/clangd min 18.1.3 and max 18.1.8. This is pulled directly from th 5.5.# release notes.
May or may not solve your problem but you should upgrade anyway.
I'm using clangd 18.1.8 and was able to get it to work with no errors but might need so more info because I had to work a little to get it to work.
- What includes are in InterfaceBaseActor.h? I had to comment out this since I don't have this file and it worked after I did. So the errors must come from this file?
note: I had to change SIM_API to FPS5_5_4_API. Make sure not to use FPS5_5_4_API in your code since this macro name is specific to my project.
You can see below where I commented to code to get it to not error.
#pragma once
#include "CoreMinimal.h"
//#include "Interface/InterfaceBaseActor.h"
#include "Animation/AnimInstance.h"
#include "BaseActorAnimInstance.generated.h"
UCLASS()
class FPS5_5_4_API UBaseActorAnimInstance : public UAnimInstance//, public IInterfaceBaseActor
{
GENERATED_BODY()
};
-
ULevelSequence* CopySequence = DuplicateObject<ULevelSequence>(SequenceTemplate, GetTransientPackage()); GetTransientPackage() returns a UPackage* so you'd need to include the UPackage header to make that error go away. You can easily do this by typing UPackage on a blank line and letting the clangd auto header insertion add the header for you. Then you can delete the UPackage you just typed.
Include What You Use (IWYU) is best practice because even though the UPackage header is included somewhere in the sequence in the future it might not be and break your code. So it's better to include it specifically in your file. The header guards will prevent it from being copied twice.
Also for future users. When adding a module like LevelSequence, make sure, after you add it, to Build the extension and to run this extension's command Update Compile Commands to update intellisense files.
-
I had to restart VSCode after creating my clangd project to stop some errors from showing. I'll have to fix this in an extension update.
-
For future users, It could be that you need to run Build so that "BaseActorAnimInstance.generated.h" is created. Once you do you can type a random letter in the file and delete it so that clangd refreshes the file.
This gives my an idea for my extension to restart clangd's language server after every build.
I have updated to clangd 18.1.8.
I have created a bare minimal UE 5.5.4 project for our reference. https://github.com/tyen901/BareMinimalUnreal
For a while there I thought it was working as expected. However when adding Source\BareMinimal\Public\CustomDataAsset.h I was not able to get these errors to stop appearing. I set it up with IWYU but the issues persisted.
"Unknown type name 'FID_Users_Tyen_Documents_Unreal_Projects_BareMinimal_Source_BareMinimal_Public_CustomDataAsset_h_6_PROLOG'", "Base class 'UDataAsset' has private copy constructor", "In implicit copy constructor for 'UCustomDataAsset' first required here", "Base class 'UDataAsset' has private move constructor", "In implicit move constructor for 'UCustomDataAsset' first required here", "A type specifier is required for all declarations",
If you try opening that project and setting it up fresh, do you get those errors in that file too?
- Do you mean the CustomDataAsset.h file itself? I get no error with that file or any file in the BareMinimal project.
Or if you meant when trying to add the UCustomDataAsset class somewhere? I created one in BareMinimal.cpp with no errors. I'm actually not sure if this is how you create one but google's ai said this is how lol. I did have to add Package.h to prevent errors.
#include "BareMinimal.h"
#include "Public/CustomDataAsset.h"
#include "Modules/ModuleManager.h"
#include "UObject/Package.h"
UCustomDataAsset* test = NewObject<UCustomDataAsset>(GetTransientPackage(), UCustomDataAsset::StaticClass());
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, BareMinimal, "BareMinimal" );
-
Of course make sure you've Built your unreal project and run this extension's Update Compile Commands file just in case. Also when asked to reload after Updating CC, click Yes.
-
This might be a C++ library problem? You're using Visual Studio Community instead of the stand alone visual studio build tools. When you build what does it say your library versions are? When I build it says this in VSCode's Terminal:
Using Visual Studio 2022 14.38.33144 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130) and Windows 10.0.22621.0 SDK (C:\Program Files (x86)\Windows Kits\10).
Newer libraries can cause problems with clangd which your Visual Studio Community could be using. In the Unreal 5.5 release notes it says 14.38 and 10.0.22621.0 are 'default' but you can use newer versions. We have to be wary though, since they didn't think we were going to be using cl to build and clang-cl/clangd for intellisense.
I'll be testing this tomorrow if you don't want to test it.
Using Visual Studio Build Tools 2022 I had Visual Studio Installer add C++ libraries above 14.38. I couldn't get my project to use them(using this extensions Update Compile Commands command). Even uninstalling 14.38 would cause an error when running the Update CC command, saying that it couldn't find 14.38. That was surprising.
That Windows SDK was already the latest one except mine uses the Window 11 version with the same version number of the Windows 10 version.
I would really like to know which versions you are using. Maybe when Visual Build Tools 2022 isn't installed, like in your case, it makes exceptions on which versions it can use.
When I build I get this in the terminal
Using Visual Studio 2022 14.38.33145 toolchain (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130) and Windows 10.0.22621.0 SDK (C:\Program Files (x86)\Windows Kits\10).
This is my current vsconfig as of right this moment.
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.Net.Component.4.8.SDK",
"Microsoft.Net.Component.4.7.2.TargetingPack",
"Microsoft.Net.ComponentGroup.DevelopmentPrerequisites",
"Microsoft.VisualStudio.Component.TypeScript.TSServer",
"Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions",
"Microsoft.VisualStudio.Component.JavaScript.TypeScript",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.Component.MSBuild",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices",
"Microsoft.VisualStudio.Component.TextTemplating",
"Microsoft.VisualStudio.Component.NuGet",
"Microsoft.VisualStudio.Component.SQL.CLR",
"Microsoft.Component.ClickOnce",
"Microsoft.VisualStudio.Component.ManagedDesktop.Core",
"Microsoft.NetCore.Component.Runtime.9.0",
"Microsoft.NetCore.Component.Runtime.8.0",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.FSharp",
"Microsoft.ComponentGroup.ClickOnce.Publish",
"Microsoft.NetCore.Component.DevelopmentTools",
"Microsoft.Net.Component.4.8.TargetingPack",
"Microsoft.Net.ComponentGroup.4.8.DeveloperTools",
"Microsoft.VisualStudio.Component.DiagnosticTools",
"Microsoft.VisualStudio.Component.EntityFramework",
"Microsoft.VisualStudio.Component.Debugger.JustInTime",
"Component.Microsoft.VisualStudio.LiveShare.2022",
"Microsoft.VisualStudio.Component.IntelliCode",
"Component.VisualStudio.GitHub.Copilot",
"Microsoft.Net.Component.4.6.2.TargetingPack",
"Microsoft.Net.Component.4.8.1.SDK",
"Microsoft.VisualStudio.Component.VC.CoreIde",
"Microsoft.VisualStudio.Component.Windows10SDK",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.Component.Graphics.Tools",
"Microsoft.VisualStudio.Component.VC.DiagnosticTools",
"Microsoft.VisualStudio.Component.Windows11SDK.22621",
"Microsoft.VisualStudio.Component.ManagedDesktop.Prerequisites",
"Microsoft.VisualStudio.Component.DotNetModelBuilder",
"Microsoft.ComponentGroup.Blend",
"Microsoft.VisualStudio.Workload.ManagedDesktop",
"Microsoft.VisualStudio.Component.VC.ATL",
"Microsoft.VisualStudio.Component.VC.Redist.14.Latest",
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"Microsoft.VisualStudio.Component.Windows11Sdk.WindowsPerformanceToolkit",
"Microsoft.VisualStudio.Component.CppBuildInsights",
"Microsoft.VisualStudio.Component.VC.TestAdapterForBoostTest",
"Microsoft.VisualStudio.Component.VC.TestAdapterForGoogleTest",
"Microsoft.VisualStudio.Component.VC.ASAN",
"Microsoft.VisualStudio.Component.Vcpkg",
"Microsoft.VisualStudio.Component.Windows10SDK.18362",
"Microsoft.VisualStudio.Workload.NativeDesktop",
"Microsoft.VisualStudio.Component.HLSL",
"Microsoft.VisualStudio.Workload.NativeGame",
"Microsoft.NetCore.Component.Runtime.6.0",
"Microsoft.Net.Component.4.6.1.TargetingPack",
"Microsoft.VisualStudio.Component.VC.14.38.17.8.x86.x64",
"Microsoft.VisualStudio.Component.VC.14.38.17.8.ATL",
"Microsoft.VisualStudio.Component.VC.14.38.17.8.CLI.Support"
],
"extensions": []
}
- Do you mean the CustomDataAsset.h file itself? I get no error with that file or any file in the BareMinimal project.
Or if you meant when trying to add the UCustomDataAsset class somewhere? I created one in BareMinimal.cpp with no errors. I'm actually not sure if this is how you create one but google's ai said this is how lol. I did have to add Package.h to prevent errors.
I mean when you open the CustomDataAsset.h file itself. I get the errors in the problems panel
Unknown type name 'FID_Users_Tyen_Documents_Unreal_Projects_BareMinimal_Source_BareMinimal_Public_CustomDataAsset_h_6_PROLOG'
Base class 'UDataAsset' has private copy constructor
In implicit copy constructor for 'UCustomDataAsset' first required here
Base class 'UDataAsset' has private move constructor
In implicit move constructor for 'UCustomDataAsset' first required here
A type specifier is required for all declarations
Hrm, and I don't get errors. Strange!
-
Close CustomDataAsset.h
-
Go to BareMinimal.code-workspace and change clangd.arguments so that the -log= says -log=verbose
-
Restart VSCode and let completionHelper.cpp load all the way (includes will be underlined)
-
Go to Output and change it to clangd
-
In the picture above click the icon to the right of clangd (which clears the log output)
-
Now open CustomDataAsset.h (edit: make sure it's closed before doing this)
-
Try not to hover over any code because you'll get hover info in the log
-
Once the log stops moving do ctrl+A to select all of the log and use https://pastebin.com/ and send me the link. You don't need to log into pastbin to use it
I tried to create the output log as clean as possible. You're right about hovering over code, it does dump a lot into the console.
https://pastebin.com/5GKJ1Dma
I get the same errors after I've deleted CustomDataAsset.generated.h so something must be wrong with that file.
Delete your Intermediate/Build folder and Build again. I tried just deleting CustomDataAsset.generated.h but it didn't work and wouldn't recreate it. Had to delete the Build folder.
Restart VSCode or run the command 'clangd: restart language server'
Oh and I forgot that clangd pulls which c++ library to use from a environmental variable and the logs show us both using 14.43 for intellisense.
Not sure if it's good or bad to be using a different library for Building and another for intellisense. Of course people might hate the fact were using cl for Building and clang-cl for intellisense....
You can 'easily' force clangd to use the library you want by following these directions: https://github.com/boocs/unreal-clangd?tab=readme-ov-file#bug-older-unreal-versions-with-newer-c-libraries-windows-only
I like the .clangd modification version.
This is optional and just a fyi.
Oh and those directions are for 5.4.# and has the wrong Windows SDK version for use with 5.5.#. So if you do want to do the above, make sure to use the correct Windows SDK for your Unreal version
Edit: And pay attention to step 9 as 5.5 has an additional include you need to add to .clangd
Sorry for adding stuff to this thread that had nothing to do with your original question!
Edited with more updated info
For you and future users that see this. The environment variable was wrong see: https://clangd.llvm.org/guides/system-headers
You can run this command in powershell to see what your auto system includes will be:
$null | clang -v -E -xc++ - in powershell (the $null | prevents having to use ctrl+c to exit to terminal)
It'll log a bunch of stuff and then say this:
clang -cc1 version 18.1.8 based upon LLVM 18.1.8 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\atlmfc\include"
#include "..." search starts here:
#include <...> search starts here:
C:\Program Files\LLVM\lib\clang\18\include
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\include
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\um
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\winrt
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\cppwinrt
End of search list.
Maybe I can use this to create a Custom System Includes extension command. Command would give you a list of versions to choose for C++ library and Windows SDK.
note: As you see clang thinks there is a directory "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\atlmfc\include" but there really isn't. It'll actually include this as a system include in Unreal 5.5 even though it doesn't exist. That's what tripped me up when I created that step 9. Saw it in the clangd logs but not actually checking if it exists.
im getting this exception when generating project files for vscode, is it just me? didnt seem to occur in 5.4.
Generating VisualStudioCode project files:
Discovering modules, targets and source code for project...
Binding IntelliSense data...
Exception while generating include data for UnrealEditor: System.ArgumentNullException: Value cannot be null. (Parameter 'element')
at System.ArgumentNullException.Throw(String paramName)
at System.Attribute.GetCustomAttributes(MemberInfo element, Type attributeType, Boolean inherit)
at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](MemberInfo element)
at UnrealBuildTool.ModuleRules.IsValidForTarget(Type moduleType, ReadOnlyTargetRules targetRules, String& invalidReason) in C:\UE_5.5\Engine\Source\Programs\UnrealBuildTool\Configuration\ModuleRules.cs:line 1680