Exemplo n.º 1
0
 public AutocompleteInfo(int arg_index, Parser.Command command_node, Parser.ASTNode ast_node)
 {
     ArgIndex    = arg_index;
     CommandNode = command_node;
     ASTNode     = ast_node;
     if (ASTNode != null)
     {
         LastCharIndex  = ASTNode.Position.LastChar;
         FirstCharIndex = ASTNode.Position.FirstChar;
     }
     else
     {
         LastCharIndex  = CommandNode.Position.LastChar;
         FirstCharIndex = CommandNode.Position.FirstChar;
     }
 }
Exemplo n.º 2
0
        private AutocompleteInfo _GetAutocompleteInfo(Parser.Command cmd)
        {
            var inbox = ConsoleMenu.Instance.InputBox;

            var cursor_pos = inbox.CursorIndex; // CursorIndex is 0 based

            // TODO
            // tabbing at: e|[[echo e]cho cho] a b
            // weirdly jumps

            for (int i = 0; i < cmd.Name.Content.Count; i++)
            {
                var node = cmd.Name.Content[i];

                if (node is Parser.Command && _CharFitsInASTNode(cursor_pos, node, tight: true))
                {
                    // forget that shit, just autocomplete this command thank you very much
                    return(_GetAutocompleteInfo((Parser.Command)node));
                }
            }

            if (_CharFitsInASTNode(cursor_pos, cmd.Name))
            {
                return(new AutocompleteInfo(0, cmd, cmd.Name));
            }

            if (cmd.Args.Count >= 1)
            {
                if (_CharFitsBetweenASTNodes(cursor_pos, cmd.Name, cmd.Args[0]))
                {
                    return(new AutocompleteInfo(1, cmd, cmd.Args[0]));
                }
                else
                {
                    int arg_index = 1;
                    for (int i = 0; i < cmd.Args.Count; i++)
                    {
                        for (int j = 0; j < cmd.Args[i].Content.Count; j++)
                        {
                            var node = cmd.Args[i].Content[j];

                            if (node is Parser.Command && _CharFitsInASTNode(cursor_pos, node, tight: true))
                            {
                                return(_GetAutocompleteInfo((Parser.Command)node));
                            }
                        }

                        var arg = cmd.Args[i];
                        if (_CharFitsInASTNode(cursor_pos, arg))
                        {
                            return(new AutocompleteInfo(arg_index, cmd, arg));
                        }

                        if ((i + 1) < cmd.Args.Count && _CharFitsBetweenASTNodes(cursor_pos, arg, cmd.Args[i + 1]))
                        {
                            return(new AutocompleteInfo(arg_index, cmd, cmd.Args[i + 1]));
                        }

                        arg_index += 1;
                    }
                }
            }

            return(new AutocompleteInfo(cmd.Args.Count, cmd, null));
        }