예제 #1
0
        public FoldingRegion GetUserRegion(int line, int column)
        {
            // search all regions -> then search the last containing region since regions can be nested
            // this algorithm doesn't require the folding regions to be sorted.
            FoldingRegion result = null;

            foreach (var region in UserRegions.Where(r => r.Region.Contains(line, column)))
            {
                if (result == null || region.Region.Start > result.Region.Start)
                {
                    result = region;
                }
            }
            return(result);
        }
예제 #2
0
        public virtual IEnumerable <FoldingRegion> GenerateFolds()
        {
            foreach (FoldingRegion fold in AdditionalFolds)
            {
                yield return(fold);
            }

            foreach (FoldingRegion fold in ConditionalRegions.ToFolds())
            {
                yield return(fold);
            }

            IEnumerable <FoldingRegion> commentFolds = comments.ToFolds();

            if (CompilationUnit != null && CompilationUnit.Types != null && CompilationUnit.Types.Count > 0)
            {
                commentFolds = commentFolds.FlagIfInsideMembers(CompilationUnit.Types, delegate(FoldingRegion f) {
                    f.Type = FoldType.CommentInsideMember;
                });
            }
            foreach (FoldingRegion fold in commentFolds)
            {
                yield return(fold);
            }

            if (CompilationUnit == null)
            {
                yield break;
            }

            FoldingRegion usingFold = CompilationUnit.Usings.ToFold();

            if (usingFold != null)
            {
                yield return(usingFold);
            }

            foreach (FoldingRegion fold in CompilationUnit.Types.ToFolds())
            {
                yield return(fold);
            }
        }
		public override IEnumerable<FoldingRegion> GenerateFolds ()
		{
			if (XDocument == null)
				yield break;
			
			foreach (XNode node in XDocument.AllDescendentNodes) {
				if (node is XCData)
				{
					if (node.Region.End.Line - node.Region.Start.Line > 2)
						yield return new FoldingRegion ("<![CDATA[ ]]>", node.Region);
				}
				else if (node is XComment)
				{
					if (node.Region.End.Line - node.Region.Start.Line > 2)
						yield return new FoldingRegion ("<!-- -->", node.Region);
				}
				else if (node is XElement)
				{
					XElement el = (XElement) node;
					if (el.IsClosed && el.ClosingTag.Region.End.Line - el.Region.Start.Line > 2) {
						yield return new FoldingRegion
							(string.Format ("<{0}...>", el.Name.FullName),
							 new DomRegion (el.Region.Start, el.ClosingTag.Region.End));
					}
				}
				else if (node is XDocType)
				{
					XDocType dt = (XDocType) node;
					string id = !String.IsNullOrEmpty (dt.PublicFpi) ? dt.PublicFpi
						: !String.IsNullOrEmpty (dt.Uri) ? dt.Uri : null;
					
					if (id != null && dt.Region.End.Line - dt.Region.Start.Line > 2) {
						if (id.Length > 50)
							id = id.Substring (0, 47) + "...";
						
						FoldingRegion fr = new FoldingRegion (string.Format ("<!DOCTYPE {0}>", id), dt.Region);
						fr.IsFoldedByDefault = true;
						yield return fr;
					}
				}
			}
		}
예제 #4
0
 public void Add(FoldingRegion region)
 {
     folds.Add(region);
 }
		public void Add (FoldingRegion region)
		{
			folds.Add (region);
		}
		void AddRegion (string name, ILocation startLocation, ILocation endLocation)
		{
			DomRegion region;
			if (endLocation == null)
				region = new DomRegion (startLocation.BeginLine, startLocation.BeginColumn + 1, 
				                        startLocation.EndLine, startLocation.EndColumn + 1);
			else
				region = new DomRegion (startLocation.BeginLine, startLocation.BeginColumn + 1, 
				                        endLocation.EndLine, endLocation.EndColumn + 1);
			
			FoldingRegion f = new FoldingRegion (name, region);
			regions.Add (f);
		}
예제 #7
0
		//
		// -----------------------------------------------------
		// Borrowed from ParsedDocument and overridden
		// -----------------------------------------------------
		//

		public override IEnumerable<FoldingRegion> GenerateFolds ()
		{
			foreach (FoldingRegion fold in AdditionalFolds)
				yield return fold;
			
			foreach (FoldingRegion fold in ConditionalRegions.ToFolds ())
				yield return fold;
			
			IEnumerable<FoldingRegion> commentFolds = Comments.ToPythonFolds ();
			if (CompilationUnit != null && CompilationUnit.Types != null && CompilationUnit.Types.Count > 0) {
				commentFolds = commentFolds.FlagIfInsideMembers (CompilationUnit.Types, delegate (FoldingRegion f) {
					f.Type = FoldType.CommentInsideMember;
				});
			}
			foreach (FoldingRegion fold in commentFolds)
				yield return fold;
			
			if (CompilationUnit == null)
				yield break;
			
			FoldingRegion usingFold = CompilationUnit.Usings.ToFold ();
			if (usingFold != null)
				yield return usingFold;
			
			foreach (FoldingRegion fold in CompilationUnit.Types.ToFolds ())
				yield return fold;

			PythonCompilationUnit pyUnit = CompilationUnit as PythonCompilationUnit;
			foreach (IMember m in pyUnit.Members)
			{
				var fold = new FoldingRegion (m.Name, m.BodyRegion, FoldType.Member);
				yield return fold;
			}
		}