Esempio n. 1
0
        private static Func <FormattingContext, bool> InFunctionStatementOnOneLine(Side side)
        {
            return((FormattingContext formattingContext) =>
            {
                ParsedToken parsedToken = GetTokenOn(side, formattingContext);
                SourceText sourceText = formattingContext.SourceText;

                int start;
                int end;

                if (parsedToken.UpperStatementNode.Kind == SyntaxKind.GlobalFunctionStatementNode)
                {
                    GlobalFunctionStatementNode function = (GlobalFunctionStatementNode)parsedToken.UpperStatementNode;
                    start = function.FunctionKeyword.Start;
                    end = function.FuncBody.EndKeyword.Start;

                    return sourceText.GetLineNumberFromIndex(start) == sourceText.GetLineNumberFromIndex(end);
                }
                else if (parsedToken.UpperStatementNode.Kind == SyntaxKind.LocalFunctionStatementNode)
                {
                    LocalFunctionStatementNode function = (LocalFunctionStatementNode)parsedToken.UpperStatementNode;
                    start = function.LocalKeyword.Start;
                    end = function.FuncBody.EndKeyword.Start;

                    return sourceText.GetLineNumberFromIndex(start) == sourceText.GetLineNumberFromIndex(end);
                }

                return false;
            });
        }
Esempio n. 2
0
        private static Func <FormattingContext, bool> InForLoopOnSameLine(Side side)
        {
            return((FormattingContext formattingContext) =>
            {
                ParsedToken parsedToken = GetTokenOn(side, formattingContext);
                SourceText sourceText = formattingContext.SourceText;

                int start;
                int end;

                if (parsedToken.UpperStatementNode.Kind == SyntaxKind.SimpleForStatementNode)
                {
                    SimpleForStatementNode forStatement = (SimpleForStatementNode)parsedToken.UpperStatementNode;
                    start = forStatement.ForKeyword.Start;
                    end = forStatement.EndKeyword.Start;

                    return sourceText.GetLineNumberFromIndex(start) == sourceText.GetLineNumberFromIndex(end);
                }
                else if (parsedToken.UpperStatementNode.Kind == SyntaxKind.MultipleArgForStatementNode)
                {
                    MultipleArgForStatementNode forStatement = (MultipleArgForStatementNode)parsedToken.UpperStatementNode;
                    start = forStatement.ForKeyword.Start;
                    end = forStatement.EndKeyword.Start;

                    return sourceText.GetLineNumberFromIndex(start) == sourceText.GetLineNumberFromIndex(end);
                }

                return false;
            });
        }