Ejemplo n.º 1
0
        public ErrorListItem NavigateToErrorListItem(
            int itemIndex,
            __VSERRORCATEGORY minimumSeverity = __VSERRORCATEGORY.EC_WARNING
            )
        {
            var errorItems = GetErrorItems()
                             .AsEnumerable()
                             .Where(e => ((IVsErrorItem)e).GetCategory() <= minimumSeverity)
                             .ToArray();

            if (itemIndex > errorItems.Count())
            {
                throw new ArgumentException(
                          $"Cannot Navigate to Item '{itemIndex}', Total Items found '{errorItems.Count()}'."
                          );
            }

            var item = errorItems.ElementAt(itemIndex);

            ErrorHandler.ThrowOnFailure(item.NavigateTo());
            return(new ErrorListItem(
                       item.GetSeverity(),
                       item.GetDescription(),
                       item.GetProject(),
                       item.GetFileName(),
                       item.GetLine(),
                       item.GetColumn()
                       ));
        }
Ejemplo n.º 2
0
        public ErrorListItem[] GetErrorListContents(
            __VSERRORCATEGORY minimumSeverity = __VSERRORCATEGORY.EC_WARNING
            )
        {
            var errorItems = GetErrorItems();

            try
            {
                return(errorItems
                       .AsEnumerable()
                       .Where(e => ((IVsErrorItem)e).GetCategory() <= minimumSeverity)
                       .Select(
                           e =>
                           new ErrorListItem(
                               e.GetSeverity(),
                               e.GetDescription(),
                               e.GetProject(),
                               e.GetFileName(),
                               e.GetLine(),
                               e.GetColumn()
                               )
                           )
                       .ToArray());
            }
            catch (IndexOutOfRangeException)
            {
                // It is entirely possible that the items in the error list are modified
                // after we start iterating, in which case we want to try again.
                return(GetErrorListContents(minimumSeverity));
            }
        }
Ejemplo n.º 3
0
        public async Task <int> GetErrorCountAsync(__VSERRORCATEGORY minimumSeverity = __VSERRORCATEGORY.EC_WARNING)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync();

            var errorItems = await GetErrorItemsAsync();

            return(errorItems.Count(e => e.GetCategory() <= minimumSeverity));
        }
Ejemplo n.º 4
0
 public TaskItemInfo(string document, int line, int column, VSTASKPRIORITY priority, VSTASKCATEGORY category, __VSERRORCATEGORY? errorCategory, string message) {
     Document = document;
     Line = line;
     Column = column;
     Priority = priority;
     Category = category;
     ErrorCategory = errorCategory;
     Message = message;
 }
Ejemplo n.º 5
0
        public ItemControl(ImageMoniker icon, __VSERRORCATEGORY category)
        {
            _icon     = icon;
            _category = category;

            Orientation       = Orientation.Horizontal;
            VerticalAlignment = VerticalAlignment.Center;
            Visibility        = Visibility.Collapsed;

            Options.Saved += OptionsSaved;
        }
Ejemplo n.º 6
0
        public async Task ShowErrorListAsync(ErrorSource errorSource, __VSERRORCATEGORY minimumSeverity, CancellationToken cancellationToken)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var errorList = await GetRequiredGlobalServiceAsync <SVsErrorList, IErrorList>(cancellationToken);

            ((IVsErrorList)errorList).BringToFront();
            errorList.AreBuildErrorSourceEntriesShown = errorSource.HasFlag(ErrorSource.Build);
            errorList.AreOtherErrorSourceEntriesShown = errorSource.HasFlag(ErrorSource.Other);
            errorList.AreErrorsShown   = minimumSeverity >= __VSERRORCATEGORY.EC_ERROR;
            errorList.AreWarningsShown = minimumSeverity >= __VSERRORCATEGORY.EC_WARNING;
            errorList.AreMessagesShown = minimumSeverity >= __VSERRORCATEGORY.EC_MESSAGE;
        }
