Пример #1
0
        public static AbstractTooltipContent[] BuildToolTip(IEditorData Editor)
        {
            try
            {
                var ctxt = ResolverContextStack.Create(Editor);
                // In the case we've got a method or something, don't return its base type, only the reference to it
                ctxt.CurrentContext.ContextDependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;
                var rr = DResolver.ResolveType(Editor, ctxt, DResolver.AstReparseOptions.AlsoParseBeyondCaret);

                if (rr.Length < 1)
                {
                    return(null);
                }

                var l = new List <AbstractTooltipContent>(rr.Length);
                foreach (var res in rr)
                {
                    l.Add(BuildTooltipContent(res));
                }

                return(l.ToArray());
            }
            catch { }
            return(null);
        }
Пример #2
0
        public static AbstractType[] ResolveHoveredCode(
            out ResolverContextStack ResolverContext,
            MonoDevelop.Ide.Gui.Document doc = null)
        {
            var edData = GetEditorData(doc);

            ResolverContext = ResolverContextStack.Create(edData);
            ResolverContext.ContextIndependentOptions |= ResolutionOptions.ReturnMethodReferencesOnly;

            // Resolve the hovered piece of code
            return(DResolver.ResolveType(edData, ResolverContext, DResolver.AstReparseOptions.AlsoParseBeyondCaret | DResolver.AstReparseOptions.OnlyAssumeIdentifierList));
        }
Пример #3
0
        protected override void BuildCompletionDataInternal(IEditorData Editor, string EnteredText)
        {
            var ctxt = ResolverContextStack.Create(Editor);
            var ex   = AccessExpression.AccessExpression == null ? AccessExpression.PostfixForeExpression : AccessExpression;

            ctxt.PushNewScope(ScopedBlock).ScopedStatement = ScopedStatement;
            var r = Evaluation.EvaluateType(ex, ctxt);

            ctxt.Pop();

            if (r == null)             //TODO: Add after-space list creation when an unbound . (Dot) was entered which means to access the global scope
            {
                return;
            }

            BuildCompletionData(r, ScopedBlock);

            if (Editor.Options.ShowUFCSItems &&
                !(r is UserDefinedType || r is PackageSymbol || r is ModuleSymbol))
            {
                UFCSCompletionProvider.Generate(r, ctxt, Editor, CompletionDataGenerator);
            }
        }
Пример #4
0
 public static ArgumentsResolutionResult ResolveArgumentContext(IEditorData editorData)
 {
     return(ResolveArgumentContext(editorData, ResolverContextStack.Create(editorData)));
 }
Пример #5
0
        /// <summary>
        /// Reparses the code of the current scope and returns the object (either IExpression or ITypeDeclaration derivative)
        /// that is beneath the caret location.
        ///
        /// Used for code completion/symbol resolution.
        /// Mind the extra options that might be passed via the Options parameter.
        /// </summary>
        /// <param name="ctxt">Can be null</param>
        public static ISyntaxRegion GetScopedCodeObject(IEditorData editor,
                                                        ResolverContextStack ctxt = null,
                                                        AstReparseOptions Options = 0)
        {
            if (ctxt == null)
            {
                ctxt = ResolverContextStack.Create(editor);
            }

            var code = editor.ModuleCode;

            int  start         = 0;
            var  startLocation = CodeLocation.Empty;
            bool IsExpression  = false;

            if (ctxt.CurrentContext.ScopedStatement is IExpressionContainingStatement)
            {
                var         exprs      = ((IExpressionContainingStatement)ctxt.CurrentContext.ScopedStatement).SubExpressions;
                IExpression targetExpr = null;

                if (exprs != null)
                {
                    foreach (var ex in exprs)
                    {
                        if ((targetExpr = ExpressionHelper.SearchExpressionDeeply(ex, editor.CaretLocation, true))
                            != ex)
                        {
                            break;
                        }
                    }
                }

                if (targetExpr != null && editor.CaretLocation >= targetExpr.Location && editor.CaretLocation <= targetExpr.EndLocation)
                {
                    startLocation = targetExpr.Location;
                    start         = DocumentHelper.LocationToOffset(editor.ModuleCode, startLocation);
                    IsExpression  = true;
                }
            }

            if (!IsExpression)
            {
                // First check if caret is inside a comment/string etc.
                int lastStart    = -1;
                int lastEnd      = -1;
                var caretContext = CaretContextAnalyzer.GetTokenContext(code, editor.CaretOffset, out lastStart, out lastEnd);

                // Return if comment etc. found
                if (caretContext != TokenContext.None)
                {
                    return(null);
                }

                start = CaretContextAnalyzer.SearchExpressionStart(code, editor.CaretOffset - 1,
                                                                   (lastEnd > 0 && lastEnd < editor.CaretOffset) ? lastEnd : 0);
                startLocation = DocumentHelper.OffsetToLocation(editor.ModuleCode, start);
            }

            if (start < 0 || editor.CaretOffset <= start)
            {
                return(null);
            }

            var expressionCode = code.Substring(start, Options.HasFlag(AstReparseOptions.AlsoParseBeyondCaret) ? code.Length - start : editor.CaretOffset - start);

            var parser = DParser.Create(new StringReader(expressionCode));

            parser.Lexer.SetInitialLocation(startLocation);
            parser.Step();

            if (!IsExpression && Options.HasFlag(AstReparseOptions.OnlyAssumeIdentifierList) && parser.Lexer.LookAhead.Kind == DTokens.Identifier)
            {
                return(parser.IdentifierList());
            }
            else if (IsExpression || parser.IsAssignExpression())
            {
                if (Options.HasFlag(AstReparseOptions.ReturnRawParsedExpression))
                {
                    return(parser.AssignExpression());
                }
                else
                {
                    return(ExpressionHelper.SearchExpressionDeeply(parser.AssignExpression(), editor.CaretLocation, Options.HasFlag(AstReparseOptions.WatchForParamExpressions)));
                }
            }
            else
            {
                return(parser.Type());
            }
        }
Пример #6
0
 public static AbstractType[] ResolveType(IEditorData editor, AstReparseOptions Options = 0)
 {
     return(ResolveType(editor, ResolverContextStack.Create(editor), Options));
 }