Esempio n. 1
0
        public static SnapshotContext GetContext(ITextSnapshot snapshot)
        {
            if (!_cachedContexts.ContainsKey(snapshot))
            {
                _cachedContexts[snapshot] = new SnapshotContext(snapshot);
            }

            return(_cachedContexts[snapshot]);
        }
        #pragma warning restore 67

        public IList <ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
        {
            var snapshotContext = SnapshotContext.GetContext(span.Snapshot);

            var result = new List <ClassificationSpan>();

            var punctuation = snapshotContext.GetDefaultClassifiedSpans(span).Where(x => x.ClassificationType == ClassificationTypeNames.Punctuation);

            result.AddRange(snapshotContext.ClassifyTokens(punctuation, _classificationTypes[FormatConstants.Brace], SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken));
            result.AddRange(snapshotContext.ClassifyTokens(punctuation, _classificationTypes[FormatConstants.Bracket], SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken));
            result.AddRange(snapshotContext.ClassifyTokens(punctuation, _classificationTypes[FormatConstants.Parenthesis], SyntaxKind.OpenParenToken, SyntaxKind.CloseParenToken));
            result.AddRange(snapshotContext.ClassifyTokens(punctuation, _classificationTypes[FormatConstants.Colon], SyntaxKind.ColonToken));
            result.AddRange(snapshotContext.ClassifyTokens(punctuation, _classificationTypes[FormatConstants.Semicolon], SyntaxKind.SemicolonToken));
            result.AddRange(snapshotContext.ClassifyTokens(punctuation, _classificationTypes[FormatConstants.Comma], SyntaxKind.CommaToken));
            result.AddRange(snapshotContext.ClassifyTokens(punctuation, _classificationTypes[FormatConstants.AngleBracket], SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken));

            return(result);
        }