/// <summary>
        /// Extracts the <see cref="DiagnosticInfo"/> Elements which are related to this document.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/>.</param>
        /// <param name="diagnostics">The list of all <see cref="DiagnosticInfo"/>.</param>
        /// <returns>All related <see cref="DiagnosticInfo"/>.</returns>
        public static IEnumerable <DiagnosticInfo> ExtractRelatedDiagnostics(this IQualityTextView textView, IEnumerable <DiagnosticInfo> diagnostics)
        {
            var path = textView.Path;

            if (string.IsNullOrWhiteSpace(path))
            {
                return(Enumerable.Empty <DiagnosticInfo>());
            }

            return(diagnostics.Where(x => path.EndsWith(x?.Path ?? " ", StringComparison.OrdinalIgnoreCase)));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiagnosticInfosViewModel"/> class.
        /// </summary>
        /// <param name="textView">The <see cref="IQualityTextView"/>.</param>
        /// <param name="diagnosticProvider">The <see cref="IDiagnosticProvider"/>.</param>
        /// <param name="outliningManagerService">THe <see cref="IOutliningManagerService"/> for the <paramref name="textView"/>.</param>
        /// <param name="adornmentSpaceReservation">The <see cref="IAdornmentSpaceReservation"/>.</param>
        public DiagnosticInfosViewModel(
            IQualityTextView textView,
            IDiagnosticProvider diagnosticProvider,
            IOutliningManagerService outliningManagerService,
            IAdornmentSpaceReservation adornmentSpaceReservation)
        {
            _diagnosticProvider       = diagnosticProvider ?? throw new ArgumentNullException(nameof(diagnosticProvider));
            TextView                  = textView ?? throw new ArgumentNullException(nameof(textView));
            AdornmentSpaceReservation = adornmentSpaceReservation ?? throw new ArgumentNullException(nameof(adornmentSpaceReservation));
            OutliningManager          = outliningManagerService.GetOutliningManager(TextView.TextView);

            WeakEventManager <IDiagnosticProvider, DiagnosticsChangedEventArgs> .AddHandler(_diagnosticProvider, nameof(IDiagnosticProvider.DiagnosticsChanged), OnDiagnosticsChanged);

            OutliningManager.RegionsExpanded  += OnRegionsExpanded;
            OutliningManager.RegionsCollapsed += OnRegionsCollapsed;

            OnDiagnosticsChanged(this, new DiagnosticsChangedEventArgs(_diagnosticProvider.CurrentDiagnostics));
        }