Ejemplo n.º 7
0
        private void VerifyConversion(__VSERRORCATEGORY vsSeverity, object expectedMoniker)
        {
            const AnalysisIssueSeverity value = AnalysisIssueSeverity.Info;

            var toVsSeverityConverterMock = new Mock <IAnalysisSeverityToVsSeverityConverter>();

            toVsSeverityConverterMock
            .Setup(x => x.Convert(value))
            .Returns(vsSeverity);

            var result   = (ImageMoniker) new SeverityToMonikerConverter(toVsSeverityConverterMock.Object).Convert(value, null, null, null);
            var expected = (ImageMoniker)expectedMoniker;

            result.Should().Be(expected);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Maps the <see cref="__VSERRORCATEGORY"/> to <see cref="DiagnosticSeverity"/>.
        /// </summary>
        /// <param name="errorCategory">The <see cref="__VSERRORCATEGORY"/>.</param>
        /// <returns>The matching <see cref="DiagnosticSeverity"/>. </returns>
        private static DiagnosticSeverity MapErrorCategoryToSeverity(__VSERRORCATEGORY errorCategory)
        {
            switch (errorCategory)
            {
            case __VSERRORCATEGORY.EC_ERROR:
                return(DiagnosticSeverity.Error);

            case __VSERRORCATEGORY.EC_WARNING:
                return(DiagnosticSeverity.Warning);

            case __VSERRORCATEGORY.EC_MESSAGE:
                return(DiagnosticSeverity.Info);
            }

            return(DiagnosticSeverity.Hidden);
        }
Ejemplo n.º 9
0
        public static string AsString(this __VSERRORCATEGORY errorCategory)
        {
            switch (errorCategory)
            {
            case __VSERRORCATEGORY.EC_MESSAGE:
                return("Message");

            case __VSERRORCATEGORY.EC_WARNING:
                return("Warning");

            case __VSERRORCATEGORY.EC_ERROR:
                return("Error");

            default:
                return("Unknown");
            }
        }
Ejemplo n.º 10
0
        public int GetErrorCount(__VSERRORCATEGORY minimumSeverity = __VSERRORCATEGORY.EC_WARNING)
        {
            var errorItems = GetErrorItems();

            try
            {
                return(errorItems
                       .AsEnumerable()
                       .Where(e => ((IVsErrorItem)e).GetCategory() <= minimumSeverity)
                       .Count());
            }
            catch (IndexOutOfRangeException)
            {
                // It is entirely possible that the items in the error list are modified
                // after we start iterating, in which case we want to try again.
                return(GetErrorCount(minimumSeverity));
            }
        }
Ejemplo n.º 11
0
        public async Task <ImmutableArray <string> > GetBuildErrorsAsync(__VSERRORCATEGORY minimumSeverity = __VSERRORCATEGORY.EC_WARNING)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync();

            var errorItems = await GetErrorItemsAsync();

            var list = new List <string>();

            foreach (var item in errorItems)
            {
                if (item.GetCategory() > minimumSeverity)
                {
                    continue;
                }

                if (!item.TryGetValue(StandardTableKeyNames.ErrorSource, out var errorSource) ||
                    (ErrorSource)errorSource != ErrorSource.Build)
                {
                    continue;
                }

                var source    = item.GetBuildTool();
                var document  = Path.GetFileName(item.GetPath() ?? item.GetDocumentName()) ?? "<unknown>";
                var line      = item.GetLine() ?? -1;
                var column    = item.GetColumn() ?? -1;
                var errorCode = item.GetErrorCode() ?? "<unknown>";
                var text      = item.GetText() ?? "<unknown>";
                var severity  = item.GetCategory() switch
                {
                    __VSERRORCATEGORY.EC_ERROR => "error",
                    __VSERRORCATEGORY.EC_WARNING => "warning",
                    __VSERRORCATEGORY.EC_MESSAGE => "info",
                    var unknown => unknown.ToString(),
                };

                var message = $"({source}) {document}({line + 1}, {column + 1}): {severity} {errorCode}: {text}";
                list.Add(message);
            }

            return(list
                   .OrderBy(x => x, StringComparer.OrdinalIgnoreCase)
                   .ThenBy(x => x, StringComparer.Ordinal)
                   .ToImmutableArray());
        }
Ejemplo n.º 12
0
        public MyTaskItem(IVsTaskProvider3 provider,
                          string document = "", int line = 0, int column = 0, string text = "", VSTASKCATEGORY category = VSTASKCATEGORY.CAT_USER, __VSERRORCATEGORY errorCategory = __VSERRORCATEGORY.EC_ERROR,
                          IEnumerable <string> customColumnText = null,
                          bool canDelete          = false, bool isChecked   = false, bool isReadOnly = false, bool hasHelp = false, bool customColumnsReadOnly = false,
                          int imageListIndex      = 0, int subcategoryIndex = 0,
                          VSTASKPRIORITY priority = VSTASKPRIORITY.TP_NORMAL)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            this.Provider  = provider;
            _document      = document;
            _line          = line;
            _column        = column;
            _text          = text;
            _category      = category;
            _errorCategory = errorCategory;

            if (customColumnText != null)
            {
                uint index = 0;
                foreach (var s in customColumnText)
                {
                    _customColumnText.Add(index++, s);
                }
            }

            _canDelete             = canDelete;
            _isChecked             = isChecked;
            _isReadOnly            = isReadOnly;
            _hasHelp               = hasHelp;
            _customColumnsReadOnly = customColumnsReadOnly;

            _imageListIndex   = imageListIndex;
            _subcategoryIndex = subcategoryIndex;

            _priority = priority;
        }
