Esempio n. 1
0
        private void AddClassificationFromToken(List <ClassificationSpan> classifications, ITextSnapshot textSnapshot, TTokenClass token)
        {
            // We don't necessarily map each token to a classification
            string classificationName = _classificationNameProvider.GetClassificationName(token);

            if (!string.IsNullOrEmpty(classificationName))
            {
                var ct = ClassificationRegistryService.GetClassificationType(classificationName);
                if (ct != null)
                {
                    Span tokenSpan        = new Span(token.Start, token.Length);
                    ClassificationSpan cs = new ClassificationSpan(new SnapshotSpan(textSnapshot, tokenSpan), ct);
                    classifications.Add(cs);
                }
            }
        }
Esempio n. 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);
                    }
                }
            }
        }