public FileSystemCompletionHelper( CompletionProvider completionProvider, TextSpan textChangeSpan, ICurrentWorkingDirectoryDiscoveryService fileSystemDiscoveryService, Glyph folderGlyph, Glyph fileGlyph, ImmutableArray <string> searchPaths, IEnumerable <string> allowableExtensions, Func <string, bool> exclude = null, CompletionItemRules itemRules = null) { Debug.Assert(searchPaths.All(path => PathUtilities.IsAbsolute(path))); _completionProvider = completionProvider; _textChangeSpan = textChangeSpan; _searchPaths = searchPaths; _allowableExtensions = allowableExtensions.Select(e => e.ToLowerInvariant()).ToSet(); _fileSystemDiscoveryService = fileSystemDiscoveryService; _folderGlyph = folderGlyph; _fileGlyph = fileGlyph; _exclude = exclude; _itemRules = itemRules; _lazyGetDrives = new Lazy <string[]>(() => IOUtilities.PerformIO(Directory.GetLogicalDrives, SpecializedCollections.EmptyArray <string>())); }
private bool ShouldShow(FileSystemInfo child) { // Get the attributes. If we can't, assume it's hidden. var attributes = IOUtilities.PerformIO(() => child.Attributes, FileAttributes.Hidden); // Don't show hidden/system files. if ((attributes & FileAttributes.Hidden) != 0 || (attributes & FileAttributes.System) != 0) { return(false); } if (child is DirectoryInfo) { return(true); } if (child is FileInfo) { return (_allowableExtensions.Count == 0 || _allowableExtensions.Contains(Path.GetExtension(child.Name).ToLowerInvariant())); } return(false); }
private bool CanAccessDirectory(DirectoryInfo directory) { var accessControl = IOUtilities.PerformIO(directory.GetAccessControl); // Quick and dirty check. If we can't even get the access control object, then we // can't access the file. if (accessControl == null) { return(false); } // TODO(cyrusn): Do more checks here. return(true); }
private bool CanAccessFile(FileInfo file) { var accessControl = IOUtilities.PerformIO(file.GetAccessControl); // Quick and dirty check. If we can't even get the access control object, then we // can't access the file. if (accessControl == null) { return(false); } // TODO(cyrusn): Actually add checks here. return(true); }
private IEnumerable <CompletionItem> GetFilesAndDirectoriesInDirectory(string fullDirectoryPath) { Debug.Assert(PathUtilities.IsAbsolute(fullDirectoryPath)); if (IOUtilities.PerformIO(() => Directory.Exists(fullDirectoryPath))) { var directoryInfo = IOUtilities.PerformIO(() => new DirectoryInfo(fullDirectoryPath)); if (directoryInfo != null) { return(from child in GetFileSystemInfos(directoryInfo) where ShouldShow(child) where CanAccess(child) select this.CreateCompletion(child)); } } return(SpecializedCollections.EmptyEnumerable <CompletionItem>()); }
private static FileSystemInfo[] GetFileSystemInfos(DirectoryInfo directoryInfo) { return(IOUtilities.PerformIO(directoryInfo.GetFileSystemInfos, SpecializedCollections.EmptyArray <FileSystemInfo>())); }
private static bool IsDriveRoot(string fullPath) { return(IOUtilities.PerformIO(() => new DirectoryInfo(fullPath).Parent == null)); }
private static FileSystemInfo[] GetFileSystemInfos(DirectoryInfo directoryInfo) { return(IOUtilities.PerformIO(directoryInfo.GetFileSystemInfos, Array.Empty <FileSystemInfo>())); }