Ejemplo n.º 1
0
        async Task <TooltipInformation> CreateTooltip(ISymbol symbol, SyntaxToken token, TextEditor editor, DocumentContext doc, int offset)
        {
            try {
                TooltipInformation result;
                var sig = new SignatureMarkupCreator(doc, offset);
                sig.BreakLineAfterReturnType = false;

                var typeOfExpression = token.Parent as TypeOfExpressionSyntax;
                if (typeOfExpression != null && symbol is ITypeSymbol)
                {
                    return(sig.GetTypeOfTooltip(typeOfExpression, (ITypeSymbol)symbol));
                }

                result = sig.GetKeywordTooltip(token);
                if (result != null)
                {
                    return(result);
                }

                if (symbol != null)
                {
                    result = await RoslynSymbolCompletionData.CreateTooltipInformation(CancellationToken.None, editor, doc, symbol, false, true);
                }

                return(result);
            } catch (Exception e) {
                LoggingService.LogError("Error while creating tooltip.", e);
                return(null);
            }
        }
Ejemplo n.º 2
0
        TooltipInformation CreateTooltip(ToolTipData data, TextEditor editor, DocumentContext doc, int offset, Gdk.ModifierType modifierState)
        {
            bool createFooter = true;             //(modifierState & Gdk.ModifierType.Mod1Mask) != 0;

            try {
                TooltipInformation result;
                var sig = new SignatureMarkupCreator(doc, offset);
                sig.BreakLineAfterReturnType = false;

                var typeOfExpression = data.Token.Parent as TypeOfExpressionSyntax;
                if (typeOfExpression != null && data.Symbol is ITypeSymbol)
                {
                    return(sig.GetTypeOfTooltip(typeOfExpression, (ITypeSymbol)data.Symbol));
                }

//				var parentKind = data.Token.Parent != null ? data.Token.Parent.Kind () : SyntaxKind.None;
//				switch (parentKind) {
//					case SyntaxKind.ConstructorConstraint:
//					case SyntaxKind.ClassConstraint:
//					case SyntaxKind.StructConstraint:
//						return sig.GetConstraintTooltip (data.Token);
//				}
//
//				if (data.Node is ThisReferenceExpression && result is ThisResolveResult) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
//					sig.BreakLineAfterReturnType = false;
//
//					return sig.GetKeywordTooltip ("this", data.Node);
//				}
//
//				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;
//				}
                result = sig.GetKeywordTooltip(data.Token);
                if (result != null)
                {
                    return(result);
                }

                if (data.Symbol != null)
                {
                    result = RoslynSymbolCompletionData.CreateTooltipInformation(CancellationToken.None, editor, doc, data.Symbol, false, createFooter).Result;
                }

//				if (result == null && parentKind == SyntaxKind.IdentifierName) {
//					if (data.SymbolInfo.CandidateReason == CandidateReason.None) {
//						if (data.Token.Parent.Parent.Kind () == SyntaxKind.SimpleMemberAccessExpression ||
//							data.Token.Parent.Parent.Kind () == SyntaxKind.PointerMemberAccessExpression) {
//							var ma = (MemberAccessExpressionSyntax)data.Token.Parent.Parent;
//							return new TooltipInformation {
//								SignatureMarkup = string.Format ("error CS0117: `{0}' does not contain a definition for `{1}'", ma.Expression, ma.Name)
//							};
//						}
//						return new TooltipInformation {
//							SignatureMarkup = string.Format ("error CS0103: The name `{0}' does not exist in the current context", data.Token)
//						};
//					}
//				}

                return(result);

//				if (result is AliasNamespaceResolveResult) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (doc);
//					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 (doc);
//					sig.BreakLineAfterReturnType = false;
//					return sig.GetAliasedTypeTooltip ((AliasTypeResolveResult)result);
//				}
//
//
//				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 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 {
//					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);
            }
        }