public AstType CreateShortType(ICompilation compilation, CSharpUnresolvedFile parsedFile, TextLocation loc, IType fullType)
        {
            var csResolver = parsedFile.GetResolver(compilation, loc);
            var builder    = new ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder(csResolver);

            return(builder.ConvertType(fullType));
        }
示例#2
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);
        }
示例#3
0
        ICompletionDataList InternalHandleCodeCompletion(CodeCompletionContext completionContext, char completionChar, bool ctrlSpace, ref int triggerWordLength)
        {
            var data = TextEditorData;

            if (data.CurrentMode is TextLinkEditMode)
            {
                if (((TextLinkEditMode)data.CurrentMode).TextLinkMode == TextLinkMode.EditIdentifier)
                {
                    return(null);
                }
            }
            if (Unit == null || CSharpUnresolvedFile == null)
            {
                return(null);
            }
            if (typeSystemSegmentTree == null)
            {
                return(null);
            }

            var list = new CSharpCompletionDataList();

            list.Resolver = CSharpUnresolvedFile != null?CSharpUnresolvedFile.GetResolver(UnresolvedFileCompilation, Document.Editor.Caret.Location) : new CSharpResolver(Compilation);

            var ctx = CSharpUnresolvedFile.GetTypeResolveContext(UnresolvedFileCompilation, data.Caret.Location) as CSharpTypeResolveContext;

            var engine = new CSharpCompletionEngine(
                data.Document,
                typeSystemSegmentTree,
                new CompletionDataFactory(this, new CSharpResolver(ctx)),
                Document.GetProjectContext(),
                ctx
                );

            engine.FormattingPolicy = FormattingPolicy.CreateOptions();
            engine.EolMarker        = data.EolMarker;
            engine.IndentString     = data.Options.IndentationString;
            try {
                foreach (var cd in engine.GetCompletionData(completionContext.TriggerOffset, ctrlSpace))
                {
                    list.Add(cd);
                    if (cd is IListData)
                    {
                        ((IListData)cd).List = list;
                    }
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while getting completion data.", e);
            }
            list.AutoCompleteEmptyMatch             = engine.AutoCompleteEmptyMatch;
            list.AutoCompleteEmptyMatchOnCurlyBrace = engine.AutoCompleteEmptyMatchOnCurlyBracket;
            list.AutoSelect = engine.AutoSelect;
            list.DefaultCompletionString = engine.DefaultCompletionString;
            list.CloseOnSquareBrackets   = engine.CloseOnSquareBrackets;
            if (ctrlSpace)
            {
                list.AutoCompleteUniqueMatch = true;
            }
            return(list.Count > 0 ? list : null);
        }
示例#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);
        }
示例#6
0
        List <string> GetUsedNamespaces()
        {
            var scope  = CSharpUnresolvedFile.GetUsingScope(document.Editor.Caret.Location);
            var result = new List <string> ();

            while (scope != null)
            {
                result.Add(scope.NamespaceName);
                var ctx = CSharpUnresolvedFile.GetResolver(Document.Compilation, scope.Region.Begin);
                foreach (var u in scope.Usings)
                {
                    var ns = u.ResolveNamespace(ctx);
                    if (ns == null)
                    {
                        continue;
                    }
                    result.Add(ns.FullName);
                }
                scope = scope.Parent;
            }
            return(result);
        }
		public AstType CreateShortType (ICompilation compilation, CSharpUnresolvedFile parsedFile, TextLocation loc, IType fullType)
		{
			var csResolver = parsedFile.GetResolver (compilation, loc);
			var builder = new ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder (csResolver);
			return builder.ConvertType (fullType);			
		}
		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;
		}
示例#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);
        }