示例#1
0
        private static void WriteCompositeToken(ICompositeToken composite, StringBuilder sb)
        {
            foreach (var token in composite.TokenList)
            {
                ITextRange range        = token as ITextRange;
                Type       tokenType    = token.GetType();
                Type       genericToken = tokenType.BaseType;

                int    intEnumCode     = (int)genericToken.GetProperty("TokenType").GetValue(token);
                string tokenTypeString = tokenType.ToString();
                tokenTypeString = tokenTypeString.Substring(tokenTypeString.LastIndexOf('.') + 1);
                sb.AppendFormat(CultureInfo.InvariantCulture, "Composite: {0} {1} : {2} - {3}\t({4})\r\n", tokenTypeString, intEnumCode, range.Start, range.End, range.Length);
            }
        }
示例#2
0
        private void AddClassificationFromCompositeToken(List <ClassificationSpan> classifications, ITextSnapshot textSnapshot, ICompositeToken composite)
        {
            string contentTypeName = composite.ContentType;
            IClassificationNameProvider compositeNameProvider;

            if (!_compositeClassificationNameProviders.TryGetValue(contentTypeName, out compositeNameProvider))
            {
                IContentType contentType = ContentTypeRegistryService.GetContentType(contentTypeName);
                var          providers   = ComponentLocatorForContentType <IClassificationNameProvider, IComponentContentTypes> .
                                           FilterByContentTypeExact(contentType, ClassificationNameProviders);

                var lazyProvider = providers.FirstOrDefault();
                Debug.Assert(lazyProvider != null);

                if (lazyProvider != null)
                {
                    compositeNameProvider = lazyProvider.Value;
                    _compositeClassificationNameProviders[contentTypeName] = compositeNameProvider;
                }
            }

            foreach (object token in composite.TokenList)
            {
                // We don't necessarily map each token to a classification
                ITextRange range;
                string     classificationName = compositeNameProvider.GetClassificationName(token, out range);

                if (!string.IsNullOrEmpty(classificationName))
                {
                    IClassificationType ct = ClassificationRegistryService.GetClassificationType(classificationName);

                    if (ct != null)
                    {
                        Span tokenSpan        = new Span(range.Start, range.Length);
                        ClassificationSpan cs = new ClassificationSpan(new SnapshotSpan(textSnapshot, tokenSpan), ct);
                        classifications.Add(cs);
                    }
                }
            }
        }