Beispiel #1
0
        public static Task <TooltipInformation> CreateTooltipInformation(CancellationToken ctoken, MonoDevelop.Ide.Editor.TextEditor editor, MonoDevelop.Ide.Editor.DocumentContext ctx, ISymbol entity, bool smartWrap, bool createFooter = false, SemanticModel model = null)
        {
            if (ctx != null)
            {
                if (ctx.ParsedDocument == null || ctx.AnalysisDocument == null)
                {
                    LoggingService.LogError("Signature markup creator created with invalid context." + Environment.NewLine + Environment.StackTrace);
                }
            }

            var tooltipInfo = new TooltipInformation();
//			if (resolver == null)
//				resolver = file != null ? file.GetResolver (compilation, textEditorData.Caret.Location) : new CSharpResolver (compilation);
            var sig = new SignatureMarkupCreator(ctx, editor != null ? editor.CaretOffset : 0);

            sig.SemanticModel            = model;
            sig.BreakLineAfterReturnType = smartWrap;

            return(Task.Run(() => {
                if (ctoken.IsCancellationRequested)
                {
                    return null;
                }
                try {
                    tooltipInfo.SignatureMarkup = sig.GetMarkup(entity);
                } catch (Exception e) {
                    LoggingService.LogError("Got exception while creating markup for :" + entity, e);
                    return new TooltipInformation();
                }

                if (ctoken.IsCancellationRequested)
                {
                    return null;
                }

                tooltipInfo.SummaryMarkup = Ambience.GetSummaryMarkup(entity) ?? "";

                //			if (entity is IMember) {
                //				var evt = (IMember)entity;
                //				if (evt.ReturnType.Kind == TypeKind.Delegate) {
                //					tooltipInfo.AddCategory (GettextCatalog.GetString ("Delegate Info"), sig.GetDelegateInfo (evt.ReturnType));
                //				}
                //			}
                if (entity is IMethodSymbol)
                {
                    var method = (IMethodSymbol)entity;
                    if (method.IsExtensionMethod)
                    {
                        tooltipInfo.AddCategory(GettextCatalog.GetString("Extension Method from"), method.ContainingType.Name);
                    }
                }
                if (createFooter)
                {
                    tooltipInfo.FooterMarkup = sig.CreateFooter(entity);
                }
                return tooltipInfo;
            }));
        }
