public HintResult getHint(string path, string line) { IList <HintItem> items = new List <HintItem>(); var ctx = new HintContext { CurrentDir = path, Line = line, LastSegment = line.Split(' ').Last(), }; foreach (var item in dic) { if (line.StartsWith(item.Key)) { items = item.Value.Invoke(ctx).ToList(); break; } } var words = items.Select(i => i.Word.ToLowerInvariant()).ToList(); return(new HintResult { Groups = items.GroupBy(item => item.Category), ResultCount = words.Count, CommonPrefix = getCommonPrefix(words) }); }
private static IEnumerable <HintItem> getGitCheckoutHint(HintContext context) { var branches = new List <string>(); branches.AddRange(GetGitBranches(context.CurrentDir)); return(branches.Where(name => name.StartsWith(context.LastSegment)).Select(name => new HintItem { Category = "Git " + (name.Contains('/') ? "Remote" : "Local") + " Branch", Word = name, })); }
private static IEnumerable <HintItem> getDirCmdHint(HintContext context) { var pattern = context.LastSegment; return(dirParameters .Where(item => item.Key.StartsWith(context.LastSegment)) .Select(item => new HintItem { Category = "dir parameters", Word = item.Key, Description = item.Value, }).Concat(getDirHint(context))); }
private static IEnumerable <HintItem> getDirHint(HintContext context) { var list = new List <HintItem>(); var pattern = context.LastSegment; string dirPath = context.CurrentDir; string pathInPattern = ""; if (pattern.Contains("/")) { return(list); } if (pattern.Contains("\\")) { var index = pattern.LastIndexOf('\\'); pathInPattern = pattern.Substring(0, index + 1); pattern = pattern.Substring(index + 1); dirPath = Path.Combine(context.CurrentDir, pathInPattern); if (!Directory.Exists(dirPath)) { return(Enumerable.Empty <HintItem>()); } } var di = new DirectoryInfo(dirPath); foreach (var item in di.EnumerateDirectories(pattern + "*")) { list.Add(new HintItem { Category = "Directory", Word = pathInPattern + item.Name, }); } foreach (var item in di.EnumerateFiles(pattern + "*")) { list.Add(new HintItem { Category = "File", Word = pathInPattern + item.Name, Description = FileTypeHelper.FileTypeInfo(item.FullName) }); } return(list); }
private static IEnumerable <HintItem> getGitHint(HintContext context) { var pattern = context.LastSegment; foreach (var cmd in gitCmds) { if (cmd.Key.StartsWith(pattern)) { yield return(new HintItem { Category = "git commands", Word = cmd.Key, Description = cmd.Value, }); } } }