Ejemplo n.º 13
0
        public async Task SonarQubeIssueToErrorListCategoryMap(string issueType,
                                                               string issueSeverity,
                                                               string expectedErrorCategopry,
                                                               __VSERRORCATEGORY expectedErrorSeverity)
        {
            var componentsClient = new Mock <IComponentsClient>();

            componentsClient.
            Setup(i => i.GetAllProjects()).
            Returns(Task.FromResult(new List <SonarQubeProject>()
            {
                new SonarQubeProject()
                {
                    Key  = "A",
                    Name = "Project A"
                },
            }));

            var issuesClient = new Mock <IIssuesClient>();

            issuesClient.
            Setup(i => i.GetProjectIssues(It.Is <string>(key => key == "A"))).
            Returns(Task.FromResult(new List <SonarQubeIssue>()
            {
                new SonarQubeIssue()
                {
                    Rule      = "other:QACPP.3030",
                    Severity  = issueSeverity,
                    Component = "A:git/proj-a/src/a.cpp",
                    Line      = 182,
                    Message   = "QACPP[1:3030]  This expression casts between two pointer types.",
                    Type      = issueType
                },
            }));

            var client = new Mock <ISonarQubeClient>();

            client.SetupGet(i => i.SonarQubeApiUrl).Returns(new Uri("https://server.com/"));
            client.SetupGet(i => i.Components).Returns(componentsClient.Object);
            client.SetupGet(i => i.Issues).Returns(issuesClient.Object);

            var provider = new ErrorListProvider(client.Object);
            var errors   = await provider.GetErrorsAsync("A", null);

            var expected = new List <ErrorListItem>()
            {
                new ErrorListItem()
                {
                    ProjectName      = "",
                    FileName         = "git\\proj-a\\src\\a.cpp",
                    Line             = 181,
                    Message          = "This expression casts between two pointer types.",
                    ErrorCode        = "QACPP3030",
                    ErrorCodeToolTip = "Get help for 'QACPP3030'",
                    ErrorCategory    = expectedErrorCategopry,
                    Severity         = expectedErrorSeverity
                },
            };

            Assert.That(errors, Is.EqualTo(expected).Using(new ErrorListItemComparer()));
        }
Ejemplo n.º 14
0
 public void Convert_NotBlocker_CorrectlyMapped(AnalysisIssueSeverity severity, __VSERRORCATEGORY expectedVsErrorCategory)
 {
     testSubject.Convert(severity).Should().Be(expectedVsErrorCategory);
 }
Ejemplo n.º 15
0
        public void Convert_Blocker_CorrectlyMapped(bool shouldTreatBlockerAsError, __VSERRORCATEGORY expectedVsErrorCategory)
        {
            envSettingsMock.Setup(x => x.TreatBlockerSeverityAsError()).Returns(shouldTreatBlockerAsError);

            testSubject.Convert(AnalysisIssueSeverity.Blocker).Should().Be(expectedVsErrorCategory);
        }
Ejemplo n.º 16
0
        public async Task <ImmutableArray <string> > GetErrorsAsync(ErrorSource errorSource, __VSERRORCATEGORY minimumSeverity, CancellationToken cancellationToken)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var errorItems = await GetErrorItemsAsync(errorSource, minimumSeverity, cancellationToken);

            var list = errorItems.Select(GetMessage).ToList();

            return(list
                   .OrderBy(x => x, StringComparer.OrdinalIgnoreCase)
                   .ThenBy(x => x, StringComparer.Ordinal)
                   .ToImmutableArray());
        }
Ejemplo n.º 17
0
        private async Task <ImmutableArray <ITableEntryHandle> > GetErrorItemsAsync(ErrorSource errorSource, __VSERRORCATEGORY minimumSeverity, CancellationToken cancellationToken)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var errorList = await GetRequiredGlobalServiceAsync <SVsErrorList, IErrorList>(cancellationToken);

            var args = await errorList.TableControl.ForceUpdateAsync().WithCancellation(cancellationToken);

            return(args.AllEntries
                   .Where(item =>
            {
                if (item.GetCategory() > minimumSeverity)
                {
                    return false;
                }

                if (item.GetErrorSource() is not {
                } itemErrorSource ||
                    !errorSource.HasFlag(itemErrorSource))
                {
                    return false;
                }

                return true;
            })
                   .ToImmutableArray());
        }