Beispiel #2
0
        public override async Task <TooltipInformation> CreateTooltipInformation(bool smartWrap, CancellationToken token)
        {
            var tt = await base.CreateTooltipInformation(smartWrap, token);

            tt.SignatureMarkup = member.Name;
            tt.SummaryMarkup   = await Task.Run(() => Ambience.GetSummaryMarkup(member));

            return(tt);
        }
        public static Task <TooltipInformation> CreateTooltipInformation(CancellationToken ctoken, MonoDevelop.Ide.Editor.TextEditor editor, MonoDevelop.Ide.Editor.DocumentContext ctx, ISymbol entity, bool smartWrap, bool createFooter = false, SemanticModel model = null)
        {
            if (entity == null)
            {
                return(TaskUtil.Default <TooltipInformation> ());
            }
            var tooltipInfo = new TooltipInformation();

            var sig = new SignatureMarkupCreator(ctx, editor != null ? editor.CaretOffset : 0);

            sig.SemanticModel            = model;
            sig.BreakLineAfterReturnType = smartWrap;

            return(Task.Run(() => {
                if (ctoken.IsCancellationRequested)
                {
                    return null;
                }
                try {
                    tooltipInfo.SignatureMarkup = sig.GetMarkup(entity);
                } catch (Exception e) {
                    LoggingService.LogError("Got exception while creating markup for :" + entity, e);
                    return new TooltipInformation();
                }

                if (ctoken.IsCancellationRequested)
                {
                    return null;
                }

                tooltipInfo.SummaryMarkup = Ambience.GetSummaryMarkup(entity) ?? "";

                if (entity is IMethodSymbol)
                {
                    var method = (IMethodSymbol)entity;
                    if (method.IsExtensionMethod)
                    {
                        tooltipInfo.AddCategory(GettextCatalog.GetString("Extension Method from"), method.ContainingType.Name);
                    }
                }
                if (createFooter)
                {
                    tooltipInfo.FooterMarkup = sig.CreateFooter(entity);
                }
                return tooltipInfo;
            }));
        }
        void AddAspAttributeValueCompletionData(CompletionDataList list, XName tagName, XName attName, string id)
        {
            Debug.Assert(tagName.IsValid && tagName.HasPrefix);
            Debug.Assert(attName.IsValid && !attName.HasPrefix);

            INamedTypeSymbol controlClass = refman.GetControlType(tagName.Prefix, tagName.Name);

            if (controlClass == null)
            {
                return;
            }

            //find the codebehind class
            INamedTypeSymbol codeBehindClass;

            GetCodeBehind(out codeBehindClass);

            //if it's an event, suggest compatible methods
            if (codeBehindClass != null && attName.Name.StartsWith("On", StringComparison.Ordinal))
            {
                string eventName = attName.Name.Substring(2);

                foreach (IEventSymbol ev in controlClass.GetAccessibleMembersInThisAndBaseTypes <IEventSymbol> (controlClass))
                {
                    if (ev.Name == eventName)
                    {
                        var domMethod = BindingService.MDDomToCodeDomMethod(ev);
                        if (domMethod == null)
                        {
                            return;
                        }

                        foreach (IMethodSymbol meth
                                 in BindingService.GetCompatibleMethodsInClass(codeBehindClass, ev))
                        {
                            list.Add(meth.Name, "md-method",
                                     GettextCatalog.GetString("A compatible method in the CodeBehind class"));
                        }

                        string suggestedIdentifier = ev.Name;
                        if (id != null)
                        {
                            suggestedIdentifier = id + "_" + suggestedIdentifier;
                        }
                        else
                        {
                            suggestedIdentifier = tagName.Name + "_" + suggestedIdentifier;
                        }

                        domMethod.Name = BindingService.GenerateIdentifierUniqueInClass
                                             (codeBehindClass, suggestedIdentifier);
                        domMethod.Attributes = (domMethod.Attributes & ~System.CodeDom.MemberAttributes.AccessMask)
                                               | System.CodeDom.MemberAttributes.Family;

                        list.Add(
                            new SuggestedHandlerCompletionData(project, domMethod, codeBehindClass,
                                                               CodeBehind.GetNonDesignerClassLocation(codeBehindClass))
                            );
                        return;
                    }
                }
            }

            //if it's a property and is an enum or bool, suggest valid values
            foreach (IPropertySymbol prop in GetAllMembers <IPropertySymbol> (controlClass))
            {
                if (prop.Name != attName.Name)
                {
                    continue;
                }

                //boolean completion
                if (prop.GetReturnType().Equals(refman.Compilation.GetTypeByMetadataName("System.Boolean")))
                {
                    AddBooleanCompletionData(list);
                    return;
                }
                //color completion
                if (prop.GetReturnType().Equals(refman.Compilation.GetTypeByMetadataName("System.Drawing.Color")))
                {
                    var conv = new System.Drawing.ColorConverter();
                    foreach (System.Drawing.Color c in conv.GetStandardValues(null))
                    {
                        if (c.IsSystemColor)
                        {
                            continue;
                        }
                        string hexcol = string.Format("#{0:x2}{1:x2}{2:x2}", c.R, c.G, c.B);
                        list.Add(c.Name, hexcol);
                    }
                    return;
                }

                //enum completion
                var retCls = prop.GetReturnType() as INamedTypeSymbol;
                if (retCls != null && retCls.TypeKind == TypeKind.Enum)
                {
                    foreach (var enumVal in GetAllMembers <IFieldSymbol> (retCls))
                    {
                        if (enumVal.DeclaredAccessibility == Accessibility.Public && enumVal.IsStatic)
                        {
                            list.Add(enumVal.Name, "md-literal", Ambience.GetSummaryMarkup(enumVal));
                        }
                    }
                    return;
                }
            }
        }
