public CppInclusionContextResult CreateInclusionContextResult(CppGlobalSymbolCache cache, CppFileLocation rootFile, FileProcessingOptions options, long cacheVersion, Lifetime lifetime) { var locationTracker = cache.Solution.GetComponent <ShaderLabCppFileLocationTracker>(); if (!locationTracker.IsValid(rootFile)) { return(CppInclusionContextResult.Fail(CppInclusionContextResult.Status.UNSUITABLE_PROJECT_FILE)); } var properties = new CppCompilationProperties() { LanguageKind = CppLanguageKind.HLSL, ClrSupport = VCXCompileAsManagedOptions.ManagedNotSet, }; var cgIncludeFolder = CgIncludeDirectoryTracker.GetCgIncludeFolderPath(cache.Solution.GetComponent <UnityVersion>()); if (!cgIncludeFolder.IsEmpty) { properties.IncludePaths.Add(cgIncludeFolder); } var shaderCache = cache.Solution.GetComponent <ShaderLabCppFileLocationTracker>(); // TODO 1) is cache ready? what will happen under document transaction? check for bad moment? // TODO 2) what will happen under psi transaction? include in cache could be out-of date. Try use include quickfix when cginclude is after cgprogram where QF is used var includeLocation = shaderCache.GetIncludes(rootFile); return(InjectInclusionContextProviderUtil.CreateInclusionContextResult(cache, rootFile, includeLocation, options, properties, null, cacheVersion, lifetime)); }
public CppCompilationProperties GetCompilationProperties(IProject project, IProjectFile projectFile, CppFileLocation rootFile, CppGlobalSymbolCache globalCache) { if (project.IsUnityProject() && CppProjectFileType.ALL_HLSL_EXTENSIONS.Contains(rootFile.Location.ExtensionWithDot)) { var properties = new CppCompilationProperties(); properties.LanguageKind = CppLanguageKind.HLSL; var path = CgIncludeDirectoryTracker.GetCgIncludeFolderPath(myUnityVersion); if (!path.IsEmpty) { properties.IncludePaths.Add(path); } return(properties); } return(null); }
public IEnumerable <CppFileLocation> GetIncludes(CppFileLocation cppFileLocation) { var sourceFile = cppFileLocation.GetRandomSourceFile(mySolution); var cgInclude = GetCgIncludeLocation(sourceFile); if (!cgInclude.Equals(CppFileLocation.EMPTY)) { yield return(cgInclude); } var cgIncludeFolder = CgIncludeDirectoryTracker.GetCgIncludeFolderPath(myUnityVersion); if (!cgIncludeFolder.ExistsDirectory) { yield break; } var range = cppFileLocation.RootRange; Assertion.Assert(range.IsValid, "range.IsValid"); var program = sourceFile.GetDominantPsiFile <ShaderLabLanguage>()?.GetContainingNodeAt <ICgContent>(new TreeOffset(range.StartOffset)); Assertion.Assert(program != null, "program != null"); if (program?.Parent?.FirstChild is ICgProgramBlock) { var hlslSupport = cgIncludeFolder.Combine("HLSLSupport.cginc"); if (hlslSupport.ExistsFile) { yield return(new CppFileLocation(hlslSupport)); } var variables = cgIncludeFolder.Combine("UnityShaderVariables.cginc"); if (variables.ExistsFile) { yield return(new CppFileLocation(variables)); } } }