public Gtk.Window CreateTooltipWindow (Mono.TextEditor.TextEditor editor, int offset, Gdk.ModifierType modifierState, TooltipItem item)
		{
			ExtensibleTextEditor ed = (ExtensibleTextEditor) editor;
			ParsedDocument doc = ProjectDomService.GetParsedDocument (null, ed.Document.FileName);
			
			ResolveResult resolveResult = (ResolveResult)item.Item;
			if (lastResult != null && lastResult.ResolvedExpression != null && lastWindow.IsRealized && 
			    resolveResult != null && resolveResult.ResolvedExpression != null &&  lastResult.ResolvedExpression.Expression == resolveResult.ResolvedExpression.Expression)
				return lastWindow;
			LanguageItemWindow result = new LanguageItemWindow (ed, modifierState, resolveResult, null, doc != null ? doc.CompilationUnit : null);
			lastWindow = result;
			lastResult = resolveResult;
			if (result.IsEmpty)
				return null;
			return result;
		}
		public LanguageItemWindow (ExtensibleTextEditor ed, Gdk.ModifierType modifierState, ResolveResult result, string errorInformations, ICompilationUnit unit)
		{
			ProjectDom dom = ed.ProjectDom;
			Ambience ambience = AmbienceService.GetAmbience (ed.Document.MimeType);
			
			string tooltip = null;
			if (result != null && ed.TextEditorResolverProvider != null) {
				tooltip = ed.TextEditorResolverProvider.CreateTooltip (dom, unit, result, errorInformations, ambience, modifierState);
				if (result.ResolveErrors.Count > 0) {
					StringBuilder sb = new StringBuilder ();
					sb.Append (tooltip);
					sb.AppendLine ();
					sb.AppendLine ();
					sb.AppendLine (GettextCatalog.GetPluralString ("Error:", "Errors:", result.ResolveErrors.Count));
					for (int i = 0; i < result.ResolveErrors.Count; i++) {
						sb.Append ('\t');
						sb.Append (result.ResolveErrors[i]);
						if (i + 1 < result.ResolveErrors.Count) 
							sb.AppendLine ();
					}
					tooltip = sb.ToString ();
				}
			} else {
				tooltip = errorInformations;
			}
			if (string.IsNullOrEmpty (tooltip)) {
				IsEmpty = true;
				return;
			}

			var label = new MonoDevelop.Components.FixedWidthWrapLabel () {
				Wrap = Pango.WrapMode.WordChar,
				Indent = -20,
				BreakOnCamelCasing = true,
				BreakOnPunctuation = true,
				Markup = tooltip,
			};
			this.BorderWidth = 3;
			Add (label);
			UpdateFont (label);
			
			EnableTransparencyControl = true;
		}
Ejemplo n.º 3
0
		public ResolveResult GetLanguageItem (int offset, string expression)
		{
			oldOffset = offset;
			
			if (textEditorResolverProvider != null) {
				this.resolveResult = textEditorResolverProvider.GetLanguageItem (this.ProjectDom, GetTextEditorData (), offset, expression);
			} else {
				this.resolveResult = null;
			}
	
			return this.resolveResult;
		}
Ejemplo n.º 4
0
		public ResolveResult GetLanguageItem (int offset)
		{
			
			// we'll cache old results.
			if (offset == oldOffset)
				return this.resolveResult;
			oldOffset = offset;
			
			if (textEditorResolverProvider != null) {
				this.resolveResult = textEditorResolverProvider.GetLanguageItem (this.ProjectDom, GetTextEditorData (), offset);
			} else {
				this.resolveResult = null;
			}
			
			return this.resolveResult;
		}
