Exemple #1
0
        public static string[] FindPathsFromSelectedItems(UIHierarchyItem[] items, out Dictionary <string, string> fileToProjectMap)
        {
            fileToProjectMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            HashSet <string> tsconfigFiles = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (UIHierarchyItem selItem in items)
            {
                if (!LintableFiles.IsLintable(selItem))
                {
                    continue;
                }
                if (selItem.Object is Solution solution)
                {
                    FindTsconfigsInSolution(solution, tsconfigFiles);
                }
                else if (selItem.Object is Project project)
                {
                    FindTsconfigsInProject(project, tsconfigFiles);
                }
                else if (selItem.Object is ProjectItem item && item.GetFullPath() is string projectItemPath)
                {
                    FindTsconfigsFromSelectedProjectItem(projectItemPath, item, tsconfigFiles, fileToProjectMap);
                }
            }
            return(tsconfigFiles.ToArray());
        }
Exemple #2
0
        public static IEnumerable <string> FindPathsFromSelectedItems(UIHierarchyItem[] items)
        {
            HashSet <string> seenPaths = new HashSet <string>();

            foreach (UIHierarchyItem selItem in items)
            {
                if (!LintableFiles.IsLintable(selItem))
                {
                    continue;
                }
                IEnumerable <string> currentEnumerable =
                    selItem.Object is Solution solution?FindInSolution(solution) :
                        selItem.Object is Project project?FindInProject(project) :
                            (selItem.Object is ProjectItem projectItem) ?
                            FindInProjectItem(projectItem) : null;

                if (currentEnumerable == null)
                {
                    continue;
                }
                foreach (string path in currentEnumerable)
                {
                    if (!seenPaths.Contains(path))
                    {
                        seenPaths.Add(path);
                        yield return(path);
                    }
                }
            }
        }
        public static string[] FindFilterFiles(UIHierarchyItem[] items)
        {
            List <string> result = new List <string>();

            foreach (UIHierarchyItem selItem in items)
            {
                if (selItem.Object is ProjectItem item &&
                    item.GetFullPath() is string projectItemPath &&
                    LintableFiles.IsLintableTsOrTsxFile(projectItemPath))
                {
                    result.Add(projectItemPath);
                }
        private static void FindInProjectItem(ProjectItem projectItem, Dictionary <string, string> fileToProjectMap)
        {
            string itemPath = projectItem.GetFullPath();

            if (LintableFiles.IsLintableTsTsxJsJsxFile(itemPath) && !fileToProjectMap.ContainsKey(itemPath))
            {
                fileToProjectMap.Add(itemPath, projectItem.ContainingProject.Name);
            }
            if (projectItem.ProjectItems == null)
            {
                return;
            }
            foreach (ProjectItem subProjectItem in projectItem.ProjectItems)
            {
                FindInProjectItem(subProjectItem, fileToProjectMap);
            }
        }
        public static Tsconfig FindFromProjectItem(string projectItemFullPath)
        {
            DirectoryInfo folder = Directory.GetParent(projectItemFullPath);

            while (folder != null)
            {
                foreach (FileInfo fileInfo in folder.EnumerateFiles())
                {
                    if (LintableFiles.IsLintableTsconfig(fileInfo.FullName))
                    {
                        return(new Tsconfig(fileInfo.FullName));
                    }
                }
                folder = folder.Parent;
            }
            return(null);
        }
Exemple #6
0
        private static void FindTsConfigsInProjectItem(ProjectItem projectItem, HashSet <string> result)
        {
            string itemPath = projectItem.GetFullPath();

            if (LintableFiles.IsLintableTsconfig(itemPath) && !result.Contains(itemPath))
            {
                result.Add(itemPath);
            }
            // A project item can be a folder or a nested file, so we may need to continue searching down the tree
            if (projectItem.ProjectItems == null || LintableFiles.ContainsIgnorePattern(itemPath))
            {
                return;
            }
            foreach (ProjectItem subProjectItem in projectItem.ProjectItems)
            {
                FindTsConfigsInProjectItem(subProjectItem, result);
            }
        }
Exemple #7
0
 private static void FindTsconfigsFromSelectedProjectItem(string projectItemPath, ProjectItem item, HashSet <string> result,
                                                          Dictionary <string, string> fileToProjectMap)
 {
     if (LintableFiles.IsLintableTsTsxJsJsxFile(projectItemPath))
     {
         if (!fileToProjectMap.ContainsKey(projectItemPath))
         {
             fileToProjectMap.Add(projectItemPath, item.ContainingProject.Name);
         }
         string tsconfig = FindParentTsconfig(projectItemPath);
         if (tsconfig != null && !result.Contains(tsconfig))
         {
             result.Add(tsconfig);
         }
     }
     else if (item.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder || LintableFiles.IsLintableTsconfig(projectItemPath))
     {
         FindTsConfigsInProjectItem(item, result);
     }
 }
Exemple #8
0
        public static IEnumerable <string> FindInProjectItem(ProjectItem projectItem)
        {
            string itemPath = projectItem.GetFullPath();

            if (LintableFiles.IsLintableTsOrTsxFile(itemPath))
            {
                yield return(itemPath);
            }
            // Checking the ignore pattern here is an optimization that prevents us iterating ignored folders
            if (projectItem.ProjectItems == null || LintableFiles.ContainsIgnorePattern(itemPath))
            {
                yield break;
            }
            foreach (ProjectItem subProjectItem in projectItem.ProjectItems)
            {
                foreach (var item in FindInProjectItem(subProjectItem))
                {
                    yield return(item);
                }
            }
        }
 public static string[] FindPathsFromSelectedItems(UIHierarchyItem[] items, out Dictionary <string, string> fileToProjectMap)
 {
     fileToProjectMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
     foreach (UIHierarchyItem selItem in items)
     {
         if (!LintableFiles.IsLintable(selItem))
         {
             continue;
         }
         if (selItem.Object is Solution solution)
         {
             FindInSolution(solution, fileToProjectMap);
         }
         else if (selItem.Object is Project project)
         {
             FindInProject(project, fileToProjectMap);
         }
         else if (selItem.Object is ProjectItem item)
         {
             FindInProjectItem(item, fileToProjectMap);
         }
     }
     return(fileToProjectMap.Keys.ToArray());
 }