public static CppFile GetCppFile(this IProject project, string filename) { FileSystemPath fileSystemPath = FileSystemPath.Parse(filename); if (fileSystemPath != null) { IPsiSourceFile file = project.GetPsiSourceFileInProject(fileSystemPath); if (file != null) { IEnumerable <IFile> files = file?.GetPsiFiles <CppLanguage>(); CppFile cppFile = files.SafeOfType <CppFile>().SingleOrDefault(); return(cppFile); } else { return(null); } //return file?.GetPsiFiles<CppLanguage>().SafeOfType<CppFile>().SingleOrDefault(); } else { return(null); } }
public bool SuppressUnresolvedErrors(CppFile cppFile, IContextBoundSettingsStore settingsStore) { if (!myUnitySolutionTracker.IsUnityProject.HasTrueValue()) { return(false); } if (mySuppressShaderErrorsInRenderPipeline.Value) { var location = cppFile.File; if (location.FullPath.Contains(".render-pipelines")) { return(true); } } return(mySuppressShaderErrors.Value); }
public void RandomizeAllFiles(string directory, string outDir) { // Every .h foreach (string str in Directory.EnumerateFiles(string.Concat(directory, "src/"), "*.h", SearchOption.AllDirectories)) { string str1 = str.Replace(string.Concat(directory, "src/"), ""); Directory.CreateDirectory(string.Concat(outDir, Path.GetDirectoryName(str1))); HeaderFile headerFile = new HeaderFile(str); headerFile.AddJunkCode(); File.WriteAllText(string.Concat(outDir, str1), headerFile.GetData()); } // Every .cpp foreach (string str2 in Directory.EnumerateFiles(string.Concat(directory, "src/"), "*.cpp", SearchOption.AllDirectories)) { string str3 = str2.Replace(string.Concat(directory, "src/"), ""); Directory.CreateDirectory(string.Concat(outDir, Path.GetDirectoryName(str3))); CppFile cppFile = new CppFile(str2); cppFile.AddJunkCode(); File.WriteAllText(string.Concat(outDir, str3), cppFile.GetData()); } }
public bool SuppressUnresolvedUnqualifiedErrors(CppFile cppFile, IContextBoundSettingsStore settingsStore) { return(SuppressUnresolvedErrors(cppFile, settingsStore)); }
public void AdjustLeadingAndTrailingWhitespaces(CppCodeFormatter cppCodeFormatter, CppFile cppFile) { var cgProgram = (cppFile.Parent as IInjectedFileHolder)?.OriginalNode.PrevSibling; var s = ShaderLabCppFormatterExtension.GetIndentInCgProgram(cgProgram); cppCodeFormatter.RemoveLeadingSpacesInFile(cppFile); cppCodeFormatter.RemoveTrailingSpaces(cppFile); var lineEnding = cppFile.DetectLineEnding(cppFile.GetPsiServices()); LowLevelModificationUtil.AddChildBefore(cppFile.firstChild, cppCodeFormatter.CreateNewLine(lineEnding), cppCodeFormatter.CreateSpace(s, null)); LowLevelModificationUtil.AddChildAfter(cppFile.lastChild, cppCodeFormatter.CreateNewLine(lineEnding), cppCodeFormatter.CreateSpace(s, null)); }
/*public override void Resolve() * { * // List all namespaces * IEnumerable<Namespace> namespaces = Files.SelectMany(f => f.Namespaces); * for (; ;) * { * IEnumerable<Namespace> subNamespaces = namespaces.SelectMany(n => n.Namespaces).Except(namespaces); * if (!subNamespaces.Any()) * break; * namespaces = namespaces.Concat(subNamespaces); * } * Namespaces.Clear(); * Namespaces.AddRange(namespaces); * * // List all types * IEnumerable<Type> types = Files.SelectMany(f => f.Types).Concat(Namespaces.SelectMany(n => n.Types)); * for (; ;) * { * IEnumerable<Type> subTypes = types.SelectMany(t => t.Types).Where(t => t.Name != "").Except(types); * if (!subTypes.Any()) * break; * types = types.Concat(subTypes); * } * Types.Clear(); * Types.AddRange(types); * * // Merge namespaces * for (int i = 0; i < Namespaces.Count; i++) * { * CppNamespace currentNamespace = Namespaces[i] as CppNamespace; * List<Namespace> otherNamespaces = Namespaces.Where(n => n != currentNamespace && n.Equals(currentNamespace)).ToList(); * * currentNamespace.Namespaces.AddRange(otherNamespaces.SelectMany(n => n.Namespaces) * .Select(n => { n.Parent = currentNamespace; return n; }) * .ToList()); * currentNamespace.Types.AddRange(otherNamespaces.SelectMany(n => n.Types) * .Select(t => { t.Parent = currentNamespace; return t; }) * .ToList()); * * foreach (Namespace nameSpace in Namespaces) * foreach (Namespace otherNamespace in otherNamespaces) * nameSpace.Namespaces.Remove(otherNamespace); * * foreach (Namespace otherNamespace in otherNamespaces) * Namespaces.Remove(otherNamespace); * } * foreach (Namespace ns in Namespaces) * if (ns.Parent is Namespace) * ns.Parent = Namespaces.First(n => n.Name == ns.Parent.Name); * foreach (Type type in Types) * if (type.Parent is Type) * type.Parent = Types.First(t => t.Name == type.Parent.Name); * * // Methods * IEnumerable<Method> methods = types.SelectMany(t => t.Methods); * IEnumerable<Method> statics = types.SelectMany(t => t.Methods).Where(m => (m.Modifiers & Modifiers.Static) == Modifiers.Static); * * // Resolve everything * foreach (File f in Files) * f.Resolve(Types); * * // Remove getters and setters * /*foreach (Type type in Types) * { * foreach (Field field in type.Fields) * { * if (field.GetAccessor != null) * type.Methods.Remove(field.GetAccessor); * if (field.SetAccessor != null) * type.Methods.Remove(field.SetAccessor); * } * }*/ /*}*/ private CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data) { if (!units.ContainsKey(parent)) { CXCursorKind parentKind = clang.getCursorKind(parent); string parentName = clang.getCString(clang.getCursorSpelling(parent)); if (parentKind != CXCursorKind.CXCursor_TranslationUnit) { throw new Exception("Root parents must be translation units"); } CppFile file = new CppFile(parentName); files.Add(file); units.Add(parent, file); } CXCursorKind kind = clang.getCursorKind(cursor); switch (kind) { case CXCursorKind.CXCursor_Namespace: return(VisitNamespace(cursor, parent, data)); case CXCursorKind.CXCursor_ClassDecl: case CXCursorKind.CXCursor_StructDecl: case CXCursorKind.CXCursor_EnumDecl: case CXCursorKind.CXCursor_TypedefDecl: case CXCursorKind.CXCursor_UnionDecl: case CXCursorKind.CXCursor_ClassTemplate: return(VisitType(cursor, parent, data)); case CXCursorKind.CXCursor_CXXAccessSpecifier: return(VisitTypeModifier(cursor, parent, data)); case CXCursorKind.CXCursor_EnumConstantDecl: return(VisitEnumConstant(cursor, parent, data)); case CXCursorKind.CXCursor_FieldDecl: case CXCursorKind.CXCursor_MemberRef: case CXCursorKind.CXCursor_VarDecl: return(VisitField(cursor, parent, data)); case CXCursorKind.CXCursor_Constructor: case CXCursorKind.CXCursor_Destructor: case CXCursorKind.CXCursor_CXXMethod: case CXCursorKind.CXCursor_FunctionDecl: case CXCursorKind.CXCursor_FunctionTemplate: return(VisitMethod(cursor, parent, data)); case CXCursorKind.CXCursor_TemplateTypeParameter: case CXCursorKind.CXCursor_NonTypeTemplateParameter: return(VisitTemplateParameter(cursor, parent, data)); case CXCursorKind.CXCursor_ParmDecl: return(VisitMethodParameter(cursor, parent, data)); case CXCursorKind.CXCursor_FirstDecl: case CXCursorKind.CXCursor_TypeRef: case CXCursorKind.CXCursor_NamespaceRef: case CXCursorKind.CXCursor_CompoundStmt: break; default: break; } return(CXChildVisitResult.CXChildVisit_Continue); }
public bool SuppressUnresolvedErrors(CppFile cppFile, IContextBoundSettingsStore settingsStore) { return(settingsStore.GetValue((UnitySettings k) => k.SuppressShaderErrorHighlighting)); }