Ejemplo n.º 5
0
		//note: this method is very careful to check that the generated URLs exist in MonoDoc
		//because if we send nonexistent URLS to MonoDoc, it shows empty pages
		public static string GetMonoDocHelpUrl (ResolveResult result)
		{
			if (result == null)
				return null;
			
			if (result is AggregatedResolveResult) 
				result = ((AggregatedResolveResult)result).PrimaryResult;
			
			
			if (result is NamespaceResolveResult)
			{
				string namespc = ((NamespaceResolveResult)result).Namespace;
				//verify that the namespace exists in the help tree
				//FIXME: GetHelpXml doesn't seem to work for namespaces, so forced to do full render
				Monodoc.Node dummy;
				if (!String.IsNullOrEmpty (namespc) && HelpTree != null && HelpTree.RenderUrl ("N:" + namespc, out dummy) != null)
					return "N:" + namespc;
				else return null;
			}
			
			IMember member = null;
			if (result is MethodResolveResult)
				member = ((MethodResolveResult)result).MostLikelyMethod;
			else if (result is MemberResolveResult)
				member = ((MemberResolveResult)result).ResolvedMember;
			
			if (member != null && member.GetMonodocDocumentation () != null)
				return member.HelpUrl;
			
			IReturnType type = result.ResolvedType;
			if (type != null && !String.IsNullOrEmpty (type.FullName)) {
				string t = "T:" + type.FullName;
				if (HelpTree != null && HelpTree.GetHelpXml (t) != null)
					return t;
			}
			
			return null;
		}
		ICompletionDataList CreateCompletionData (DomLocation location, ResolveResult resolveResult, 
		                                          ExpressionResult expressionResult, NRefactoryResolver resolver)
		{
			if (resolveResult == null || expressionResult == null || dom == null)
				return null;
			CompletionDataList result = new ProjectDomCompletionDataList ();
			IEnumerable<object> objects = resolveResult.CreateResolveResult (dom, resolver != null ? resolver.CallingMember : null);
			CompletionDataCollector col = new CompletionDataCollector (dom, result, Document.CompilationUnit, resolver != null ? resolver.CallingType : null, location);
			col.HideExtensionParameter = !resolveResult.StaticResolve;
			col.NamePrefix = expressionResult.Expression;
			bool showOnlyTypes = expressionResult.Contexts.Any (ctx => ctx == ExpressionContext.InheritableType || ctx == ExpressionContext.Constraints);
			if (objects != null) {
				foreach (object obj in objects) {
					if (expressionResult.ExpressionContext != null && expressionResult.ExpressionContext.FilterEntry (obj))
						continue;
					if (expressionResult.ExpressionContext == ExpressionContext.NamespaceNameExcepted && !(obj is Namespace))
						continue;
					if (showOnlyTypes && !(obj is IType))
						continue;
					CompletionData data = col.Add (obj);
					if (data != null && expressionResult.ExpressionContext == ExpressionContext.Attribute && data.CompletionText != null && data.CompletionText.EndsWith ("Attribute")) {
						string newText = data.CompletionText.Substring (0, data.CompletionText.Length - "Attribute".Length);
						data.SetText (newText);
					}
				}
			}
			
			return result;
		}
Ejemplo n.º 7
0
		List<MonoDevelop.Projects.CodeGeneration.MemberReference> GetReferences (ResolveResult resolveResult)
		{
			INode member = null;
			
			if (resolveResult is MemberResolveResult) {
				member = ((MemberResolveResult)resolveResult).ResolvedMember;
				if (member == null)
					member = dom.GetType (resolveResult.ResolvedType);
			}
			if (resolveResult is ParameterResolveResult)
				member = ((ParameterResolveResult)resolveResult).Parameter;
			if (resolveResult is LocalVariableResolveResult)
				member = ((LocalVariableResolveResult)resolveResult).LocalVariable;
			if (member != null) {
				try {
					ICompilationUnit compUnit = Document.CompilationUnit;
					if (compUnit == null)
						return null;
					NRefactoryResolver resolver = new NRefactoryResolver (dom, compUnit, ICSharpCode.OldNRefactory.SupportedLanguage.CSharp, Document.Editor, Document.FileName);
					if (member is LocalVariable)
						resolver.CallingMember = ((LocalVariable)member).DeclaringMember;
					FindMemberAstVisitor visitor = new FindMemberAstVisitor (textEditorData.Document, member);
					visitor.IncludeXmlDocumentation = true;
/*					ICSharpCode.OldNRefactory.Ast.CompilationUnit unit = compUnit.Tag as ICSharpCode.OldNRefactory.Ast.CompilationUnit;
					if (unit == null)
						return null;*/
					visitor.RunVisitor (resolver);
					return visitor.FoundReferences;
				} catch (Exception e) {
					LoggingService.LogError ("Error in highlight usages extension.", e);
				}
			}
			return null;
		}
