Exemplo n.º 1
0
        public List<TagSpan<IOutliningRegionTag>> GetOutlineSpans(SyntaxNode node, ITextSnapshot textSnapshot,
            IdeServices ideServices)
        {
            var ret = new List<TagSpan<IOutliningRegionTag>>();
            var isBlock = IsBlock(node);
            if (!isBlock)
            {
                return ret;
            }
            // always has an extra empty line?
            var text = node.GetText();
            var isOnlineBlock = text.Lines.Count <= 2;
            if (isOnlineBlock)
            {
                return ret;
            }

            if (node.IsKind(SyntaxKind.MultiLineIfBlock))
            {
                var additionalSpan = AddAdditionalOutlinerForIfStatement(node, textSnapshot, ideServices);
                if (additionalSpan != null)
                {
                    ret.Add(additionalSpan);
                }
            }

            var hint = GetCodeHint(textSnapshot, ideServices, node.FullSpan.Start, node.FullSpan.Length);

            var span = new TagSpan<IOutliningRegionTag>(
                new SnapshotSpan(textSnapshot, GetSpanStartPosition(node, text), GetSpanLength(node, text)),
                new OutliningRegionTag(isDefaultCollapsed: false, isImplementation: true,
                    collapsedForm: "...", collapsedHintForm: hint));
            ret.Add(span);
            return ret;
        }
 public static FrameworkElement GetHint(SnapshotSpan span, IdeServices ideServices)
 {
     var x = new ElisionBufferDeferredContent(span,
         ideServices.ProjectionBufferFactoryService,
         ideServices.EditorOptionsFactoryService,
         ideServices.TextEditorFactoryService);
     return ideServices.UiDispatcher.Invoke(() => x.Create());
 }
Exemplo n.º 3
0
        public List <TagSpan <IOutliningRegionTag> > GetOutlineSpans(SyntaxNode node, ITextSnapshot textSnapshot,
                                                                     IdeServices ideServices)
        {
            var outliner = GetOutliner(node);

            return(outliner == null ? new List <TagSpan <IOutliningRegionTag> >()
                : outliner.GetOutlineSpan(node, textSnapshot, ideServices));
        }
Exemplo n.º 4
0
        private static object GetCodeHint(ITextSnapshot textSnapshot, IdeServices ideServices,
                                          int start, int len)
        {
            object hint;

            try
            {
                hint = CollapsedHintCreator.GetHint(
                    new SnapshotSpan(textSnapshot,
                                     start, len)
                    , ideServices);
            }
            catch (Exception ex)
            {
                hint = @"unable to generate hint, please see log (%appdata%\Roaming\nicologies\vbsharpoutliner.log) for details";
                var srcCode = textSnapshot.GetText(start, Math.Min(len, textSnapshot.Length - start));
                Logger.WriteLog(ex, srcCode);
            }
            return(hint);
        }
Exemplo n.º 5
0
 public List<TagSpan<IOutliningRegionTag>> GetOutlineSpan(SyntaxNode node, ITextSnapshot textSnapshot,
     IdeServices ideServices)
 {
     var ret = new List<TagSpan<IOutliningRegionTag>>();
     var text = node.Parent.GetText();
     var isOneLineBlock = text.Lines.Count <= 2;
     if (isOneLineBlock)
     {
         return ret;
     }
     var hint = CollapsedHintCreator.GetHint(
         new SnapshotSpan(textSnapshot, node.Parent.FullSpan.Start, node.Parent.FullSpan.Length),
         ideServices);
     var span = new TagSpan<IOutliningRegionTag>(
         new SnapshotSpan(textSnapshot,
             node.FullSpan.Start - 1,
             GetSpanLength(node)),
         new OutliningRegionTag(isDefaultCollapsed: false, isImplementation: true,
             collapsedForm: "...", collapsedHintForm: hint));
     ret.Add(span);
     return ret;
 }
 public List<TagSpan<IOutliningRegionTag>> GetOutlineSpan(SyntaxNode node, ITextSnapshot textSnapshot,
     IdeServices ideServices)
 {
     var ret = new List<TagSpan<IOutliningRegionTag>>();
     var sectionSyntax = node as SwitchSectionSyntax;
     if (sectionSyntax == null)
     {
         return ret;
     }
     var hint = CollapsedHintCreator.GetHint(
         new SnapshotSpan(textSnapshot, sectionSyntax.FullSpan.Start,
         sectionSyntax.FullSpan.Length),
         ideServices);
     var span = new TagSpan<IOutliningRegionTag>(
         new SnapshotSpan(textSnapshot,
             sectionSyntax.Statements.FullSpan.Start - 1,
             sectionSyntax.Statements.FullSpan.Length - 1),
         new OutliningRegionTag(isDefaultCollapsed: false, isImplementation: true,
             collapsedForm: "...", collapsedHintForm:hint));
     ret.Add(span);
     return ret;
 }
Exemplo n.º 7
0
        public List <TagSpan <IOutliningRegionTag> > GetOutlineSpans(SyntaxNode node, ITextSnapshot textSnapshot,
                                                                     IdeServices ideServices)
        {
            var ret     = new List <TagSpan <IOutliningRegionTag> >();
            var isBlock = IsBlock(node);

            if (!isBlock)
            {
                return(ret);
            }
            // always has an extra empty line?
            var text          = node.GetText();
            var isOnlineBlock = text.Lines.Count <= 2;

            if (isOnlineBlock)
            {
                return(ret);
            }

            if (node.IsKind(SyntaxKind.MultiLineIfBlock))
            {
                var additionalSpan = AddAdditionalOutlinerForIfStatement(node, textSnapshot, ideServices);
                if (additionalSpan != null)
                {
                    ret.Add(additionalSpan);
                }
            }

            var hint = GetCodeHint(textSnapshot, ideServices, node.FullSpan.Start, node.FullSpan.Length);

            var span = new TagSpan <IOutliningRegionTag>(
                new SnapshotSpan(textSnapshot, GetSpanStartPosition(node, text), GetSpanLength(node, text)),
                new OutliningRegionTag(isDefaultCollapsed: false, isImplementation: true,
                                       collapsedForm: "...", collapsedHintForm: hint));

            ret.Add(span);
            return(ret);
        }
