Classifier that classifies all text as an instance of the "XSharpClassifier" classification type.
상속: IClassifier, IDisposable
예제 #1
0
        static internal XSharpClassifier GetColorizer(ITextBuffer buffer, IClassificationTypeRegistryService registry, ITextDocumentFactoryService factory)
        {
            XSharpClassifier colorizer = buffer.Properties.GetOrCreateSingletonProperty(
                () => new XSharpClassifier(buffer, registry, factory));

            return(colorizer);
        }
예제 #2
0
 public override void ExitIfStmt([NotNull] XSharpParser.IfStmtContext context)
 {
     TagRegion(context, context.ChildCount - 2);
     //
     try
     {
         XSharpParser.StatementBlockContext elseBlock = null;
         XSharpParser.IfElseBlockContext    stmt      = null;
         if (context.IfStmt.ElseBlock != null)
         {
             elseBlock = context.IfStmt.ElseBlock;
             stmt      = context.IfStmt;
         }
         else if (context.IfStmt.ElseIfBlock != null)
         {
             if (context.IfStmt.ElseIfBlock.ElseBlock != null)
             {
                 elseBlock = context.IfStmt.ElseIfBlock.ElseBlock;
                 stmt      = context.IfStmt.ElseIfBlock;
             }
         }
         //
         if (elseBlock != null)
         {
             // Search the ELSE block, if Any
             int i = 0;
             LanguageService.SyntaxTree.Tree.IParseTree token = null;
             for (i = 0; i < stmt.ChildCount; i++)
             {
                 token = stmt.GetChild(i);
                 String tokenText = token.GetText().ToUpper();
                 if (tokenText == "ELSE")
                 {
                     break;
                 }
                 else
                 {
                     token = null;
                 }
             }
             //
             if (token is LanguageService.SyntaxTree.Tree.TerminalNodeImpl)
             {
                 LanguageService.SyntaxTree.IToken sym = ((LanguageService.SyntaxTree.Tree.TerminalNodeImpl)token).Symbol;
                 var tokenSpan = new TextSpan(sym.StartIndex, sym.StopIndex - sym.StartIndex + 1);
                 _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStartType));
                 //
                 XSharpParser.StatementBlockContext lastTokenInContext = elseBlock as LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.StatementBlockContext;
                 tokenSpan = new TextSpan(lastTokenInContext.Stop.StopIndex - 1, 1);
                 _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStopType));
             }
         }
     }
     catch (Exception e)
     {
         XSharpClassifier.Debug("Tagregion failed: " + e.Message);
     }
 }
예제 #3
0
 private void TagRegion(RuleContext _context, int endChild)
 {
     try
     {
         var context  = _context as XSharpParserRuleContext;
         var endToken = context.GetChild(endChild);
         if (endToken is LanguageService.SyntaxTree.Tree.TerminalNodeImpl)
         {
             LanguageService.SyntaxTree.IToken sym = ((LanguageService.SyntaxTree.Tree.TerminalNodeImpl)endToken).Symbol;
             var tokenSpan = new TextSpan(context.Start.StartIndex, 1);
             // Attribute ?
             if (context.Start.Text == "[")
             {
                 // Skip it
                 int newStart = getStatementForAttribute(_snapshot, context.Start.StartIndex);
                 tokenSpan = new TextSpan(newStart, 1);
             }
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStartType));
             tokenSpan = new TextSpan(sym.StartIndex, sym.StopIndex - sym.StartIndex + 1);
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStopType));
         }
         else if (endToken is LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.StatementBlockContext)
         {
             XSharpParser.StatementBlockContext lastTokenInContext = endToken as LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.StatementBlockContext;
             var tokenSpan = new TextSpan(context.Start.StartIndex, 1);
             // Attribute on top of Function/Method/... ?
             if (context.Start.Text == "[")
             {
                 // Skip it
                 int newStart = getStatementForAttribute(_snapshot, context.Start.StartIndex);
                 tokenSpan = new TextSpan(newStart, 1);
             }
             //
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStartType));
             tokenSpan = new TextSpan(lastTokenInContext.Stop.StopIndex - 1, 1);
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStopType));
         }
         else if (endToken is ParserRuleContext)
         {
             var lastTokenInContext = endToken as ParserRuleContext;
             var tokenSpan          = new TextSpan(context.Start.StartIndex, 1);
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStartType));
             tokenSpan = new TextSpan(lastTokenInContext.Stop.StartIndex - 1, 1);
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStopType));
         }
     }
     catch (Exception e)
     {
         XSharpClassifier.Debug("Tagregion failed: " + e.Message);
     }
 }