Ejemplo n.º 8
0
			public ResolveNameOperation (ProjectDom ctx, Document doc, ResolveResult resolveResult, string ns)
			{
				this.ctx = ctx;
				this.doc = doc;
				this.resolveResult = resolveResult;
				this.ns = ns;
			}
Ejemplo n.º 9
0
		public static void GetItem (ProjectDom ctx, Document doc, ITextBuffer editor, out ResolveResult resolveResult, out INode item)
		{
			resolveResult = GetResolveResult (doc, editor);
			if (resolveResult is AggregatedResolveResult)
				resolveResult = ((AggregatedResolveResult)resolveResult).PrimaryResult;
			
			item = null;
			if (resolveResult is ParameterResolveResult) {
				item = ((ParameterResolveResult)resolveResult).Parameter;
			} else if (resolveResult is LocalVariableResolveResult) {
				item = ((LocalVariableResolveResult)resolveResult).LocalVariable;
				//s.Append (ambience.GetString (((LocalVariableResolveResult)result).ResolvedType, WindowConversionFlags));
			} else if (resolveResult is MemberResolveResult) {
				item = ((MemberResolveResult)resolveResult).ResolvedMember;
				if (item == null && ((MemberResolveResult)resolveResult).ResolvedType != null) {
					item = ctx.GetType (((MemberResolveResult)resolveResult).ResolvedType);
				}
			} else if (resolveResult is MethodResolveResult) {
				item = ((MethodResolveResult)resolveResult).MostLikelyMethod;
				if (item == null && ((MethodResolveResult)resolveResult).ResolvedType != null) {
					item = ctx.GetType (((MethodResolveResult)resolveResult).ResolvedType);
				}
			} else if (resolveResult is BaseResolveResult) {
				item = ctx.GetType (((BaseResolveResult)resolveResult).ResolvedType);
			} else if (resolveResult is ThisResolveResult) {
				item = ctx.GetType (((ThisResolveResult)resolveResult).ResolvedType);
			}
		}
Ejemplo n.º 10
0
		public UnresolvedMemberResolveResult (ResolveResult targetResolveResult, string memberName)
		{
			this.TargetResolveResult = targetResolveResult;
			this.MemberName = memberName;
		}
Ejemplo n.º 11
0
		public bool CanShowHelp (ResolveResult result)
		{
			return CanShowHelp (HelpService.GetMonoDocHelpUrl (result));
		}
