/// <inheritdoc/> public void AddTagger(ISarifLocationTagger tagger) { using (this.sarifTaggersLock.EnterWriteLock()) { if (!this.sarifTaggers.Contains(tagger)) { this.sarifTaggers.Add(tagger); tagger.Disposed += this.Tagger_Disposed; } } }
#pragma warning restore IDE0044 #pragma warning restore CS0649 /// <inheritdoc/> /// <remarks> /// Note that Visual Studio's tagger aggregation expects and correctly handles null /// if a tagger provider does not want to provide tags. /// </remarks> public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer textBuffer) where T : ITag { ThreadHelper.ThrowIfNotOnUIThread(); if (textView == null) { throw new ArgumentNullException(nameof(textView)); } if (textBuffer == null) { throw new ArgumentNullException(nameof(textBuffer)); } // The SARIF viewer needs a text buffer to have a file name in order to be able to associate a SARIF // result location with the file. Visual Studio allows text buffers to be created at any time with our without a filename. // So, if there is no file name, then do not create a tagger for this buffer. if (!SdkUIUtilities.TryGetFileNameFromTextBuffer(textBuffer, out _)) { return(null); } ISarifLocationTagger newTagger = null; if (typeof(T) == typeof(IErrorTag)) { newTagger = new SarifLocationErrorTagger(textBuffer, this.persistentSpanFactory, this.sarifErrorListEventSelectionService); } if (typeof(T) == typeof(ITextMarkerTag)) { newTagger = new SarifLocationTextMarkerTagger(textView, textBuffer, this.persistentSpanFactory, this.textViewCaretListenerService, this.sarifErrorListEventSelectionService); } if (newTagger != null) { this.sarifLocationTaggerService.AddTagger(newTagger); } return(newTagger as ITagger <T>); }