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() )); }
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)); } }
public async Task <int> GetErrorCountAsync(__VSERRORCATEGORY minimumSeverity = __VSERRORCATEGORY.EC_WARNING) { await JoinableTaskFactory.SwitchToMainThreadAsync(); var errorItems = await GetErrorItemsAsync(); return(errorItems.Count(e => e.GetCategory() <= minimumSeverity)); }
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; }
public ItemControl(ImageMoniker icon, __VSERRORCATEGORY category) { _icon = icon; _category = category; Orientation = Orientation.Horizontal; VerticalAlignment = VerticalAlignment.Center; Visibility = Visibility.Collapsed; Options.Saved += OptionsSaved; }
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; }
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); }
/// <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); }
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"); } }
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)); } }
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()); }
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; }
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())); }
public void Convert_NotBlocker_CorrectlyMapped(AnalysisIssueSeverity severity, __VSERRORCATEGORY expectedVsErrorCategory) { testSubject.Convert(severity).Should().Be(expectedVsErrorCategory); }
public void Convert_Blocker_CorrectlyMapped(bool shouldTreatBlockerAsError, __VSERRORCATEGORY expectedVsErrorCategory) { envSettingsMock.Setup(x => x.TreatBlockerSeverityAsError()).Returns(shouldTreatBlockerAsError); testSubject.Convert(AnalysisIssueSeverity.Blocker).Should().Be(expectedVsErrorCategory); }
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()); }
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()); }