コード例 #1
0
        public SarifLocationTextMarkerTagger(
            ITextView textView,
            ITextBuffer textBuffer,
            IPersistentSpanFactory persistentSpanFactory,
            ITextViewCaretListenerService <ITextMarkerTag> textViewCaretListenerService,
            ISarifErrorListEventSelectionService sarifErrorListEventSelectionService)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!SdkUIUtilities.TryGetFileNameFromTextBuffer(textBuffer, out this.filePath))
            {
                throw new ArgumentException("Always expect to be able to get file name from text buffer.", nameof(textBuffer));
            }

            this.TextBuffer            = textBuffer;
            this.persistentSpanFactory = persistentSpanFactory;
            this.sarifErrorListEventSelectionService = sarifErrorListEventSelectionService;

            // Subscribe to the SARIF error item being selected from the error list
            // so we can properly filter the tags being shown in the editor
            // to the currently selected item.
            this.sarifErrorListEventSelectionService.SelectedItemChanged += this.SelectedSarifItemChanged;

            // Subscribe to the caret position so we can send enter and exit notifications
            // to the tags so they can decide potentially change their colors.
            textViewCaretListenerService.CreateListener(textView, this);
        }
コード例 #2
0
        private void RefreshPersistentSpans()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // If this text buffer is not associated with a file, it cannot have any SARIF errors.
            this.errorsInFile = SdkUIUtilities.TryGetFileNameFromTextBuffer(this.textBuffer, out string fileName)
                ? GetErrorsInFile(fileName)
                : Enumerable.Empty <SarifErrorListItem>().ToList();
            this.CalculatePersistentSpans(this.errorsInFile);
        }
        public SarifLocationErrorTagger(ITextBuffer textBuffer, IPersistentSpanFactory persistentSpanFactory, ISarifErrorListEventSelectionService sarifErrorListEventSelectionService)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (!SdkUIUtilities.TryGetFileNameFromTextBuffer(textBuffer, out this.filePath))
            {
                throw new ArgumentException("Always expect to be able to get file name from text buffer.", nameof(textBuffer));
            }

            this.TextBuffer = textBuffer;

            this.persistentSpanFactory = persistentSpanFactory;
            this.sarifErrorListEventSelectionService = sarifErrorListEventSelectionService;
            this.sarifErrorListEventSelectionService.SelectedItemChanged += this.SarifErrorListEventSelectionService_SelectedItemChanged;
        }
コード例 #4
0
#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>);
        }