コード例 #1
0
        public static bool TryGetCompletions(WithStatement withStatement, CompletionContext context, out CompletionResult result)
        {
            result = CompletionResult.Empty;

            if (context.Position > withStatement.HeaderIndex && withStatement.HeaderIndex > withStatement.StartIndex)
            {
                return(false);
            }

            foreach (var item in withStatement.Items.Reverse().MaybeEnumerate())
            {
                if (item.AsIndex > item.StartIndex)
                {
                    if (context.Position > item.AsIndex + 2)
                    {
                        return(true);
                    }

                    if (context.Position >= item.AsIndex)
                    {
                        var applicableSpan = new SourceSpan(context.IndexToLocation(item.AsIndex), context.IndexToLocation(item.AsIndex + 2));
                        result = new CompletionResult(Enumerable.Repeat(CompletionItemSource.AsKeyword, 1), applicableSpan);
                        return(true);
                    }
                }

                if (item.ContextManager != null && !(item.ContextManager is ErrorExpression))
                {
                    if (context.Position > item.ContextManager.EndIndex && item.ContextManager.EndIndex > item.ContextManager.StartIndex)
                    {
                        result = result = new CompletionResult(Enumerable.Repeat(CompletionItemSource.AsKeyword, 1));
                        return(true);
                    }

                    if (context.Position >= item.ContextManager.StartIndex)
                    {
                        return(false);
                    }
                }
            }

            return(false);
        }
コード例 #2
0
        public static bool TryGetCompletionsForOverride(FunctionDefinition function, CompletionContext context, SourceLocation?location, out CompletionResult result)
        {
            result = CompletionResult.Empty;
            if (!string.IsNullOrEmpty(function.NameExpression?.Name) && context.Position > function.NameExpression.EndIndex)
            {
                return(false);
            }

            if (function.Parent is ClassDefinition cd && function.NameExpression != null && context.Position > function.NameExpression.StartIndex)
            {
                var loc          = function.GetStart();
                var overrideable = GetOverrideable(context, location).ToArray();
                overrideable = !string.IsNullOrEmpty(function.Name)
                        ? overrideable.Where(o => o.Name.StartsWithOrdinal(function.Name)).ToArray()
                        : overrideable;
                var items = overrideable.Select(o => ToOverrideCompletionItem(o, cd, context, new string(' ', loc.Column - 1)));
                result = new CompletionResult(items);
                return(true);
            }

            return(false);
        }
コード例 #3
0
        public static bool TryGetCompletions(ForStatement forStatement, CompletionContext context, out CompletionResult result)
        {
            result = null;

            if (forStatement.Left == null)
            {
                return(false);
            }

            if (forStatement.InIndex > forStatement.StartIndex)
            {
                if (context.Position > forStatement.InIndex + 2)
                {
                    return(false);
                }

                if (context.Position >= forStatement.InIndex)
                {
                    var applicableSpan = new SourceSpan(
                        context.IndexToLocation(forStatement.InIndex),
                        context.IndexToLocation(forStatement.InIndex + 2)
                        );
                    result = new CompletionResult(Enumerable.Repeat(CompletionItemSource.InKeyword, 1), applicableSpan);
                    return(true);
                }
            }

            if (forStatement.Left.StartIndex > forStatement.StartIndex &&
                forStatement.Left.EndIndex > forStatement.Left.StartIndex &&
                context.Position > forStatement.Left.EndIndex)
            {
                var applicableSpan = context.GetApplicableSpanFromLastToken(forStatement);
                result = new CompletionResult(Enumerable.Repeat(CompletionItemSource.InKeyword, 1), applicableSpan);
                return(true);
            }

            return(forStatement.ForIndex >= forStatement.StartIndex && context.Position > forStatement.ForIndex + 3);
        }
コード例 #4
0
        public static bool TryGetCompletions(RaiseStatement raiseStatement, CompletionContext context, out CompletionResult result)
        {
            result = null;

            // raise Type, Value, Traceback with Cause
            if (raiseStatement.Cause != null && context.Position >= raiseStatement.CauseFieldStartIndex)
            {
                return(false);
            }

            if (raiseStatement.Traceback != null && context.Position >= raiseStatement.TracebackFieldStartIndex)
            {
                return(false);
            }

            if (raiseStatement.Value != null && context.Position >= raiseStatement.ValueFieldStartIndex)
            {
                return(false);
            }

            if (raiseStatement.ExceptType == null)
            {
                return(false);
            }

            if (context.Position <= raiseStatement.ExceptType.EndIndex)
            {
                return(false);
            }

            if (context.Ast.LanguageVersion.Is3x())
            {
                var applicableSpan = context.GetApplicableSpanFromLastToken(raiseStatement);
                result = new CompletionResult(Enumerable.Repeat(CompletionItemSource.FromKeyword, 1), applicableSpan);
            }

            return(true);
        }
コード例 #5
0
        public static bool TryGetCompletions(TryStatementHandler tryStatement, CompletionContext context, out CompletionResult result)
        {
            result = CompletionResult.Empty;

            // except Test as Target
            if (tryStatement.Target != null && context.Position >= tryStatement.Target.StartIndex)
            {
                return(true);
            }

            if (tryStatement.Test is TupleExpression || tryStatement.Test is null)
            {
                return(false);
            }

            if (context.Position <= tryStatement.Test.EndIndex)
            {
                return(false);
            }

            var applicableSpan = context.GetApplicableSpanFromLastToken(tryStatement);

            result = new CompletionResult(Enumerable.Repeat(CompletionItemSource.AsKeyword, 1), applicableSpan);
            return(true);
        }