Exemplo n.º 1
0
        public static bool AddFoldingForBracedConstruct(
            [NotNull] this IHighlightingConsumer context,
            [CanBeNull] ITokenNode lbrace, [CanBeNull] ITokenNode rbrace, [CanBeNull] ITreeNode anchorToken = null,
            string placeholder = "{...}")
        {
            if (lbrace == null || rbrace == null)
            {
                return(false);
            }

            var start        = lbrace.GetDocumentStartOffset();
            var end          = rbrace.GetDocumentEndOffset();
            var anchorOffset = anchorToken?.GetDocumentEndOffset().Offset ?? -1;

            var document    = start.Document;
            var endDocument = end.Document;

            if (document == null || end < start || document != endDocument)
            {
                return(false);
            }

            var foldingRange = new DocumentRange(start, end);

            if (anchorOffset != -1 && anchorOffset < start.Offset)
            {
                var offset = document.FindLastNewLineOffset(anchorOffset, start.Offset);
                foldingRange = foldingRange.SetStartTo(new DocumentOffset(document, offset));
            }

            if (!foldingRange.IsNotEmptyNormalized())
            {
                return(false);
            }
            if (foldingRange.CountNewLines() < 1)
            {
                return(false);
            }

            context.AddDefaultPriorityFolding("ReSharper Default Folding", foldingRange, placeholder);
            return(true);
        }