Ejemplo n.º 12
0
		ResolveResult ResolveMemberReference (ResolveResult result, MemberReferenceExpression memberReferenceExpression)
		{
			IType type = resolver.Dom.GetType (result.ResolvedType);
			if (type == null) 
				return null;
			//Console.WriteLine ("Resolve member: " + memberReferenceExpression.MemberName + " on " + type);
			
			List<IMember> member = new List<IMember> ();
			List<IType> accessibleExtTypes = DomType.GetAccessibleExtensionTypes (resolver.Dom, resolver.Unit);
			// Inheritance of extension methods is handled in DomType
			foreach (IMethod method in type.GetExtensionMethods (accessibleExtTypes)) {
				if (method.Name == memberReferenceExpression.MemberName) {
					member.Add (method);
				}
			}
			bool includeProtected = true;
			foreach (IType curType in resolver.Dom.GetInheritanceTree (type)) {
				if (curType.ClassType == MonoDevelop.Projects.Dom.ClassType.Interface && type.ClassType != MonoDevelop.Projects.Dom.ClassType.Interface)
					continue;
				if (curType.IsAccessibleFrom (resolver.Dom, resolver.CallingType, resolver.CallingMember, includeProtected)) {
					foreach (IMember foundMember in curType.SearchMember (memberReferenceExpression.MemberName, true)) {
						if (foundMember.IsExplicitDeclaration)
							continue;
						if (result is BaseResolveResult && foundMember.IsAbstract)
							continue;
						member.Add (foundMember);
					}
				} 
			}
			if (member.Count > 0) {
				if (member[0] is IMethod) {
					bool isStatic = result.StaticResolve;
					List<IMember> nonMethodMembers = new List<IMember> ();
					List<string> errors = new List<string> ();
					int typeParameterCount = 0;
					if (memberReferenceExpression.TypeArguments != null)
						typeParameterCount = memberReferenceExpression.TypeArguments.Count;
					
					for (int i = 0; i < member.Count; i++) {
						IMethod method = member[i] as IMethod;
						if (method == null)
							nonMethodMembers.Add (member[i]);
						
						if (!member[i].IsAccessibleFrom (resolver.Dom, type, resolver.CallingMember, includeProtected))
							errors.Add (
								MonoDevelop.Core.GettextCatalog.GetString ("'{0}' is inaccessible due to its protection level.",
								ambience.GetString (method, OutputFlags.IncludeParameters | OutputFlags.IncludeGenerics)));
						
						if (method != null && !method.IsFinalizer && (method.IsExtension || method.WasExtended)/* && method.IsAccessibleFrom (resolver.Dom, type, resolver.CallingMember, true)*/) {
							continue;
						}
						if ((member[i].IsStatic ^ isStatic) || 
/*						    !member[i].IsAccessibleFrom (resolver.Dom, type, resolver.CallingMember, includeProtected) || */
						    (method != null && (method.IsFinalizer || typeParameterCount > 0 && method.TypeParameters.Count != typeParameterCount))) {
							member.RemoveAt (i);
							i--;
						}
					}
					if (member.Count == 0)
						return null;
					result = new MethodResolveResult (member);
					((MethodResolveResult)result).Type = type;
					result.CallingType   = resolver.CallingType;
					result.CallingMember = resolver.CallingMember;
					result.ResolveErrors.AddRange (errors);
					//result.StaticResolve = isStatic;
					//result.UnresolvedType = result.ResolvedType  = member[0].ReturnType;
					foreach (TypeReference typeReference in memberReferenceExpression.TypeArguments) {
						((MethodResolveResult)result).AddGenericArgument (resolver.ResolveType (typeReference.ConvertToReturnType ()));
					}
					((MethodResolveResult)result).ResolveExtensionMethods ();
					if (nonMethodMembers.Count > 0) {
						MemberResolveResult baseResult = (MemberResolveResult) CreateResult (nonMethodMembers[0].DeclaringType.CompilationUnit, nonMethodMembers[0].ReturnType);
						baseResult.ResolvedMember = nonMethodMembers[0];
						return new CombinedMethodResolveResult (baseResult, (MethodResolveResult)result);
					}
					//System.Console.WriteLine(result + "/" + result.ResolvedType);
					return result;
				}
				
				if (member[0] is IType) {
					result = CreateResult (member[0].FullName);
					result.StaticResolve = true;
				} else {
					result = CreateResult (member[0].DeclaringType.CompilationUnit, member[0].ReturnType);
					((MemberResolveResult)result).ResolvedMember = member[0];
				}
				if (!member[0].IsAccessibleFrom (resolver.Dom, type, resolver.CallingMember, includeProtected))
					result.ResolveErrors.Add (string.Format (MonoDevelop.Core.GettextCatalog.GetString ("'{0}' is inaccessible due to it's protection level."), ambience.GetString (member[0], OutputFlags.IncludeParameters | OutputFlags.IncludeGenerics)));
			
				return result;
			}
			return new UnresolvedMemberResolveResult (result, memberReferenceExpression.MemberName) {
				CallingType   = resolver.CallingType,
				CallingMember = resolver.CallingMember
			};
		}
Ejemplo n.º 13
0
 ResolveResult GetFunctionParameterType(ResolveResult resolveResult)
 {
     if (resolveResult == null || resolveResult.ResolvedType == null)
         return null;
     IReturnType type = resolveResult.ResolvedType;
     while (type.GenericArguments.Count > 0) {
         IType realType = dom.SearchType (new SearchTypeRequest (Unit, type, CallingType));
         if (realType != null && realType.ClassType == MonoDevelop.Projects.Dom.ClassType.Delegate) {
             IMethod invokeMethod = realType.SearchMember ("Invoke", true) [0] as IMethod;
             if (invokeMethod != null && invokeMethod.Parameters.Count > 0) {
                 type = invokeMethod.Parameters[0].ReturnType;
                 break;
             }
         }
         if (type.GenericArguments.Count > 0) {
             type = type.GenericArguments[0];
         } else {
             break;
         }
     }
     resolveResult.ResolvedType = type;
     return resolveResult;
 }