Example #1
0
        public static TooltipInformation CreateTooltipInformation(ICompilation compilation, CSharpUnresolvedFile file, TextEditorData textEditorData, MonoDevelop.PlayScript.Formatting.PlayScriptFormattingPolicy formattingPolicy, IParameterizedMember entity, int currentParameter, bool smartWrap)
        {
            var tooltipInfo = new TooltipInformation();
            var resolver    = file.GetResolver(compilation, textEditorData.Caret.Location);
            var sig         = new SignatureMarkupCreator(resolver, formattingPolicy.CreateOptions());

            sig.HighlightParameter       = currentParameter;
            sig.BreakLineAfterReturnType = smartWrap;
            try {
                tooltipInfo.SignatureMarkup = sig.GetMarkup(entity);
            } catch (Exception e) {
                LoggingService.LogError("Got exception while creating markup for :" + entity, e);
                return(new TooltipInformation());
            }
            tooltipInfo.SummaryMarkup = AmbienceService.GetSummaryMarkup(entity) ?? "";

            if (entity is IMethod)
            {
                var method = (IMethod)entity;
                if (method.IsExtensionMethod)
                {
                    tooltipInfo.AddCategory(GettextCatalog.GetString("Extension Method from"), method.DeclaringTypeDefinition.FullName);
                }
            }
            int paramIndex = currentParameter;

            if (entity is IMethod && ((IMethod)entity).IsExtensionMethod)
            {
                paramIndex++;
            }
            paramIndex = Math.Min(entity.Parameters.Count - 1, paramIndex);

            var curParameter = paramIndex >= 0 && paramIndex < entity.Parameters.Count ? entity.Parameters [paramIndex] : null;

            if (curParameter != null)
            {
                string docText = AmbienceService.GetDocumentation(entity);
                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 = AmbienceService.GetDocumentationMarkup(entity, match.Groups [1].Value);
                        if (!string.IsNullOrWhiteSpace(text))
                        {
                            tooltipInfo.AddCategory(GettextCatalog.GetString("Parameter"), text);
                        }
                    }
                }

                if (curParameter.Type.Kind == TypeKind.Delegate)
                {
                    tooltipInfo.AddCategory(GettextCatalog.GetString("Delegate Info"), sig.GetDelegateInfo(curParameter.Type));
                }
            }
            return(tooltipInfo);
        }
Example #2
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;
            }));
        }
        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;
            }));
        }