Exemplo n.º 8
0
        public List <TagSpan <IOutliningRegionTag> > GetOutlineSpan(SyntaxNode node, ITextSnapshot textSnapshot,
                                                                    IdeServices ideServices)
        {
            var ret      = new List <TagSpan <IOutliningRegionTag> >();
            var switcher = node as SwitchStatementSyntax;

            if (switcher == null)
            {
                return(ret);
            }
            var hint = CollapsedHintCreator.GetHint(
                new SnapshotSpan(textSnapshot, node.FullSpan.Start, node.FullSpan.Length),
                ideServices);
            var span = new TagSpan <IOutliningRegionTag>(
                new SnapshotSpan(textSnapshot,
                                 switcher.OpenBraceToken.FullSpan.Start - 1,
                                 switcher.CloseBraceToken.FullSpan.End - switcher.OpenBraceToken.FullSpan.Start - 1),
                new OutliningRegionTag(isDefaultCollapsed: false, isImplementation: true,
                                       collapsedForm: "...",
                                       collapsedHintForm: hint));

            ret.Add(span);
            return(ret);
        }
Exemplo n.º 9
0
        public List <TagSpan <IOutliningRegionTag> > GetOutlineSpan(SyntaxNode node, ITextSnapshot textSnapshot,
                                                                    IdeServices ideServices)
        {
            var ret            = new List <TagSpan <IOutliningRegionTag> >();
            var text           = node.Parent.GetText();
            var isOneLineBlock = text.Lines.Count <= 2;

            if (isOneLineBlock)
            {
                return(ret);
            }
            var hint = CollapsedHintCreator.GetHint(
                new SnapshotSpan(textSnapshot, node.Parent.FullSpan.Start, node.Parent.FullSpan.Length),
                ideServices);
            var span = new TagSpan <IOutliningRegionTag>(
                new SnapshotSpan(textSnapshot,
                                 node.FullSpan.Start - 1,
                                 GetSpanLength(node)),
                new OutliningRegionTag(isDefaultCollapsed: false, isImplementation: true,
                                       collapsedForm: "...", collapsedHintForm: hint));

            ret.Add(span);
            return(ret);
        }
Exemplo n.º 10
0
        private static TagSpan<IOutliningRegionTag> AddAdditionalOutlinerForIfStatement(SyntaxNode node, 
            ITextSnapshot textSnapshot, IdeServices ideServices)
        {
            var multiLineIf = node as MultiLineIfBlockSyntax;
            Debug.Assert(multiLineIf != null, "multiLineIf != null");
            var hasElse = multiLineIf.ElseIfBlocks.Any() || multiLineIf.ElseBlock != null;
            if (multiLineIf.Statements.Count <= 1 || !hasElse)
            {
                return null;
            }
            var start = multiLineIf.Statements.Span.Start;
            var len = multiLineIf.Statements.Span.Length;
            var hint = GetCodeHint(textSnapshot, ideServices, multiLineIf.Statements.FullSpan.Start,
                multiLineIf.Statements.FullSpan.Length);

            var span = new TagSpan<IOutliningRegionTag>(
                new SnapshotSpan(textSnapshot, start, len),
                new OutliningRegionTag(isDefaultCollapsed: false, isImplementation: true,
                    collapsedForm: "...", collapsedHintForm: hint));
            return span;
        }
Exemplo n.º 11
0
 private static object GetCodeHint(ITextSnapshot textSnapshot, IdeServices ideServices,
     int start, int len)
 {
     object hint;
     try
     {
         hint = CollapsedHintCreator.GetHint(
             new SnapshotSpan(textSnapshot,
                 start, len)
             , ideServices);
     }
     catch (Exception ex)
     {
         hint = @"unable to generate hint, please see log (%appdata%\Roaming\nicologies\vbsharpoutliner.log) for details";
         var srcCode = textSnapshot.GetText(start, Math.Min(len, textSnapshot.Length - start));
         Logger.WriteLog(ex, srcCode);
     }
     return hint;
 }
Exemplo n.º 12
0
        private static TagSpan <IOutliningRegionTag> AddAdditionalOutlinerForIfStatement(SyntaxNode node,
                                                                                         ITextSnapshot textSnapshot, IdeServices ideServices)
        {
            var multiLineIf = node as MultiLineIfBlockSyntax;

            Debug.Assert(multiLineIf != null, "multiLineIf != null");
            var hasElse = multiLineIf.ElseIfBlocks.Any() || multiLineIf.ElseBlock != null;

            if (multiLineIf.Statements.Count <= 1 || !hasElse)
            {
                return(null);
            }
            var start = multiLineIf.Statements.Span.Start;
            var len   = multiLineIf.Statements.Span.Length;
            var hint  = GetCodeHint(textSnapshot, ideServices, multiLineIf.Statements.FullSpan.Start,
                                    multiLineIf.Statements.FullSpan.Length);

            var span = new TagSpan <IOutliningRegionTag>(
                new SnapshotSpan(textSnapshot, start, len),
                new OutliningRegionTag(isDefaultCollapsed: false, isImplementation: true,
                                       collapsedForm: "...", collapsedHintForm: hint));

            return(span);
        }