#pragma warning restore 649


        #region IClassifierProvider

        /// <summary>
        /// Gets a classifier for the given text buffer.
        /// </summary>
        /// <param name="buffer">The <see cref="ITextBuffer"/> to classify.</param>
        /// <returns>A classifier for the text buffer, or null if the provider cannot do so in its current state.</returns>
        public IClassifier GetClassifier(ITextBuffer buffer)
        {
            // only return a classifier when this is really our document
            if (!factory.IsXSharpDocument( buffer))
                return null;
            return buffer.Properties.GetOrCreateSingletonProperty<XSharpClassifier>(creator: () => XSharpClassifier.GetColorizer(buffer, this.classificationRegistry, this.factory));
        }
예제 #5
0
        public IEnumerable <ITagSpan <IOutliningRegionTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            //yield break;
            if (spans.Count == 0)
            {
                yield break;
            }
            // Try to retrieve an already parsed list of Tags
            XSharpClassifier xsClassifier = null;

            if (buffer.Properties.ContainsProperty(typeof(XSharpClassifier)))
            {
                xsClassifier = buffer.Properties[typeof(XSharpClassifier)] as XSharpClassifier;
            }

            if (xsClassifier != null)
            {
                //
                ITextSnapshot snapshot        = xsClassifier.Snapshot;
                SnapshotSpan  Span            = new SnapshotSpan(snapshot, 0, snapshot.Length);
                var           classifications = xsClassifier.GetRegionTags();

                SnapshotSpan fullSpan        = new SnapshotSpan(spans[0].Start, spans[spans.Count - 1].End).TranslateTo(snapshot, SpanTrackingMode.EdgeExclusive);
                int          startLineNumber = fullSpan.Start.GetContainingLine().LineNumber;
                int          endLineNumber   = fullSpan.End.GetContainingLine().LineNumber;
                //
                Stack <ClassificationSpan> startStack = new Stack <ClassificationSpan>();
                // convert classifications to an array so there will be no crash when the classifications are changed
                // in another thread.

                // Now, let's have a look at all the Classifications we have in the document
                foreach (var tag in classifications)
                {
                    // Is it a Region ?
                    if (tag.ClassificationType.IsOfType(this.xsharpRegionStartType.Classification))
                    {
                        startStack.Push(tag);
                    }
                    else if (tag.ClassificationType.IsOfType(this.xsharpRegionStopType.Classification) && (startStack.Count > 0))
                    {
                        //
                        var startTag  = startStack.Pop();
                        var startLine = startTag.Span.Start.GetContainingLine();
                        var endLine   = tag.Span.End.GetContainingLine();
                        //
                        if (startTag.Span.Start < tag.Span.End &&
                            startLine.LineNumber <= endLineNumber &&
                            endLine.LineNumber >= startLineNumber)
                        {
                            SnapshotSpan sSpan;
                            try
                            {
                                sSpan = new SnapshotSpan(startLine.Start, endLine.End);
                            }
                            catch (Exception e)
                            {
                                System.Diagnostics.Debug.WriteLine("Incorrect span " + e.Message);
                                sSpan = new SnapshotSpan(startLine.Start, startLine.Start);
                            }
                            hoverText = sSpan.GetText();
                            if (hoverText.Length > 1024)
                            {
                                hoverText = hoverText.Substring(0, 1024) + "\r\n......";
                            }
                            //
                            sSpan = new SnapshotSpan(startLine.Start, startLine.End);
                            ////the region starts at the beginning of the entity, and goes until the *end* of the line that ends.
                            yield return(new TagSpan <IOutliningRegionTag>(
                                             new SnapshotSpan(startLine.End, endLine.End),
                                             new OutliningRegionTag(false, true, ellipsis, hoverText)));
                        }
                    }
                }
            }
            else
            {
                yield break;
            }
        }
예제 #6
0
 static internal XSharpClassifier GetColorizer(ITextBuffer buffer, IClassificationTypeRegistryService registry, ITextDocumentFactoryService factory)
 {
     if (hashtable == null)
         hashtable = new System.Collections.Generic.Dictionary<ITextBuffer, XSharpClassifier>();
     if (hashtable.ContainsKey(buffer))
         return hashtable[buffer];
     var colorizer = new XSharpClassifier(buffer, registry, factory);
     hashtable.Add(buffer, colorizer);
     return colorizer;
 }