예제 #1
0
        private static bool CompleteAgainstStatementFlags(Ast scriptAst, Ast lastAst, Token token, out TokenKind kind)
        {
            Func <Ast, bool> predicate = null;

            kind = TokenKind.Unknown;
            ErrorStatementAst ast = lastAst as ErrorStatementAst;

            if (((ast != null) && (ast.Kind != null)) && (ast.Kind.Kind == TokenKind.Switch))
            {
                kind = TokenKind.Switch;
                return(true);
            }
            ScriptBlockAst ast2 = scriptAst as ScriptBlockAst;

            if (((token != null) && (token.Kind == TokenKind.Minus)) && (ast2 != null))
            {
                Tuple <Token, Ast> tuple;
                if (predicate == null)
                {
                    predicate = a => IsCursorBeforeExtent(token.Extent.StartScriptPosition, a.Extent);
                }
                Ast parent = AstSearcher.FindAll(ast2, predicate, true).LastOrDefault <Ast>();
                ast = null;
                while (parent != null)
                {
                    ast = parent as ErrorStatementAst;
                    if (ast != null)
                    {
                        break;
                    }
                    parent = parent.Parent;
                }
                if ((((ast != null) && (ast.Kind != null)) && ((ast.Kind.Kind == TokenKind.Switch) && (ast.Flags != null))) && (ast.Flags.TryGetValue("--%", out tuple) && IsTokenTheSame(tuple.Item1, token)))
                {
                    kind = TokenKind.Switch;
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        internal CompletionContext CreateCompletionContext(ExecutionContext executionContext)
        {
            Func <Token, bool> predicate         = null;
            Func <Token, bool> func2             = null;
            Token           token                = null;
            IScriptPosition positionForAstSearch = this._cursorPosition;
            bool            flag   = false;
            Token           token2 = this._tokens.LastOrDefault <Token>(t => IsCursorWithinOrJustAfterExtent(this._cursorPosition, t.Extent) && IsInterestingToken(t));

            if (token2 == null)
            {
                if (predicate == null)
                {
                    predicate = t => IsCursorBeforeExtent(this._cursorPosition, t.Extent) && IsInterestingToken(t);
                }
                token = this._tokens.LastOrDefault <Token>(predicate);
                if (token != null)
                {
                    positionForAstSearch = token.Extent.EndScriptPosition;
                    flag = true;
                }
            }
            else
            {
                StringExpandableToken token3 = token2 as StringExpandableToken;
                if ((token3 != null) && (token3.NestedTokens != null))
                {
                    if (func2 == null)
                    {
                        func2 = t => IsCursorWithinOrJustAfterExtent(this._cursorPosition, t.Extent) && IsInterestingToken(t);
                    }
                    token2 = token3.NestedTokens.LastOrDefault <Token>(func2) ?? token3;
                }
            }
            IEnumerable <Ast> source = AstSearcher.FindAll(this._ast, ast => IsCursorWithinOrJustAfterExtent(positionForAstSearch, ast.Extent), true);

            return(new CompletionContext {
                TokenAtCursor = token2, TokenBeforeCursor = token, CursorPosition = this._cursorPosition, RelatedAsts = source.ToList <Ast>(), Options = this._options, ExecutionContext = executionContext, ReplacementIndex = flag ? this._cursorPosition.Offset : 0
            });
        }
예제 #3
0
 private static Ast GetLastAstAtCursor(ScriptBlockAst scriptBlockAst, IScriptPosition cursorPosition)
 {
     return(AstSearcher.FindAll(scriptBlockAst, ast => IsCursorRightAfterExtent(cursorPosition, ast.Extent), true).LastOrDefault <Ast>());
 }