Example #1
0
        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)
            });
        }
Example #2
0
        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,
            }));
        }
Example #3
0
        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)));
        }
Example #4
0
        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);
        }
Example #5
0
        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,
                    });
                }
            }
        }