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 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());
        }
Example #3
0
        public async Task <ImmutableArray <string> > GetErrorsAsync(ErrorSource errorSource, __VSERRORCATEGORY minimumSeverity, CancellationToken cancellationToken)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var errorItems = await GetErrorItemsAsync(cancellationToken);

            var list = new List <string>();

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

                if (!item.TryGetValue(StandardTableKeyNames.ErrorSource, out ErrorSource itemErrorSource) ||
                    !errorSource.HasFlag(itemErrorSource))
                {
                    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());
        }