public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            if (!buffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.SyntacticColorizer))
            {
                return(null);
            }

            if (!_tagComputers.TryGetValue(buffer, out var tagComputer))
            {
                var asyncListener = new AggregateAsynchronousOperationListener(_asyncListeners, FeatureAttribute.Classification);
                tagComputer = new TagComputer(buffer, _notificationService, asyncListener, _typeMap, this);
                _tagComputers.Add(buffer, tagComputer);
            }

            tagComputer.IncrementReferenceCount();

            var tagger      = new Tagger(tagComputer);
            var typedTagger = tagger as ITagger <T>;

            if (typedTagger == null)
            {
                // Oops, we can't actually return this tagger, so just clean up
                tagger.Dispose();
                return(null);
            }
            else
            {
                return(typedTagger);
            }
        }
Exemple #2
0
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            if (!buffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.SyntacticColorizer))
            {
                return(null);
            }

            if (!_tagComputers.TryGetValue(buffer, out var tagComputer))
            {
                tagComputer = new TagComputer(buffer, _notificationService, _listener, _typeMap, this);
                _tagComputers.Add(buffer, tagComputer);
            }

            tagComputer.IncrementReferenceCount();

            var tagger = new Tagger(tagComputer);

            if (!(tagger is ITagger <T> typedTagger))
            {
                // Oops, we can't actually return this tagger, so just clean up
                tagger.Dispose();
                return(null);
            }
            else
            {
                return(typedTagger);
            }
        }
Exemple #3
0
 public void Dispose()
 {
     if (_tagComputer != null)
     {
         _tagComputer.TagsChanged -= OnTagsChanged;
         _tagComputer.DecrementReferenceCountAndDisposeIfNecessary();
         _tagComputer = null;
     }
 }
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            if (!buffer.GetOption(InternalFeatureOnOffOptions.SyntacticColorizer))
            {
                return(null);
            }

            TagComputer tagComputer;

            if (!_tagComputers.TryGetValue(buffer, out tagComputer))
            {
                var asyncListener = new AggregateAsynchronousOperationListener(_asyncListeners, FeatureAttribute.Classification);

                var languageName = _contentTypesToLanguageNames.FirstOrDefault(x => buffer.ContentType.MatchesAny(x.Metadata.DefaultContentType))?.Metadata.Language;
                var editorClassificationService = _editorClassificationLanguageServices.FirstOrDefault(x => x.Metadata.Language == languageName).Value as IEditorClassificationService;

                if (editorClassificationService == null)
                {
                    return(null);
                }

                tagComputer = new TagComputer(
                    buffer,
                    _notificationService,
                    asyncListener,
                    _typeMap,
                    this,
                    _viewSupportsClassificationServiceOpt,
                    _associatedViewService,
                    editorClassificationService,
                    languageName);

                _tagComputers.Add(buffer, tagComputer);
            }

            tagComputer.IncrementReferenceCount();

            var tagger      = new Tagger(tagComputer);
            var typedTagger = tagger as ITagger <T>;

            if (typedTagger == null)
            {
                // Oops, we can't actually return this tagger, so just clean up
                tagger.Dispose();
                return(null);
            }
            else
            {
                return(typedTagger);
            }
        }
        public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag
        {
            if (!tagComputers.TryGetValue(buffer, out var tagComputer))
            {
                tagComputer = new TagComputer(buffer, _typeMap, _listener, this);
                tagComputers.Add(buffer, tagComputer);
            }

            tagComputer.IncrementReferenceCount();

            var tagger = new Tagger(tagComputer);

            if (tagger is ITagger <T> typedTagger)
            {
                return(typedTagger);
            }

            // Oops, we can't actually return this tagger, so just clean up
            // (This seems like it should be impossible in practice, but Roslyn
            // was hardened against it so we are as well.)
            tagger.Dispose();
            return(null);
        }
Exemple #6
0
 public Tagger(TagComputer tagComputer)
 {
     _tagComputer              = tagComputer;
     _tagComputer.TagsChanged += OnTagsChanged;
 }
Exemple #7
0
 public Tagger(TagComputer tagComputer)
 {
     this.tagComputer              = tagComputer;
     this.tagComputer.TagsChanged += OnTagsChanged;
 }