Example #4
0
        public static TooltipInformation CreateTooltipInformation(ICompilation compilation, CSharpUnresolvedFile file, CSharpResolver resolver, TextEditorData textEditorData, MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy formattingPolicy, IEntity entity, bool smartWrap, bool createFooter = false)
        {
            var tooltipInfo = new TooltipInformation();

            if (resolver == null)
            {
                resolver = file != null?file.GetResolver(compilation, textEditorData.Caret.Location) : new CSharpResolver(compilation);
            }
            var sig = new SignatureMarkupCreator(resolver, formattingPolicy.CreateOptions());

            sig.BreakLineAfterReturnType = smartWrap;
            try {
                tooltipInfo.SignatureMarkup = sig.GetMarkup(entity);
            } catch (Exception e) {
                LoggingService.LogError("Got exception while creating markup for :" + entity, e);
                return(new TooltipInformation());
            }
            tooltipInfo.SummaryMarkup = AmbienceService.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 IMethod)
            {
                var method = (IMethod)entity;
                if (method.IsExtensionMethod)
                {
                    tooltipInfo.AddCategory(GettextCatalog.GetString("Extension Method from"), method.DeclaringTypeDefinition.FullName);
                }
            }
            if (createFooter)
            {
                tooltipInfo.FooterMarkup = sig.CreateFooter(entity);
            }
            return(tooltipInfo);
        }
        public static TooltipInformation CreateTooltipInformation(ICompilation compilation, CSharpUnresolvedFile file, TextEditorData textEditorData, MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy formattingPolicy, IType type, bool smartWrap, bool createFooter = false)
        {
            var tooltipInfo = new TooltipInformation();

            if (type.Kind == TypeKind.Unknown)
            {
                return(tooltipInfo);
            }
            var resolver = file != null?file.GetResolver(compilation, textEditorData.Caret.Location) : new CSharpResolver(compilation);

            var sig = new SignatureMarkupCreator(resolver, formattingPolicy.CreateOptions());

            sig.BreakLineAfterReturnType = smartWrap;
            try {
                tooltipInfo.SignatureMarkup = sig.GetMarkup(type.IsParameterized ? type.GetDefinition() : type);
            } catch (Exception e) {
                LoggingService.LogError("Got exception while creating markup for :" + type, e);
                return(new TooltipInformation());
            }
            if (type.IsParameterized)
            {
                var typeInfo = new StringBuilder();
                for (int i = 0; i < type.TypeParameterCount; i++)
                {
                    typeInfo.AppendLine(type.GetDefinition().TypeParameters [i].Name + " is " + sig.GetTypeReferenceString(type.TypeArguments [i]));
                }
                tooltipInfo.AddCategory("Type Parameters", typeInfo.ToString());
            }

            var def = type.GetDefinition();

            if (def != null)
            {
                if (createFooter)
                {
                    tooltipInfo.FooterMarkup = sig.CreateFooter(def);
                }
                tooltipInfo.SummaryMarkup = AmbienceService.GetSummaryMarkup(def) ?? "";
            }
            return(tooltipInfo);
        }
		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)
		{
			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;
			});
		}
		public static TooltipInformation CreateTooltipInformation (ICompilation compilation, CSharpUnresolvedFile file, TextEditorData textEditorData, MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy formattingPolicy, IParameterizedMember entity, int currentParameter, bool smartWrap)
		{
			var tooltipInfo = new TooltipInformation ();
			var resolver = file.GetResolver (compilation, textEditorData.Caret.Location);
			var sig = new SignatureMarkupCreator (resolver, formattingPolicy.CreateOptions ());
			sig.HighlightParameter = currentParameter;
			sig.BreakLineAfterReturnType = smartWrap;
			try {
				tooltipInfo.SignatureMarkup = sig.GetMarkup (entity);
			} catch (Exception e) {
				LoggingService.LogError ("Got exception while creating markup for :" + entity, e);
				return new TooltipInformation ();
			}
			tooltipInfo.SummaryMarkup = AmbienceService.GetSummaryMarkup (entity) ?? "";
			
			if (entity is IMethod) {
				var method = (IMethod)entity;
				if (method.IsExtensionMethod) {
					tooltipInfo.AddCategory (GettextCatalog.GetString ("Extension Method from"), method.DeclaringTypeDefinition.FullName);
				}
			}
			int paramIndex = currentParameter;

			if (entity is IMethod && ((IMethod)entity).IsExtensionMethod)
				paramIndex++;
			paramIndex = Math.Min (entity.Parameters.Count - 1, paramIndex);

			var curParameter = paramIndex >= 0  && paramIndex < entity.Parameters.Count ? entity.Parameters [paramIndex] : null;
			if (curParameter != null) {

				string docText = AmbienceService.GetDocumentation (entity);
				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 = AmbienceService.GetDocumentationMarkup (entity, match.Groups [1].Value);
						if (!string.IsNullOrWhiteSpace (text))
							tooltipInfo.AddCategory (GettextCatalog.GetString ("Parameter"), text);
					}
				}
		
				if (curParameter.Type.Kind == TypeKind.Delegate)
					tooltipInfo.AddCategory (GettextCatalog.GetString ("Delegate Info"), sig.GetDelegateInfo (curParameter.Type));
			}
			return tooltipInfo;
		}
