Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

Clear error list from duplicates

$
0
0

Hello guys, 

this should be fairly common problem, however I have not find the solution yet.


I am logging errors in two ways:

1) When you work with IWpfTextView individually. 
This is the code I am using:

 internal class TaskListPresenter
    {
        private readonly ICodeService _codeService;
        private readonly ErrorListProvider _errorList;

        private readonly IWpfTextView _textView;

        private int _bufferTrackIndex = 0;
        private IVsSolution _vsSolution;

        public TaskListPresenter(IWpfTextView textView, IServiceProvider serviceProvider)
        {
            _textView = textView;
            _textView.TextBuffer.Changed += OnTextBufferChanged;
            _textView.Closed += OnTextViewClosed;

            _codeService = serviceProvider.GetService(typeof (ICodeService)) as ICodeService;
            _vsSolution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;

            _errorList = new ErrorListProvider(serviceProvider);

            CreateErrors(_bufferTrackIndex);
        }

        private void OnTextViewClosed(object sender, EventArgs e)
        {
            // when a text view is closed we want to remove the corresponding errors from the error list
            ClearErrors();

        }

        private void OnTextBufferChanged(object sender, TextContentChangedEventArgs e)
        {
            var dt = new DispatcherTimer(DispatcherPriority.Send);
            dt.Tick += (s, ev) =>
            {
                dt.Stop();
                CreateErrors(++_bufferTrackIndex);
            };
            dt.Interval = TimeSpan.FromMilliseconds(2500);
            dt.Start();
        }

        private void ClearErrors()
        {
            _errorList.Tasks.Clear();
        }

        private void CreateErrors(int index)
        {
            // if the track index is not the same as passed index,
            // it means that this is "old"
            if (_bufferTrackIndex != index)
                return;

            var textBuffer = _textView.TextBuffer;
            var report = _codeService.Analyze(textBuffer.CurrentSnapshot.GetText());

            ClearErrors();

            var uniqueFileName =
                _textView.TextBuffer.Properties.GetProperty<ITextDocument>(typeof (ITextDocument)).FilePath;

            IVsHierarchy objVsHierarchy = null;
            var project = ProjectFileHelper.GetContainingProject(uniqueFileName);
            if (project != null)
                ErrorHandler.ThrowOnFailure(_vsSolution.GetProjectOfUniqueName(project.UniqueName, out objVsHierarchy));

            foreach (var message in report.Issues)
            {
                var sourceSpan = message.SourceSpan;

                int startIndex =
                    textBuffer.CurrentSnapshot.GetLineFromLineNumber(sourceSpan.Location.Line).Start.Position +
                    sourceSpan.Location.Column;

                //var span = new Span(message.SourceSpan.Location.Position, message.SourceSpan.Length);
                var span = new Span(startIndex, sourceSpan.Length);

                // creates the instance that will be added to the Error List
                var task = new ErrorTask
                {
                    Category = TaskCategory.All,
                    Priority = TaskPriority.Normal,
                    Document = uniqueFileName,
                    ErrorCategory = TranslateErrorCategory(message.IssueType),
                    Text = message.Content,
                    Line = message.SourceSpan.Location.Line,

                    Column = message.SourceSpan.Location.Column,
                    HierarchyItem = objVsHierarchy
                };

                task.Navigate += OnTaskNavigate;
                _errorList.Tasks.Add(task);
            }
        }
    }
As you can see, nothing fancy. If you change buffer in IWpfTextView, it'll create errors & log these.

Now, I also "log" errors in second place, namely when you rebuild/build.
This happens in my custom MSBUILD task, I use 'new TaskLoggingHelper(this.Log)' Microsoft class to actually log my error messages. 


The problem comes from the fact that my errors are now duplicated:

Say I work with IWpfTextView AFTER I've rebuild the project, I will add "duplicate" error now.
The problem is that I have no "connection" between those different logging mechanisms. 


One has no idea about another(nor its messages) and vice versa. How do you deal with this? Custom MPF project.





C#/C++ | WPF/DirectShow/OpenGL/Winapi/



Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>