// TODO: Roslyn port
//		public override ParameterHintingResult HandleParameterCompletionAsync (CodeCompletionContext completionContext, char completionChar)
//		{
///*			if (Tracker.Engine.CurrentState is AspNetExpressionState && documentBuilder != null && localDocumentInfo != null) {
//				return documentBuilder.HandleParameterCompletion (defaultDocument, completionContext, documentInfo, localDocumentInfo, completionChar);
//			}*/
//
//			return base.HandleParameterCompletionAsync (completionContext, completionChar);
//		}

        /*public override void RunParameterCompletionCommand ()
         * {
         *      if (localDocumentInfo == null) {
         *              base.RunParameterCompletionCommand ();
         *              return;
         *      }
         *      var doc = document;
         *      document = localDocumentInfo.HiddenDocument;
         *      var cw = CompletionWidget;
         *      CompletionWidget = documentBuilder.CreateCompletionWidget (localDocumentInfo);
         *      try {
         *              base.RunParameterCompletionCommand ();
         *      } finally {
         *              document = doc;
         *              CompletionWidget = cw;
         *      }
         * }*/

        protected override async Task <CompletionDataList> GetElementCompletions(CancellationToken token)
        {
            var   list       = new CompletionDataList();
            XName parentName = GetParentElementName(0);

            INamedTypeSymbol controlClass = null;

            if (parentName.HasPrefix)
            {
                controlClass = refman.GetControlType(parentName.Prefix, parentName.Name);
            }
            else
            {
                XName grandparentName = GetParentElementName(1);
                if (grandparentName.IsValid && grandparentName.HasPrefix)
                {
                    controlClass = refman.GetControlType(grandparentName.Prefix, grandparentName.Name);
                }
            }

            //we're just in HTML
            if (controlClass == null)
            {
                //root element?
                if (!parentName.IsValid)
                {
                    if (aspDoc.Info.Subtype == WebSubtype.WebControl)
                    {
                        await AddHtmlTagCompletionData(list, Schema, new XName ("div"), token);

                        AddAspBeginExpressions(list);
                        list.AddRange(refman.GetControlCompletionData());
                        AddMiscBeginTags(list);
                    }
                    else if (!string.IsNullOrEmpty(aspDoc.Info.MasterPageFile))
                    {
                        //FIXME: add the actual region names
                        list.Add(new CompletionData("asp:Content"));
                    }
                }
                else
                {
                    AddAspBeginExpressions(list);
                    list.AddRange(refman.GetControlCompletionData());
                    list.AddRange(await base.GetElementCompletions(token));
                }
                return(list);
            }

            string defaultProp;
            bool   childrenAsProperties = AreChildrenAsProperties(controlClass, out defaultProp);

            if (defaultProp != null && defaultProp.Length == 0)
            {
                defaultProp = null;
            }

            //parent permits child controls directly
            if (!childrenAsProperties)
            {
                AddAspBeginExpressions(list);
                list.AddRange(refman.GetControlCompletionData());
                AddMiscBeginTags(list);
                //TODO: get correct parent for Content tags
                await AddHtmlTagCompletionData(list, Schema, new XName ("body"), token);

                return(list);
            }

            //children of properties
            if (childrenAsProperties && (!parentName.HasPrefix || defaultProp != null))
            {
                string          propName = defaultProp ?? parentName.Name;
                IPropertySymbol property =
                    controlClass.GetMembers().OfType <IPropertySymbol> ()
                    .FirstOrDefault(x => string.Equals(propName, x.Name, StringComparison.OrdinalIgnoreCase));

                if (property == null)
                {
                    return(list);
                }

                //sanity checks on attributes
                switch (GetPersistenceMode(property))
                {
                case System.Web.UI.PersistenceMode.Attribute:
                case System.Web.UI.PersistenceMode.EncodedInnerDefaultProperty:
                    return(list);

                case System.Web.UI.PersistenceMode.InnerDefaultProperty:
                    if (!parentName.HasPrefix)
                    {
                        return(list);
                    }
                    break;

                case System.Web.UI.PersistenceMode.InnerProperty:
                    if (parentName.HasPrefix)
                    {
                        return(list);
                    }
                    break;
                }

                //check if allows freeform ASP/HTML content
                if (property.GetReturnType().GetFullName() == "System.Web.UI.ITemplate")
                {
                    AddAspBeginExpressions(list);
                    AddMiscBeginTags(list);
                    await AddHtmlTagCompletionData(list, Schema, new XName ("body"), token);

                    list.AddRange(refman.GetControlCompletionData());
                    return(list);
                }

                //FIXME:unfortunately ASP.NET doesn't seem to have enough type information / attributes
                //to be able to resolve the correct child types here
                //so we assume it's a list and have a quick hack to find arguments of strongly typed ILists

                ITypeSymbol collectionType = property.GetReturnType();
                if (collectionType == null)
                {
                    list.AddRange(refman.GetControlCompletionData());
                    return(list);
                }

                string        addStr = "Add";
                IMethodSymbol meth   = collectionType.GetMembers().OfType <IMethodSymbol> ().FirstOrDefault(m => m.Parameters.Length == 1 && m.Name == addStr);

                if (meth != null)
                {
                    var argType           = meth.Parameters [0].Type as INamedTypeSymbol;
                    INamedTypeSymbol type = refman.Compilation.GetTypeByMetadataName("System.Web.UI.Control");
                    if (argType != null && type != null && argType.IsDerivedFromClass(type))
                    {
                        list.AddRange(refman.GetControlCompletionData(argType));
                        return(list);
                    }
                }

                list.AddRange(refman.GetControlCompletionData());
                return(list);
            }

            //properties as children of controls
            if (parentName.HasPrefix && childrenAsProperties)
            {
                foreach (IPropertySymbol prop in GetUniqueMembers <IPropertySymbol> (controlClass.GetMembers().OfType <IPropertySymbol> ()))
                {
                    if (GetPersistenceMode(prop) != System.Web.UI.PersistenceMode.Attribute)
                    {
                        list.Add(prop.Name, prop.GetStockIcon(), Ambience.GetSummaryMarkup(prop));
                    }
                }
            }
            return(list);
        }
            internal static Task <TooltipInformation> CreateTooltipInformation(MonoDevelop.Ide.Editor.TextEditor editor, MonoDevelop.Ide.Editor.DocumentContext ctx, ISymbol sym, int currentParameter, bool smartWrap, CancellationToken cancelToken)
            {
                var tooltipInfo = new TooltipInformation();
                var sig         = new SignatureMarkupCreator(ctx, editor != null ? editor.CaretOffset : 0);

                sig.HighlightParameter       = currentParameter;
                sig.BreakLineAfterReturnType = smartWrap;

                return(Task.Run(() => {
                    if (cancelToken.IsCancellationRequested)
                    {
                        return null;
                    }
                    try {
                        tooltipInfo.SignatureMarkup = sig.GetMarkup(sym);
                    } catch (Exception e) {
                        LoggingService.LogError("Got exception while creating markup for :" + sym, e);
                        return new TooltipInformation();
                    }
                    tooltipInfo.SummaryMarkup = Ambience.GetSummaryMarkup(sym) ?? "";

                    if (cancelToken.IsCancellationRequested)
                    {
                        return null;
                    }

                    if (sym is IMethodSymbol)
                    {
                        var method = (IMethodSymbol)sym;
                        if (method.IsExtensionMethod && method.ReducedFrom != null && method.ReducedFrom.ContainingType != null)
                        {
                            tooltipInfo.AddCategory(GettextCatalog.GetString("Extension Method from"), method.ReducedFrom.ContainingType.Name);
                        }
                    }
                    int paramIndex = currentParameter;

                    //				if (Symbol is IMethodSymbol && ((IMethodSymbol)Symbol).IsExtensionMethod)
                    //					paramIndex++;
                    var list = GetParameterList(sym);
                    paramIndex = Math.Min(list.Length - 1, paramIndex);

                    var curParameter = paramIndex >= 0 && paramIndex < list.Length ? list [paramIndex] : null;
                    if (curParameter != null)
                    {
                        string docText = Ambience.GetDocumentation(sym);
                        if (!string.IsNullOrEmpty(docText))
                        {
                            string text = docText;
                            Regex paramRegex = new Regex("(\\<param\\s+name\\s*=\\s*\"" + curParameter.Name + "\"\\s*\\>.*?\\</param\\>)", RegexOptions.Compiled);
                            Match match = paramRegex.Match(docText);

                            if (match.Success)
                            {
                                text = Ambience.GetDocumentationMarkup(sym, match.Groups [1].Value);
                                if (!string.IsNullOrWhiteSpace(text))
                                {
                                    tooltipInfo.AddCategory(GettextCatalog.GetString("Parameter"), text);
                                }
                            }
                        }
                        if (curParameter.Type.TypeKind == TypeKind.Delegate)
                        {
                            tooltipInfo.AddCategory(GettextCatalog.GetString("Delegate Info"), sig.GetDelegateInfo(curParameter.Type));
                        }
                    }
                    return tooltipInfo;
                }));
            }