private void ApplyTextEdits(ITextBuffer textbuffer, ITextSnapshot snapshot)
        {
            using (ITextEdit bufferEdit = textbuffer.CreateEdit())
            {
                foreach (ReplacementEdit edit in this.edits)
                {
                    SnapshotSpan translatedSpan = edit.Span.TranslateTo(snapshot, SpanTrackingMode.EdgeExclusive);
                    bufferEdit.Replace(translatedSpan.Span, edit.Text);
                }

                bufferEdit.Apply();
            }

            SarifLocationTagHelpers.RefreshTags(this.textBuffer);
        }
예제 #2
0
        /// <summary>
        /// Closes the specified SARIF log in the viewer.
        /// </summary>
        /// <param name="logFiles">The complete path to the SARIF log file.</param>
        public static void CloseSarifLogs(IEnumerable <string> logFiles)
        {
            SarifTableDataSource.Instance.ClearErrorsForLogFiles(logFiles);

            var runIdsToClear = new List <int>();

            foreach (string logFile in logFiles)
            {
                // The null conditional operator in the Where clause is necessary because log files
                // that come in through the API ILoadSarifLogService.LoadSarifLog(Stream) don't have
                // a file name. The good news is, we never close such a log file. If in future we
                // do need to close such a log file, we'll need to synthesize a log file name so we
                // know which runs belong to that file.
                runIdsToClear.AddRange(CodeAnalysisResultManager.Instance.RunIndexToRunDataCache.
                                       Where(runDataCacheKvp => runDataCacheKvp.Value.LogFilePath?.Equals(logFile, StringComparison.OrdinalIgnoreCase) == true).
                                       Select(runDataCacheKvp => runDataCacheKvp.Key));

                if (CodeAnalysisResultManager.Instance.RunIndexToRunDataCache
                    .Any(kvp => kvp.Value.SarifErrors
                         .Any(error => error.FileName?.Equals(logFile, StringComparison.OrdinalIgnoreCase) == true)))
                {
                    KeyValuePair <int, RunDataCache> cache = CodeAnalysisResultManager.Instance.RunIndexToRunDataCache
                                                             .First(kvp => kvp.Value.SarifErrors
                                                                    .Any(error => error.FileName?.Equals(logFile, StringComparison.OrdinalIgnoreCase) == true));
                    SarifErrorListItem sarifError = cache.Value.SarifErrors.First(error => error.FileName?.Equals(logFile, StringComparison.OrdinalIgnoreCase) == true);
                    cache.Value.SarifErrors.Remove(sarifError);

                    CodeAnalysisResultManager.Instance.RunIndexToRunDataCache[cache.Key] = cache.Value;
                }

                SarifLogsMonitor.Instance.StopWatch(logFile);
            }

            foreach (int runIdToClear in runIdsToClear)
            {
                CodeAnalysisResultManager.Instance.RunIndexToRunDataCache.Remove(runIdToClear);
            }

            SarifLocationTagHelpers.RefreshTags();
        }
예제 #3
0
        private int WriteRunToErrorList(Run run, string logFilePath, SarifLog sarifLog)
        {
            if (!SarifViewerPackage.IsUnitTesting)
            {
#pragma warning disable VSTHRD108 // Assert thread affinity unconditionally
                ThreadHelper.ThrowIfNotOnUIThread();
#pragma warning restore VSTHRD108
            }

            int runIndex  = CodeAnalysisResultManager.Instance.GetNextRunIndex();
            var dataCache = new RunDataCache(runIndex, logFilePath, sarifLog);
            CodeAnalysisResultManager.Instance.RunIndexToRunDataCache.Add(runIndex, dataCache);
            CodeAnalysisResultManager.Instance.CacheUriBasePaths(run);
            var sarifErrors = new List <SarifErrorListItem>();

            var dte = Package.GetGlobalService(typeof(DTE)) as DTE2;

            var projectNameCache = new ProjectNameCache(dte?.Solution);

            this.StoreFileDetails(run.Artifacts);

            if (run.Results != null)
            {
                foreach (Result result in run.Results)
                {
                    result.Run = run;
                    var sarifError = new SarifErrorListItem(run, runIndex, result, logFilePath, projectNameCache);
                    sarifErrors.Add(sarifError);
                }
            }

            if (run.Invocations != null)
            {
                foreach (Invocation invocation in run.Invocations)
                {
                    if (invocation.ToolConfigurationNotifications != null)
                    {
                        foreach (Notification configurationNotification in invocation.ToolConfigurationNotifications)
                        {
                            var sarifError = new SarifErrorListItem(run, runIndex, configurationNotification, logFilePath, projectNameCache);
                            sarifErrors.Add(sarifError);
                        }
                    }

                    if (invocation.ToolExecutionNotifications != null)
                    {
                        foreach (Notification toolNotification in invocation.ToolExecutionNotifications)
                        {
                            if (toolNotification.Level != FailureLevel.Note)
                            {
                                var sarifError = new SarifErrorListItem(run, runIndex, toolNotification, logFilePath, projectNameCache);
                                sarifErrors.Add(sarifError);
                            }
                        }
                    }
                }
            }

            if (run.HasAbsentResults())
            {
                this.ShowFilteredCategoryColumn();
            }

            if (run.HasSuppressedResults())
            {
                this.ShowFilteredSuppressionStateColumn();
            }

            (dataCache.SarifErrors as List <SarifErrorListItem>).AddRange(sarifErrors);
            SarifTableDataSource.Instance.AddErrors(sarifErrors);

            // This causes already open "text views" to be tagged when SARIF logs are processed after a view is opened.
            SarifLocationTagHelpers.RefreshTags();

            return(sarifErrors.Count);
        }
예제 #4
0
 public static void CleanAllErrors()
 {
     SarifTableDataSource.Instance.CleanAllErrors();
     CodeAnalysisResultManager.Instance.RunIndexToRunDataCache.Clear();
     SarifLocationTagHelpers.RefreshTags();
 }