Example #8
0
        TooltipInformation CreateTooltip(ToolTipData data, int offset, Ambience ambience, Gdk.ModifierType modifierState)
        {
            ResolveResult result = data.Result;
            var           doc    = IdeApp.Workbench.ActiveDocument;

            if (doc == null)
            {
                return(null);
            }
            bool createFooter = (modifierState & Gdk.ModifierType.Mod1Mask) != 0;
            var  file         = doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile;

            if (file == null)
            {
                return(null);
            }
            try {
                if (result is AliasNamespaceResolveResult)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetAliasedNamespaceTooltip((AliasNamespaceResolveResult)result));
                }

                if (result is AliasTypeResolveResult)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetAliasedTypeTooltip((AliasTypeResolveResult)result));
                }

                if (data.Node is TypeOfExpression)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetTypeOfTooltip((TypeOfExpression)data.Node, result as TypeOfResolveResult));
                }
                if (data.Node is PrimitiveType && data.Node.Parent is Constraint)
                {
                    var t = (PrimitiveType)data.Node;
                    if (t.Keyword == "class" || t.Keyword == "new" || t.Keyword == "struct")
                    {
                        var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                        var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                        sig.BreakLineAfterReturnType = false;
                        return(sig.GetConstraintTooltip(t.Keyword));
                    }
                    return(null);
                }
                if (data.Node is ExternAliasDeclaration)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetExternAliasTooltip((ExternAliasDeclaration)data.Node, doc.Project as DotNetProject));
                }
                if (result == null && data.Node is CSharpTokenNode)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetKeywordTooltip(data.Node));
                }
                if (data.Node is PrimitiveType && ((PrimitiveType)data.Node).KnownTypeCode == KnownTypeCode.Void)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetKeywordTooltip("void", null));
                }
                if (data.Node is NullReferenceExpression)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetKeywordTooltip("null", null));
                }

                if (result is UnknownIdentifierResolveResult)
                {
                    return(new TooltipInformation()
                    {
                        SignatureMarkup = string.Format("error CS0103: The name `{0}' does not exist in the current context", ((UnknownIdentifierResolveResult)result).Identifier)
                    });
                }
                else if (result is UnknownMemberResolveResult)
                {
                    var ur = (UnknownMemberResolveResult)result;
                    if (ur.TargetType.Kind != TypeKind.Unknown)
                    {
                        return(new TooltipInformation()
                        {
                            SignatureMarkup = string.Format("error CS0117: `{0}' does not contain a definition for `{1}'", ur.TargetType.FullName, ur.MemberName)
                        });
                    }
                }
                else if (result.IsError)
                {
                    return(new TooltipInformation()
                    {
                        SignatureMarkup = "Unknown resolve error."
                    });
                }
                if (result is LocalResolveResult)
                {
                    var lr          = (LocalResolveResult)result;
                    var tooltipInfo = new TooltipInformation();
                    var resolver    = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig         = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    tooltipInfo.SignatureMarkup  = sig.GetLocalVariableMarkup(lr.Variable);
                    return(tooltipInfo);
                }
                else if (result is MethodGroupResolveResult)
                {
                    var mrr        = (MethodGroupResolveResult)result;
                    var allMethods = new List <IMethod> (mrr.Methods);
                    foreach (var l in mrr.GetExtensionMethods())
                    {
                        allMethods.AddRange(l);
                    }

                    var method = allMethods.FirstOrDefault();
                    if (method != null)
                    {
                        return(MemberCompletionData.CreateTooltipInformation(
                                   doc.Compilation,
                                   file,
                                   doc.Editor,
                                   doc.GetFormattingPolicy(),
                                   method,
                                   false,
                                   createFooter));
                    }
                }
                else if (result is CSharpInvocationResolveResult)
                {
                    var invocationResult = (CSharpInvocationResolveResult)result;
                    var member           = (IMember)invocationResult.ReducedMethod ?? invocationResult.Member;
                    return(MemberCompletionData.CreateTooltipInformation(
                               doc.Compilation,
                               file,
                               doc.Editor,
                               doc.GetFormattingPolicy(),
                               member,
                               false,
                               createFooter));
                }
                else if (result is MemberResolveResult)
                {
                    var member = ((MemberResolveResult)result).Member;
                    return(MemberCompletionData.CreateTooltipInformation(
                               doc.Compilation,
                               file,
                               doc.Editor,
                               doc.GetFormattingPolicy(),
                               member,
                               false,
                               createFooter));
                }
                else if (result is NamespaceResolveResult)
                {
                    var tooltipInfo = new TooltipInformation();
                    var resolver    = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig         = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    try {
                        tooltipInfo.SignatureMarkup = sig.GetMarkup(((NamespaceResolveResult)result).Namespace);
                    } catch (Exception e) {
                        LoggingService.LogError("Got exception while creating markup for :" + ((NamespaceResolveResult)result).Namespace, e);
                        return(new TooltipInformation());
                    }
                    return(tooltipInfo);
                }
                else if (result is OperatorResolveResult)
                {
                    var or          = result as OperatorResolveResult;
                    var tooltipInfo = new TooltipInformation();
                    var resolver    = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig         = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    try {
                        tooltipInfo.SignatureMarkup = sig.GetMarkup(or.UserDefinedOperatorMethod);
                    } catch (Exception e) {
                        LoggingService.LogError("Got exception while creating markup for :" + ((NamespaceResolveResult)result).Namespace, e);
                        return(new TooltipInformation());
                    }
                    return(tooltipInfo);
                }
                else
                {
                    return(MemberCompletionData.CreateTooltipInformation(
                               doc.Compilation,
                               file,
                               doc.Editor,
                               doc.GetFormattingPolicy(),
                               result.Type,
                               false,
                               createFooter));
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while creating tooltip.", e);
                return(null);
            }

            return(null);
        }
