From 1050e0eb96d6c8e7a6cfb253458155e1014625c3 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 5 Dec 2023 10:06:19 -0800 Subject: Support `include` for pulling file into the current module. (#3377) * Support `include` for pulling file into the current module. * Add auto-completion, hover info and goto-def support. * Disable warning for missing `module` declaration for now. --------- Co-authored-by: Yong He --- source/compiler-core/slang-include-system.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source/compiler-core/slang-include-system.cpp') diff --git a/source/compiler-core/slang-include-system.cpp b/source/compiler-core/slang-include-system.cpp index f0a850a81..1b768d506 100644 --- a/source/compiler-core/slang-include-system.cpp +++ b/source/compiler-core/slang-include-system.cpp @@ -113,15 +113,15 @@ SlangResult IncludeSystem::findFile(String const& pathToInclude, String const& p return SLANG_E_NOT_FOUND; } -SlangResult IncludeSystem::loadFile(const PathInfo& pathInfo, ComPtr& outBlob) +SlangResult IncludeSystem::loadFile(const PathInfo& pathInfo, ComPtr& outBlob, SourceFile*& outSourceFile) { if (m_sourceManager) { // See if this an already loaded source file - SourceFile* sourceFile = m_sourceManager->findSourceFileRecursively(pathInfo.uniqueIdentity); + outSourceFile = m_sourceManager->findSourceFileRecursively(pathInfo.uniqueIdentity); // If not create a new one, and add to the list of known source files - if (!sourceFile) + if (!outSourceFile) { ComPtr foundSourceBlob; if (SLANG_FAILED(m_fileSystemExt->loadFile(pathInfo.foundPath.getBuffer(), foundSourceBlob.writeRef()))) @@ -129,17 +129,17 @@ SlangResult IncludeSystem::loadFile(const PathInfo& pathInfo, ComPtr return SLANG_E_CANNOT_OPEN; } - sourceFile = m_sourceManager->createSourceFileWithBlob(pathInfo, foundSourceBlob); - m_sourceManager->addSourceFile(pathInfo.uniqueIdentity, sourceFile); + outSourceFile = m_sourceManager->createSourceFileWithBlob(pathInfo, foundSourceBlob); + m_sourceManager->addSourceFile(pathInfo.uniqueIdentity, outSourceFile); outBlob = foundSourceBlob; return SLANG_OK; } else { - if (sourceFile->getContentBlob()) + if (outSourceFile->getContentBlob()) { - outBlob = sourceFile->getContentBlob(); + outBlob = outSourceFile->getContentBlob(); return SLANG_OK; } @@ -149,7 +149,7 @@ SlangResult IncludeSystem::loadFile(const PathInfo& pathInfo, ComPtr return SLANG_E_CANNOT_OPEN; } - sourceFile->setContents(foundSourceBlob); + outSourceFile->setContents(foundSourceBlob); outBlob = foundSourceBlob; return SLANG_OK; @@ -158,6 +158,7 @@ SlangResult IncludeSystem::loadFile(const PathInfo& pathInfo, ComPtr else { // If we don't have the source manager, just load + outSourceFile = nullptr; return m_fileSystemExt->loadFile(pathInfo.foundPath.getBuffer(), outBlob.writeRef()); } } -- cgit v1.2.3