Exemplo n.º 1
0
        IEnumerable <FoldingRegion> GenerateFoldingsInternal(IReadOnlyList <Comment> comments, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                yield break;
            }

            foreach (var fold in comments.ToFolds())
            {
                yield return(fold);
            }

            if (cancellationToken.IsCancellationRequested)
            {
                yield break;
            }

            var visitor = new FoldingVisitor(cancellationToken);

            if (Unit != null)
            {
                try {
                    visitor.Visit(Unit.GetRoot(cancellationToken));
                } catch (Exception) { }
            }

            if (cancellationToken.IsCancellationRequested)
            {
                yield break;
            }
            foreach (var fold in visitor.Foldings)
            {
                yield return(fold);
            }
        }
Exemplo n.º 2
0
        public override async Task <Container <FoldingRange> > Handle(FoldingRangeRequestParam request,
                                                                      CancellationToken cancellationToken)
        {
            var progress = ProgressManager.For(request, cancellationToken);
            var workDone = ProgressManager.WorkDone(request, new WorkDoneProgressBegin
            {
                Message    = "Begin getting fold ranges",
                Percentage = 0
            });
            var module = TextDocumentHandler.GetAstModule(request.TextDocument.Uri);
            var l      = new List <FoldingRange>(FoldingVisitor.GenerateFoldsInternal(module));

            progress?.OnNext(new Container <FoldingRange>(l));

            if (!cancellationToken.IsCancellationRequested)
            {
                l.AddRange(GenerateMultilineCommentFolds(module));
            }
            l.AddRange(GenerateMultiSingleLineCommentFolds(cancellationToken, module));
            l.AddRange(GenerateRegionFolds(cancellationToken, module));

            progress?.OnNext(new Container <FoldingRange>(l));

            workDone.OnCompleted();
            progress?.OnCompleted();
            return(progress != null ? new Container <FoldingRange>() : new Container <FoldingRange>(l));
        }
Exemplo n.º 3
0
        IEnumerable <FoldingRegion> GenerateFoldings(SyntaxTree unit, ParsedDocument doc)
        {
            foreach (var fold in doc.ConditionalRegions.ToFolds())
            {
                yield return(fold);
            }

            foreach (var fold in doc.Comments.ToFolds())
            {
                yield return(fold);
            }

            var visitor = new FoldingVisitor();

            unit.AcceptVisitor(visitor, null);
            foreach (var fold in visitor.Foldings)
            {
                yield return(fold);
            }
        }
Exemplo n.º 4
0
        IEnumerable <FoldingRegion> GenerateFoldings(CancellationToken cancellationToken)
        {
            foreach (var fold in GetCommentsAsync().Result.ToFolds())
            {
                yield return(fold);
            }

            var visitor = new FoldingVisitor(cancellationToken);

            if (Unit != null)
            {
                try {
                    visitor.Visit(Unit.GetRoot(cancellationToken));
                } catch (Exception) { }
            }
            foreach (var fold in visitor.Foldings)
            {
                yield return(fold);
            }
        }
        protected override CodeFoldingResult GetCodeFoldingResult(out int firstErrorOffset)
        {
            var document = codeEditor.TextEditor.Document;
            var result   = new CodeFoldingResult();

            var foldingContext = new CSharpCodeFoldingContext(document);
            var v = new FoldingVisitor();

            v.document = foldingContext.Document;
            foldingContext.SyntaxTree.AcceptVisitor(v);
            result.FoldingData = v.foldings.OrderBy(x => x.StartOffset).ToList();

            var firstError = foldingContext.SyntaxTree.Errors.FirstOrDefault();

            firstErrorOffset = firstError != null
        ? foldingContext.Document.GetOffset(firstError.Region.Begin)
        : int.MaxValue;

            return(result);
        }
		IEnumerable<FoldingRegion> GenerateFoldings (CancellationToken cancellationToken)
		{
			foreach (var fold in GetCommentsAsync().Result.ToFolds ())
				yield return fold;

			var visitor = new FoldingVisitor (cancellationToken);
			if (Unit != null) {
				try {
					visitor.Visit (Unit.GetRoot (cancellationToken));
				} catch (Exception) { }
			}
			foreach (var fold in visitor.Foldings)
				yield return fold;
		}
Exemplo n.º 7
0
		IEnumerable<FoldingRegion> GenerateFoldingsInternal (IReadOnlyList<Comment> comments, CancellationToken cancellationToken)
		{
			foreach (var fold in comments.ToFolds ())
				yield return fold;

			var visitor = new FoldingVisitor (cancellationToken);
			if (Unit != null) {
				try {
					visitor.Visit (Unit.GetRoot (cancellationToken));
				} catch (Exception) { }
			}
			foreach (var fold in visitor.Foldings)
				yield return fold;
		}