UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SourceFileProject.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
8
9namespace uLang
10{
11
12struct SPackageDesc;
13
18{
19public:
21 : _FilePath(Move(FilePath))
22 , _FileSystem(FileSystem)
23 {
24 ClearLineIndexCache();
25 }
26
27 // This mimics what Unreal allows for package names, except that we allow periods in filenames as well.
28 static constexpr char _InvalidSnippetCharacters[] = "\\:*?\"<>|' ,&!~\n\r\t@#";
29
30 //~ Begin ISourceSnippet interface
31 virtual CUTF8String GetPath() const override { return _FilePath; }
32 virtual void SetPath(const CUTF8String& Path) override { _FilePath = Path; }
33 VERSECOMPILER_API virtual TOptional<CUTF8String> GetText() const override;
34 virtual TOptional<uLang::TSRef<Verse::Vst::Snippet>> GetVst() const override { return _Vst; }
35 virtual void SetVst(TSRef<Verse::Vst::Snippet> Snippet) override { _Vst = Snippet; };
36 //~ End ISourceSnippet interface
37
38 const CUTF8StringView& GetFilePath() const { return _FilePath; }
39
40 bool HasModifiedText() const { return _ModifiedText.IsSet(); }
41 const CUTF8StringView& GetModifiedText() const { return *_ModifiedText; }
42 void SetModifiedText(const CUTF8StringView& Text) { _ModifiedText = Text; }
43 void UnsetModifiedText() { _ModifiedText = EResult::Unspecified; }
44
45 operator const CUTF8String&() const { return _FilePath; } // For set/map lookup
46
48
49 // DeadLine represents the first line we know is invalid.
50 // Lines before that are still ok for the offset cache.
52 {
53 TruncateLineIndexCache(MinDeadLine);
54 _SnippetVersion++;
55 }
56
57 bool IsSnippetValid(Verse::Vst::Snippet& Snippet) const override { return _SnippetVersion == Snippet._SnippetVersion; }
58 uint64_t GetSourceVersion() const override { return _SnippetVersion; }
59
60private:
61 void ClearLineIndexCache() { _LineIndexCache.SetNumZeroed(1, false); }
62 void TruncateLineIndexCache(int32_t DeadLine) { DeadLine = std::max(DeadLine, 1); if (DeadLine < _LineIndexCache.Num()) _LineIndexCache.SetNum(DeadLine, false); }
63
64 CUTF8String _FilePath; // Path on disk
65 TOptional<CUTF8String> _ModifiedText; // Version of the file content that was edited in memory, if exists
66 TSRef<IFileSystem> _FileSystem;
67
69 uint64_t _SnippetVersion = 1; // This is analogous to the LSP file version, but not the same thing. The protocol doesn't version file changes to closed files
70
71 TArray<int64_t> _LineIndexCache; // File offset cache for each line in the file.
72};
73
78{
79public:
81 : CSourceModule(ModuleName), _FilePath(ModuleFilePath)
82 {}
84 : CSourceModule(ModuleName), _FilePath(Move(ModuleFilePath))
85 {}
86
87 virtual const CUTF8String& GetFilePath() const override { return _FilePath; }
89
92
95 bool RemoveSnippet(const uLang::TSRef<ISourceSnippet>& Snippet, bool bRecursive) { return CSourceModule::RemoveSnippet(Snippet, bRecursive); }
96
97private:
98
99 friend class CSourceFilePackage;
100
101 // Path to the module file on disk
102 // If no module file exists, this is the module directory with a slash `/` at the end
103 CUTF8String _FilePath;
104
105};
106
111{
112public:
113
116
117 virtual const CUTF8String& GetDirPath() const override { return _DirPath; }
118 virtual const CUTF8String& GetFilePath() const override { return _PackageFilePath; }
119 virtual EOrigin GetOrigin() const override { return EOrigin::FileSystem; }
120
123 VERSECOMPILER_API TOptional<TSRef<CSourceFileSnippet>> AddSnippet(const CUTF8StringView& FilePath); // Look up module by file path and add snippet to it - might fail if file path is not under root path
124 VERSECOMPILER_API bool RemoveSnippet(const CUTF8StringView& FilePath); // Look up module by file path and remove snippet from it
125
126private:
127 void ReadPackageFile(const CUTF8String& PackageFilePath, const TSRef<CDiagnostics>& Diagnostics);
128 TSRef<CSourceFileModule> ResolveModuleForRelativeVersePath(const CUTF8String& RelativeVersePath, const TSRef<CDiagnostics>& Diagnostics) const;
129 void GatherPackageSourceFiles(const CUTF8String& PackageFilePath, const TSRef<IFileSystem>& FileSystem, const TSRef<CDiagnostics>& Diagnostics);
130
131 CUTF8String _PackageFilePath;
132 CUTF8String _DirPath; // Can be the containing folder of the package file, or point somewhere else
133 TOptional<TArray<CUTF8String>> _FilePaths; // If set, use these _FilePaths for compilation instead of _DirPath (all _FilePaths must be under _DirPath)
134
135 const TSRef<IFileSystem> _FileSystem;
136};
137
142{
143public:
148
153
154 virtual const CUTF8String& GetFilePath() const override { return _FilePath; }
155
158
160 VERSECOMPILER_API TOptional<TSRef<CSourceFileSnippet>> AddSnippet(const CUTF8StringView& FilePath); // Look up module by file path and add snippet to it - might fail if file path is not under root path
161 VERSECOMPILER_API bool RemoveSnippet(const CUTF8StringView& FilePath); // Look up module by file path and remove snippet from it
162
163 VERSECOMPILER_API static bool IsSnippetFile(const CUTF8StringView& FilePath);
164 VERSECOMPILER_API static bool IsModuleFile(const CUTF8StringView& FilePath);
165 VERSECOMPILER_API static bool IsPackageFile(const CUTF8StringView& FilePath);
166 VERSECOMPILER_API static bool IsProjectFile(const CUTF8StringView& FilePath);
167 VERSECOMPILER_API static bool IsValidModuleName(const CUTF8StringView& ModuleName);
168 VERSECOMPILER_API static bool IsValidSnippetFileName(const CUTF8StringView& FileName);
169
170private:
171
172 CUTF8String _FilePath;
173 const TSRef<IFileSystem> _FileSystem;
174};
175
176}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition Array.h:670
Definition SourceFileProject.h:78
VERSECOMPILER_API TSRef< CSourceFileModule > FindOrAddSubmodule(const CUTF8StringView &ModuleName, const CUTF8StringView &DirPath)
Definition SourceFileProject.cpp:91
CSourceFileModule(const CUTF8StringView &ModuleName, const CUTF8StringView &ModuleFilePath)
Definition SourceFileProject.h:80
virtual const CUTF8String & GetFilePath() const override
Definition SourceFileProject.h:87
VERSECOMPILER_API CUTF8StringView GetDirPath() const
Definition SourceFileProject.cpp:78
VERSECOMPILER_API TOptional< TSRef< CSourceFileSnippet > > FindSnippetByFilePath(const CUTF8StringView &FilePath, bool bRecursive) const
Definition SourceFileProject.cpp:102
VERSECOMPILER_API TOptional< TSRef< CSourceFileModule > > FindSubmodule(const CUTF8StringView &ModuleName) const
Definition SourceFileProject.cpp:85
void AddSnippet(const uLang::TSRef< ISourceSnippet > &Snippet)
Definition SourceFileProject.h:94
CSourceFileModule(const CUTF8StringView &ModuleName, CUTF8String &&ModuleFilePath)
Definition SourceFileProject.h:83
bool RemoveSnippet(const uLang::TSRef< ISourceSnippet > &Snippet, bool bRecursive)
Definition SourceFileProject.h:95
Definition SourceFileProject.h:111
VERSECOMPILER_API TOptional< TSRef< CSourceFileSnippet > > FindSnippetByFilePath(const CUTF8StringView &FilePath) const
Definition SourceFileProject.cpp:232
VERSECOMPILER_API bool RemoveSnippet(const CUTF8StringView &FilePath)
Definition SourceFileProject.cpp:266
VERSECOMPILER_API CSourceFileModule * GetModuleForFilePath(const CUTF8StringView &FilePath)
Definition SourceFileProject.cpp:211
virtual EOrigin GetOrigin() const override
Definition SourceFileProject.h:119
virtual const CUTF8String & GetDirPath() const override
Definition SourceFileProject.h:117
virtual const CUTF8String & GetFilePath() const override
Definition SourceFileProject.h:118
VERSECOMPILER_API TOptional< TSRef< CSourceFileSnippet > > AddSnippet(const CUTF8StringView &FilePath)
Definition SourceFileProject.cpp:253
Definition SourceFileProject.h:142
VERSECOMPILER_API bool RemoveSnippet(const CUTF8StringView &FilePath)
Definition SourceFileProject.cpp:716
VERSECOMPILER_API TOptional< TSRef< CSourceFileSnippet > > AddSnippet(const CUTF8StringView &FilePath)
Definition SourceFileProject.cpp:702
virtual const CUTF8String & GetFilePath() const override
Definition SourceFileProject.h:154
static VERSECOMPILER_API bool IsValidModuleName(const CUTF8StringView &ModuleName)
Definition SourceFileProject.cpp:749
static VERSECOMPILER_API bool IsSnippetFile(const CUTF8StringView &FilePath)
Definition SourceFileProject.cpp:729
static VERSECOMPILER_API bool IsValidSnippetFileName(const CUTF8StringView &FileName)
Definition SourceFileProject.cpp:768
VERSECOMPILER_API bool WriteVSCodeWorkspaceFile(const CUTF8String &WorkspaceFilePath, const CUTF8String &ProjectFilePath, const TSRef< CDiagnostics > &Diagnostics)
Definition SourceFileProject.cpp:682
VERSECOMPILER_API bool WriteProjectFile(const CUTF8String &ProjectFilePath, const TSRef< CDiagnostics > &Diagnostics)
Definition SourceFileProject.cpp:676
static VERSECOMPILER_API bool IsModuleFile(const CUTF8StringView &FilePath)
Definition SourceFileProject.cpp:734
static VERSECOMPILER_API bool IsPackageFile(const CUTF8StringView &FilePath)
Definition SourceFileProject.cpp:739
static VERSECOMPILER_API bool IsProjectFile(const CUTF8StringView &FilePath)
Definition SourceFileProject.cpp:744
VERSECOMPILER_API TOptional< TSRef< CSourceFileSnippet > > FindSnippetByFilePath(const CUTF8StringView &FilePath) const
Definition SourceFileProject.cpp:688
Definition SourceFileProject.h:18
uint64_t GetSourceVersion() const override
Definition SourceFileProject.h:58
virtual void SetPath(const CUTF8String &Path) override
Definition SourceFileProject.h:32
const CUTF8StringView & GetFilePath() const
Definition SourceFileProject.h:38
CSourceFileSnippet(CUTF8String &&FilePath, const TSRef< IFileSystem > &FileSystem)
Definition SourceFileProject.h:20
TOptional< SIndexedSourceText > GetIndexedSourceText()
Definition SourceFileProject.cpp:60
bool IsSnippetValid(Verse::Vst::Snippet &Snippet) const override
Definition SourceFileProject.h:57
void SetModifiedText(const CUTF8StringView &Text)
Definition SourceFileProject.h:42
static constexpr char _InvalidSnippetCharacters[]
Definition SourceFileProject.h:28
void MarkDirty(int32_t MinDeadLine)
Definition SourceFileProject.h:51
virtual TOptional< uLang::TSRef< Verse::Vst::Snippet > > GetVst() const override
Definition SourceFileProject.h:34
bool HasModifiedText() const
Definition SourceFileProject.h:40
const CUTF8StringView & GetModifiedText() const
Definition SourceFileProject.h:41
virtual CUTF8String GetPath() const override
Definition SourceFileProject.h:31
virtual VERSECOMPILER_API TOptional< CUTF8String > GetText() const override
Definition SourceFileProject.cpp:23
virtual void SetVst(TSRef< Verse::Vst::Snippet > Snippet) override
Definition SourceFileProject.h:35
void UnsetModifiedText()
Definition SourceFileProject.h:43
Definition SourceProject.h:59
VERSECOMPILER_API void AddSnippet(const uLang::TSRef< ISourceSnippet > &Snippet)
Definition SourceProject.cpp:40
VERSECOMPILER_API bool RemoveSnippet(const uLang::TSRef< ISourceSnippet > &Snippet, bool bRecursive)
Definition SourceProject.cpp:47
Definition SourceProject.h:103
EOrigin
Where the source code of this package originates.
Definition SourceProject.h:212
@ FileSystem
Definition SourceProject.h:215
Definition SourceProject.h:275
Definition UTF8StringView.h:15
Definition SourceProject.h:21
Definition Array.h:51
Definition SharedPointer.h:77
Definition VVMEngineEnvironment.h:23
@ Unspecified
Not sure if success or failure.
uLang::TUTF8String< CHeapRawAllocator > CUTF8String
A string allocated on the heap.
Definition UTF8String.h:269
ULANG_FORCEINLINE TRemoveReference< T >::Type && Move(T &&Obj)
Definition References.h:86
Definition Optional.h:131
Definition VstNode.h:885
uint64_t _SnippetVersion
Definition VstNode.h:913
Definition SourceProjectWriter.h:17
Definition Optional.h:23