Exemple #1
0
		public DataProvider (Document doc, object tag, Ambience amb)
		{
			this.Document = doc;
			this.tag = tag;
			this.amb = amb;
			Reset ();
		}
Exemple #2
0
		string GetString (Ambience amb, IUnresolvedEntity x)
		{
			var ctx = new SimpleTypeResolveContext (Document.Compilation.MainAssembly);
			IEntity rx = null;
			if (x is IUnresolvedMember)
				rx = ((IUnresolvedMember)x).CreateResolved (ctx);
			
			if (tag is IUnresolvedFile)
				return amb.GetString (rx, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.UseFullInnerTypeName | OutputFlags.ReformatDelegates);
			return amb.GetString (rx, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.ReformatDelegates);
		}
		public ImportSymbolCompletionData (MonoDevelop.Ide.Gui.Document doc, ImportSymbolCache cache, IType type)
		{
			this.doc = doc;
			this.cache = cache;
//			this.data = doc.Editor;
			this.ambience = AmbienceService.GetAmbience (doc.Editor.MimeType);
			this.type = type;
			this.unit = doc.ParsedDocument;
		}
		internal static string GetAttributes (Ambience ambience, IEnumerable<IAttribute> attributes)
		{
			StringBuilder result = new StringBuilder ();
			foreach (var attr in attributes) {
				if (result.Length > 0)
					result.AppendLine ();
	//			result.Append (ambience.GetString (attr, OutputFlags.AssemblyBrowserDescription));
			}
			if (result.Length > 0)
				result.AppendLine ();
			return result.ToString ();
		}
		public string CreateTooltip (ResolveResult result, int offset, Ambience ambience)
		{
			var doc = IdeApp.Workbench.ActiveDocument;
			if (doc == null)
				return null;
			try {
				OutputSettings settings = new OutputSettings (OutputFlags.ClassBrowserEntries | OutputFlags.IncludeParameterName | OutputFlags.IncludeKeywords | OutputFlags.IncludeMarkup | OutputFlags.UseFullName);
				// Approximate value for usual case
				StringBuilder s = new StringBuilder (150);
				string documentation = null;
				if (result is UnknownIdentifierResolveResult) {
					s.Append (String.Format (GettextCatalog.GetString ("Unresolved identifier '{0}'"), ((UnknownIdentifierResolveResult)result).Identifier));
				} else if (result.IsError) {
					s.Append (GettextCatalog.GetString ("Resolve error."));
				} else if (result is LocalResolveResult) {
					var lr = (LocalResolveResult)result;
					s.Append ("<small><i>");
					s.Append (lr.IsParameter ? paramStr : localStr);
					s.Append ("</i></small>\n");
					s.Append (ambience.GetString (lr.Variable.Type, settings));
					s.Append (" ");
					s.Append (lr.Variable.Name);
				} else if (result is MethodGroupResolveResult) {

					var mrr = (MethodGroupResolveResult)result;
					s.Append ("<small><i>");
					s.Append (methodStr);
					s.Append ("</i></small>\n");
					var allMethods = new List<IMethod> (mrr.Methods);
					foreach (var l in mrr.GetExtensionMethods ()) {
						allMethods.AddRange (l);
					}
					
					var method = allMethods.FirstOrDefault ();
					if (method != null) {
						s.Append (GLib.Markup.EscapeText (TextEditorResolverProvider.CreateAmbience (doc, offset, method.Compilation).ConvertEntity (method)));
						if (allMethods.Count > 1) {
							int overloadCount = allMethods.Count - 1;
							s.Append (string.Format (GettextCatalog.GetPluralString (" (+{0} overload)", " (+{0} overloads)", overloadCount), overloadCount));
						}
						documentation = AmbienceService.GetDocumentationSummary (method);
					}
				} else if (result is MemberResolveResult) {
					var member = ((MemberResolveResult)result).Member;
					s.Append ("<small><i>");
					s.Append (GetString (member));
					s.Append ("</i></small>\n");
					var field = member as IField;
					if (field != null && field.IsConst) {
						s.Append (GLib.Markup.EscapeText (TextEditorResolverProvider.CreateAmbience (doc, offset, field.Compilation).ConvertType (field.Type)));
						s.Append (" ");
						s.Append (field.Name);
						s.Append (" = ");
						s.Append (GetConst (field.ConstantValue));
						s.Append (";");
					} else {
						s.Append (GLib.Markup.EscapeText (TextEditorResolverProvider.CreateAmbience (doc, offset, member.Compilation).ConvertEntity (member)));
					}
					documentation = AmbienceService.GetDocumentationSummary (member);
				} else if (result is NamespaceResolveResult) {
					s.Append ("<small><i>");
					s.Append (namespaceStr);
					s.Append ("</i></small>\n");
					s.Append (ambience.GetString (((NamespaceResolveResult)result).NamespaceName, settings));
				} else {
					var tr = result;
					var typeString = GetString (tr.Type);
					if (!string.IsNullOrEmpty (typeString)) {
						s.Append ("<small><i>");
						s.Append (typeString);
						s.Append ("</i></small>\n");
					}
					settings.OutputFlags |= OutputFlags.UseFullName | OutputFlags.UseFullInnerTypeName;
					s.Append (ambience.GetString (tr.Type, settings));
					documentation = AmbienceService.GetDocumentationSummary (tr.Type.GetDefinition ());
				}
				
				if (!string.IsNullOrEmpty (documentation)) {
					s.Append ("\n<small>");
					s.Append (AmbienceService.GetDocumentationMarkup ("<summary>" + documentation + "</summary>"));
					s.Append ("</small>");
				}
				return s.ToString ();
			} catch (Exception e) {
				LoggingService.LogError ("Error while creating tooltip.", e);
				return null;
			}
		}
		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;
		}
		public string CreateTooltip (IParsedFile unit, ResolveResult result, string errorInformations, Ambience ambience, Gdk.ModifierType modifierState)
		{
			OutputSettings settings = new OutputSettings (OutputFlags.ClassBrowserEntries | OutputFlags.IncludeParameterName | OutputFlags.IncludeKeywords | OutputFlags.IncludeMarkup | OutputFlags.UseFullName);
			//			if ((Gdk.ModifierType.ShiftMask & modifierState) == Gdk.ModifierType.ShiftMask) {
			//				settings.EmitNameCallback = delegate(object domVisitable, ref string outString) {
			//					// crop used namespaces.
			//					if (unit != null) {
			//						int len = 0;
			//						foreach (var u in unit.Usings) {
			//							foreach (string ns in u.Namespaces) {
			//								if (outString.StartsWith (ns + ".")) {
			//									len = Math.Max (len, ns.Length + 1);
			//								}
			//							}
			//						}
			//						string newName = outString.Substring (len);
			//						int count = 0;
			//						// check if there is a name clash.
			//						if (dom.GetType (newName) != null)
			//							count++;
			//						foreach (IUsing u in unit.Usings) {
			//							foreach (string ns in u.Namespaces) {
			//								if (dom.GetType (ns + "." + newName) != null)
			//									count++;
			//							}
			//						}
			//						if (len > 0 && count == 1)
			//							outString = newName;
			//					}
			//				};
			//			}
			
			// Approximate value for usual case
			StringBuilder s = new StringBuilder (150);
			string doc = null;
			if (result != null) {
				if (result is UnknownIdentifierResolveResult) {
					s.Append (String.Format (GettextCatalog.GetString ("Unresolved identifier '{0}'"), ((UnknownIdentifierResolveResult)result).Identifier));
				} else if (result.IsError) {
					s.Append (GettextCatalog.GetString ("Resolve error."));
				} else if (result is LocalResolveResult) {
					var lr = (LocalResolveResult)result;
					s.Append ("<small><i>");
					s.Append (lr.IsParameter ? paramStr : localStr);
					s.Append ("</i></small>\n");
					s.Append (ambience.GetString (lr.Variable.Type, settings));
					s.Append (" ");
					s.Append (lr.Variable.Name);
				} else if (result is MethodGroupResolveResult) {
					var mrr = (MethodGroupResolveResult)result;
					s.Append ("<small><i>");
					s.Append (methodStr);
					s.Append ("</i></small>\n");
					var allMethods = new List<IMethod> (mrr.Methods);
					foreach (var l in mrr.GetExtensionMethods ()) {
						allMethods.AddRange (l);
					}
					
					var method = allMethods.FirstOrDefault ();
					if (method != null) {
						s.Append (ambience.GetString (method, settings));
						if (allMethods.Count > 1) {
							int overloadCount = allMethods.Count - 1;
							s.Append (string.Format (GettextCatalog.GetPluralString (" (+{0} overload)", " (+{0} overloads)", overloadCount), overloadCount));
						}
						doc = AmbienceService.GetDocumentationSummary (method);
					}
				} else if (result is MemberResolveResult) {
					var member = ((MemberResolveResult)result).Member;
					s.Append ("<small><i>");
					s.Append (GetString (member));
					s.Append ("</i></small>\n");
					var field = member as IField;
					if (field != null && field.IsConst) {
						s.Append (ambience.GetString (field.Type, settings));
						s.Append (" ");
						s.Append (field.Name);
						s.Append (" = ");
						s.Append (GetConst (field.ConstantValue));
						s.Append (";");
					} else {
						s.Append (ambience.GetString (member, settings));
					}
					doc = AmbienceService.GetDocumentationSummary (member);
				} else if (result is NamespaceResolveResult) {
					s.Append ("<small><i>");
					s.Append (namespaceStr);
					s.Append ("</i></small>\n");
					s.Append (ambience.GetString (((NamespaceResolveResult)result).NamespaceName, settings));
				} else {
					var tr = result;
					var typeString = GetString (tr.Type);
					if (!string.IsNullOrEmpty (typeString)) {
						s.Append ("<small><i>");
						s.Append (typeString);
						s.Append ("</i></small>\n");
					}
					settings.OutputFlags |= OutputFlags.UseFullName;
					s.Append (ambience.GetString (tr.Type, settings));
					doc = AmbienceService.GetDocumentationSummary (tr.Type.GetDefinition ());
				}
				
				if (!string.IsNullOrEmpty (doc)) {
					s.Append ("\n<small>");
					s.Append (AmbienceService.GetDocumentationMarkup ("<summary>" + doc + "</summary>"));
					s.Append ("</small>");
				}
			}
			
			if (!string.IsNullOrEmpty (errorInformations)) {
				if (s.Length != 0)
					s.Append ("\n\n");
				s.Append ("<small>");
				s.Append (errorInformations);
				s.Append ("</small>");
			}
			return s.ToString ();
		}
			public TypeDataProvider (MonoDevelop.Projects.DotNetProject project)
			{
				TypeNamesList = new List<string> ();
				var ctx = TypeSystemService.GetCompilation (project);
				TypesList = new List<ITypeDefinition> (ctx.MainAssembly.GetAllTypeDefinitions ());
				this.ambience = AmbienceService.GetAmbience (project.LanguageName);
				foreach (var typeDef in TypesList) {
					TypeNamesList.Add (ambience.GetString ((IEntity)typeDef, OutputFlags.IncludeGenerics | OutputFlags.UseFullName | OutputFlags.IncludeMarkup));
				}
			}
		public ImportSymbolCompletionData (MonoDevelop.Ide.Gui.Document doc, ImportSymbolCache cache, IType type)
		{
			this.doc = doc;
			this.cache = cache;
//			this.data = doc.Editor;
			this.ambience = AmbienceService.GetAmbience (doc.Editor.MimeType);
			this.type = type;
			this.unit = doc.ParsedDocument;
			this.DisplayFlags |= ICSharpCode.NRefactory.Completion.DisplayFlags.IsImportCompletion;
		}