Example #9
0
        public static TooltipInformation CreateTooltipInformation(ICompilation compilation, CSharpUnresolvedFile file, CSharpResolver resolver, TextEditorData textEditorData, MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy formattingPolicy, IEntity entity, bool smartWrap, bool createFooter = false)
        {
            var tooltipInfo = new TooltipInformation();

            if (resolver == null)
            {
                resolver = file != null?file.GetResolver(compilation, textEditorData.Caret.Location) : new CSharpResolver(compilation);
            }
            var sig = new SignatureMarkupCreator(resolver, formattingPolicy.CreateOptions());

            sig.BreakLineAfterReturnType = smartWrap;
            try {
                tooltipInfo.SignatureMarkup = sig.GetMarkup(entity);
            } catch (Exception e) {
                LoggingService.LogError("Got exception while creating markup for :" + entity, e);
                return(new TooltipInformation());
            }
            tooltipInfo.SummaryMarkup = AmbienceService.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 IMethod)
            {
                var method = (IMethod)entity;
                if (method.IsExtensionMethod)
                {
                    tooltipInfo.AddCategory(GettextCatalog.GetString("Extension Method from"), method.DeclaringTypeDefinition.FullName);
                }
            }
            if (createFooter)
            {
                if (entity is IType)
                {
                    var type = entity as IType;
                    var def  = type.GetDefinition();
                    if (def != null)
                    {
                        if (!string.IsNullOrEmpty(def.ParentAssembly.AssemblyName))
                        {
                            var project = def.GetSourceProject();
                            if (project != null)
                            {
                                var relPath = FileService.AbsoluteToRelativePath(project.BaseDirectory, def.Region.FileName);
                                tooltipInfo.FooterMarkup = "<small>" + GettextCatalog.GetString("Project:\t{0}", AmbienceService.EscapeText(def.ParentAssembly.AssemblyName)) + "</small>" + Environment.NewLine +
                                                           "<small>" + GettextCatalog.GetString("File:\t\t{0} (line {1})", AmbienceService.EscapeText(relPath), def.Region.Begin.Line) + "</small>";
                            }
                        }
                    }
                }
                else if (entity.DeclaringTypeDefinition != null)
                {
                    var project = entity.DeclaringTypeDefinition.GetSourceProject();
                    if (project != null)
                    {
                        var relPath = FileService.AbsoluteToRelativePath(project.BaseDirectory, entity.Region.FileName);
                        tooltipInfo.FooterMarkup =
                            "<small>" + GettextCatalog.GetString("Project:\t{0}", AmbienceService.EscapeText(project.Name)) + "</small>" + Environment.NewLine +
                            "<small>" + GettextCatalog.GetString("From:\t{0}", AmbienceService.EscapeText(entity.DeclaringType.FullName)) + "</small>" + Environment.NewLine +
                            "<small>" + GettextCatalog.GetString("File:\t\t{0} (line {1})", AmbienceService.EscapeText(relPath), entity.Region.Begin.Line) + "</small>";
                    }
                }
            }
            return(tooltipInfo);
        }
		TooltipInformation CreateTooltip (ToolTipData data, int offset, Ambience ambience)
		{
			ResolveResult result = data.Result;
			var doc = IdeApp.Workbench.ActiveDocument;
			if (doc == null)
				return null;
			try {

				if (result is AliasNamespaceResolveResult) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetAliasedNamespaceTooltip ((AliasNamespaceResolveResult)result);
				}
				
				if (result is AliasTypeResolveResult) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetAliasedTypeTooltip ((AliasTypeResolveResult)result);
				}
				
				if (data.Node is TypeOfExpression) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetTypeOfTooltip ((TypeOfExpression)data.Node, result as TypeOfResolveResult);
				}
				if (data.Node is PrimitiveType && data.Node.Parent is Constraint) {
					var t = (PrimitiveType)data.Node;
					if (t.Keyword == "class" || t.Keyword == "new" || t.Keyword == "struct") {
						var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
						var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
						sig.BreakLineAfterReturnType = false;
						return sig.GetConstraintTooltip (t.Keyword);
					}
					return null;
				}
				if (data.Node is ExternAliasDeclaration) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetExternAliasTooltip ((ExternAliasDeclaration)data.Node, doc.Project as DotNetProject);
				}
				if (result == null && data.Node is CSharpTokenNode) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetKeywordTooltip (data.Node);
				}
				if (data.Node is PrimitiveType && ((PrimitiveType)data.Node).KnownTypeCode == KnownTypeCode.Void) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetKeywordTooltip ("void", null);
				}

				if (result is UnknownIdentifierResolveResult) {
					return new TooltipInformation () {
						SignatureMarkup = string.Format ("error CS0103: The name `{0}' does not exist in the current context", ((UnknownIdentifierResolveResult)result).Identifier)
					};
				} else if (result is UnknownMemberResolveResult) {
					var ur = (UnknownMemberResolveResult)result;
					if (ur.TargetType.Kind != TypeKind.Unknown) {
						return new TooltipInformation () {
							SignatureMarkup = string.Format ("error CS0117: `{0}' does not contain a definition for `{1}'", ur.TargetType.FullName, ur.MemberName)
						};
					}
				} else if (result.IsError) {
					return new TooltipInformation () {
						SignatureMarkup = "Unknown resolve error."
					};
				}
				if (result is LocalResolveResult) {
					var lr = (LocalResolveResult)result;
					var tooltipInfo = new TooltipInformation ();
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					tooltipInfo.SignatureMarkup = sig.GetLocalVariableMarkup (lr.Variable);
					return tooltipInfo;
				} else if (result is MethodGroupResolveResult) {
					var mrr = (MethodGroupResolveResult)result;
					var allMethods = new List<IMethod> (mrr.Methods);
					foreach (var l in mrr.GetExtensionMethods ()) {
						allMethods.AddRange (l);
					}
				
					var method = allMethods.FirstOrDefault ();
					if (method != null) {
						return MemberCompletionData.CreateTooltipInformation (
						doc.Compilation,
						doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile,
						doc.Editor,
						doc.GetFormattingPolicy (),
						method, 
						false);
					}
				} else if (result is CSharpInvocationResolveResult) {
					var member = ((CSharpInvocationResolveResult)result).ReducedMethod ?? (IMethod)((CSharpInvocationResolveResult)result).Member;
					return MemberCompletionData.CreateTooltipInformation (
						doc.Compilation,
						doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile,
						doc.Editor,
						doc.GetFormattingPolicy (),
						member, 
						false);
				} else if (result is MemberResolveResult) {
					var member = ((MemberResolveResult)result).Member;
					return MemberCompletionData.CreateTooltipInformation (
					doc.Compilation,
					doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile,
					doc.Editor,
					doc.GetFormattingPolicy (),
					member, 
					false);
				}else if (result is NamespaceResolveResult) {
					var tooltipInfo = new TooltipInformation ();
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					try {
						tooltipInfo.SignatureMarkup = sig.GetMarkup (((NamespaceResolveResult)result).Namespace);
					} catch (Exception e) {
						LoggingService.LogError ("Got exception while creating markup for :" + ((NamespaceResolveResult)result).Namespace, e);
						return new TooltipInformation ();
					}
					return tooltipInfo;
				} else {
					return MemberCompletionData.CreateTooltipInformation (
					doc.Compilation,
					doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile,
					doc.Editor,
					doc.GetFormattingPolicy (),
					result.Type, 
					false);
				}
			} catch (Exception e) {
				LoggingService.LogError ("Error while creating tooltip.", e);
				return null;
			}
		
			return null;
		}
            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;
                }));
            }
			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;
				});
			}