Пример #1
0
        private static ErrorTask CreateTask(MinificationError error, ErrorListProvider provider)
        {
            ErrorTask task = new ErrorTask()
            {
                Line          = error.LineNumber,
                Column        = error.ColumnNumber,
                ErrorCategory = TaskErrorCategory.Error,
                Category      = TaskCategory.Html,
                Document      = error.FileName,
                Priority      = TaskPriority.Low,
                Text          = $"({Vsix.Name}) {error.Message}",
            };

            EnvDTE.ProjectItem item = BundlerMinifierPackage._dte.Solution.FindProjectItem(error.FileName);

            if (item != null && item.ContainingProject != null)
            {
                AddHierarchyItem(task, item.ContainingProject);
            }

            task.Navigate += (s, e) =>
            {
                provider.Navigate(task, new Guid(EnvDTE.Constants.vsViewKindPrimary));

                if (task.Column > 0)
                {
                    var doc = (EnvDTE.TextDocument)BundlerMinifierPackage._dte.ActiveDocument.Object("textdocument");
                    doc.Selection.MoveToLineAndOffset(task.Line, task.Column, false);
                }
            };

            return(task);
        }
Пример #2
0
        public async Task AddToErrorListAsync(IEnumerable <string> outputs)
        {
            _errorListProvider.Tasks.Clear();

            var errors   = new List <ErrorTask>();
            var messages = await _buildErrorProcessor.ExtractMessagesAsync(outputs);

            foreach (var message in messages)
            {
                var document = string.IsNullOrEmpty(message.SourceFile) // make unclickable error otherwise it will refer to the project root
                    ? ""
                    : message.SourceFile.IndexOfAny(Path.GetInvalidPathChars()) == -1
                        ? Path.Combine(_project.RootPath, message.SourceFile)
                        : "";
                var task = new ErrorTask
                {
                    Text          = message.Text,
                    Document      = document,
                    Line          = message.Line - 1,
                    Column        = message.Column,
                    ErrorCategory = ParseKind(message.Kind),
                    Category      = TaskCategory.BuildCompile,
                };
                task.Navigate += (sender, e) =>
                {
                    task.Line++; // just because vs error list is dumb. inside it dec 1 and jumps to this line
                    _errorListProvider.Navigate(task, Guid.Parse(/*EnvDTE.Constants.vsViewKindCode*/ "{7651A701-06E5-11D1-8EBD-00A0C90F26EA}"));
                    task.Line--;
                };
                _errorListProvider.Tasks.Add(task);
                errors.Add(task);
            }

            NotifyErrorTagger?.Invoke(errors);
        }
Пример #3
0
        private void AddError(TaskErrorCategory category, string projectFileName, string filePath, string text, int line, int column)
        {
            var          ivsSolution = (IVsSolution)Package.GetGlobalService(typeof(IVsSolution));
            IVsHierarchy hierarchyItem;

            ivsSolution.GetProjectOfUniqueName(projectFileName, out hierarchyItem);

            var error = new ErrorTask();

            error.Line          = line - 1;
            error.Column        = column;
            error.Text          = text;
            error.ErrorCategory = category;
            error.Category      = TaskCategory.BuildCompile;
            error.Document      = filePath;
            error.HierarchyItem = hierarchyItem;

            error.Navigate += (sender, e) =>
            {
                error.Line++;
                ErrorList.Navigate(error, new Guid(EnvDTE.Constants.vsViewKindCode));
                error.Line--;
            };
            ErrorList.Tasks.Add(error);
        }
Пример #4
0
        public static void Show(Diagnostic diag)
        {
            var task = new ErrorTask
            {
                Text          = string.Format(@"{0,4} : {1}", diag.ID, diag.Message),
                Category      = TaskCategory.CodeSense,
                ErrorCategory =
                    diag.Level == DiagnosticLevel.Warning
                                       ? TaskErrorCategory.Warning
                                       : TaskErrorCategory.Error,
                Column        = diag.StartColumn,
                Line          = diag.StartLine - 1,
                Document      = diag.FilePath,
                HierarchyItem = (IVsHierarchy)AVRStudio.GetProjectItem(dte, diag.FilePath).Object,
            };

            task.Navigate += (sender, args) =>
            {
                task.Line++;
                errorListProvider.Navigate(task, Guid.Parse(EnvDTE.Constants.vsViewKindCode));
                task.Line--;
            };

            errorListProvider.Tasks.Add(task);
        }
Пример #5
0
        private static ErrorTask CreateTask(CompilerError error, ErrorListProvider provider)
        {
            ErrorTask task = new ErrorTask()
            {
                Line = error.LineNumber,
                Column = error.ColumnNumber,
                ErrorCategory = error.IsWarning ? TaskErrorCategory.Warning : TaskErrorCategory.Error,
                Category = TaskCategory.BuildCompile,
                Document = error.FileName,
                Priority = TaskPriority.Normal,
                Text = $"(WebCompiler) {error.Message}",
            };

            EnvDTE.ProjectItem item = WebCompilerPackage._dte.Solution.FindProjectItem(error.FileName);

            if (item != null && item.ContainingProject != null)
                AddHierarchyItem(task, item.ContainingProject);

            task.Navigate += (s, e) =>
            {
                provider.Navigate(task, new Guid(EnvDTE.Constants.vsViewKindPrimary));

                if (task.Column > 0)
                {
                    var doc = (EnvDTE.TextDocument)WebCompilerPackage._dte.ActiveDocument.Object("textdocument");
                    doc.Selection.MoveToLineAndOffset(task.Line, task.Column, false);
                }
            };

            return task;
        }
Пример #6
0
        private static ErrorTask CreateTask(Error error, ErrorListProvider provider)
        {
            ErrorTask task = new ErrorTask()
            {
                Line          = error.Line + 1,
                Column        = error.Column + 1,
                ErrorCategory = TaskErrorCategory.Warning,
                Category      = TaskCategory.Html,
                Document      = error.File,
                Priority      = TaskPriority.Normal,
                Text          = $"({Vsix.Name}) {error.Message}",
            };

            var item = ProjectHelpers.DTE.Solution.FindProjectItem(error.File);

            if (item != null && item.ContainingProject != null)
            {
                AddHierarchyItem(task, item.ContainingProject);
            }

            task.Navigate += (s, e) =>
            {
                provider.Navigate(task, new Guid(EnvDTE.Constants.vsViewKindPrimary));

                if (task.Column > 0)
                {
                    var doc = (TextDocument)ProjectHelpers.DTE.ActiveDocument.Object("textdocument");
                    doc.Selection.MoveToLineAndOffset(task.Line, task.Column, false);
                }
            };

            return(task);
        }
Пример #7
0
        public static void AddError(Package package, string errorText)
        {
            var          ivsSolution       = (IVsSolution)Package.GetGlobalService(typeof(IVsSolution));
            var          errorListProvider = new ErrorListProvider(package);
            var          errorCategory     = TaskErrorCategory.Error;
            IVsHierarchy hierarchyItem;
            var          proj = GetActiveProject();
            var          projectUniqueName  = proj.FileName;
            var          firstFileInProject = GetSelectedItemPaths(EditProjectPackage.DTE).FirstOrDefault();

            ivsSolution.GetProjectOfUniqueName(projectUniqueName, out hierarchyItem);
            var newError = new ErrorTask()
            {
                ErrorCategory = errorCategory,
                Category      = TaskCategory.BuildCompile,
                Text          = errorText,
                Document      = firstFileInProject,
                Line          = 1,
                Column        = 1,
                HierarchyItem = hierarchyItem
            };

            newError.Navigate += (sender, e) =>
            {
                //there are two Bugs in the errorListProvider.Navigate method:
                //    Line number needs adjusting
                //    Column is not shown
                newError.Line++;
                errorListProvider.Navigate(newError, new Guid(EnvDTE.Constants.vsViewKindCode));
                newError.Line--;
            };
            errorListProvider.Tasks.Clear();       // clear previously created
            errorListProvider.Tasks.Add(newError); // add item
            errorListProvider.Show();              // make sure it is visible
        }
Пример #8
0
        void Navigate(object sender, EventArgs e)
        {
            var task = (ErrorTask)sender;

            task.Line++;
            ErrorListProvider.Navigate(task, new Guid(EnvDTE.Constants.vsViewKindCode));
            task.Line--;
        }
Пример #9
0
        private void NavigateTo(object sender, EventArgs e)
        {
            var errorTask = (ErrorTask)sender;

            errorTask.Line += 1; // Fix the index start
            var bResult = errorListProvider.Navigate(errorTask, new Guid(EnvDTE.Constants.vsViewKindCode));

            errorTask.Line -= 1; // Restore the index start
        }
Пример #10
0
        private void ErrorTaskNavigate(object sender, EventArgs e)
        {
            ErrorTask objErrorTask = (ErrorTask)sender;

            objErrorTask.Line += 1;
            bool bResult = mErrorProvider.Navigate(objErrorTask, new Guid(EnvDTE.Constants.vsViewKindCode));

            objErrorTask.Line -= 1;
        }
Пример #11
0
 private static void ErrorTaskOnNavigate(object sender, EventArgs eventArgs)
 {
     try {
         var task = (ErrorTask)sender;
         _errorListProvider.Navigate(task, new Guid(EnvDTE.Constants.vsViewKindCode));
     } catch {
         // Couldn't navigate
     }
 }
Пример #12
0
 private void GotoLine(object sender, EventArgs e)
 {
     if (sender is ErrorTask task)
     {
         task.Line++;
         _errorList.Navigate(task, _textViewGuid);
         task.Line--;
     }
 }
Пример #13
0
        private void task_Navigate(object sender, EventArgs e)
        {
            ErrorTask task = sender as ErrorTask;

            _provider.Navigate(task, new Guid(Constants.vsViewKindPrimary));

            var doc = (TextDocument)WebEssentialsPackage.DTE.ActiveDocument.Object("textdocument");

            doc.Selection.MoveToDisplayColumn(task.Line + 1, task.Column + 1);
        }
Пример #14
0
        void OTask_Navigate(object sender, EventArgs e)
        {
            TaskListItem OTask = (TaskListItem)sender;

            OTask.Line++;
            OTask.Column++;
            FProvider.Navigate(OTask, new Guid(EnvDTE.Constants.vsViewKindCode));
            OTask.Line--;
            OTask.Column--;
        }
        private void task_Navigate(object sender, EventArgs e)
        {
            ErrorTask task = (ErrorTask)sender;

            _errorlist.Navigate(task, new Guid("{00000000-0000-0000-0000-000000000000}"));

            var line  = _view.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(task.Line);
            var point = new SnapshotPoint(line.Snapshot, line.Start.Position + task.Column);

            _view.Caret.MoveTo(point);
        }
Пример #16
0
        private static void TaskOnNavigate(object sender, EventArgs eventArgs)
        {
            var task = sender as Task;

            if (task == null)
            {
                throw new ArgumentException("sender");
            }
            task.Line++; // Navigation starts counting from 1, do ++
            _errorListProvider.Navigate(task, new Guid(Constants.vsViewKindCode));
            task.Line--; // Back to normal, do --
        }
Пример #17
0
        private void task_Navigate(object sender, EventArgs e)
        {
            Task task = sender as Task;

            _provider.Navigate(task, new Guid(EnvDTE.Constants.vsViewKindPrimary));

            if (task.Column > 0)
            {
                var doc = (TextDocument)EditorExtensionsPackage.DTE.ActiveDocument.Object("textdocument");
                doc.Selection.MoveToLineAndOffset(task.Line, task.Column, false);
            }
        }
        void task_Navigate(object sender, EventArgs e)
        {
            ErrorTask error = sender as ErrorTask;

            if (error != null)
            {
                error.Line   += 1;
                error.Column += 1;
                _errorProvider.Navigate(error, new Guid(EnvDTE.Constants.vsViewKindCode));
                error.Column -= 1;
                error.Line   -= 1;
            }
        }
Пример #19
0
        public static void Parse(ErrorListProvider errorListProvider, string path)
        {
            lock (errorListProvider)
            {
                // Remove all tasks for the current file, since they're likely out-of-date
                // if the user has just saved
                RemoveStaleErrors(errorListProvider, path);

                // Show a message that we're executing; since this can be slow. Otherwise we'd
                // have to leave known-stale errors, or empty list (which suggests no errors).
                errorListProvider.Tasks.Add(new ErrorTask
                {
                    ErrorCategory = TaskErrorCategory.Message,
                    Document      = path,
                    Text          = "Executing DartAnalyzer, please wait..."
                });
            }


            IEnumerable <ErrorTask> errors;

            try
            {
                errors = new DartAnalyzer().Analyze(path);
            }
            catch (Exception ex)
            {
                // Update the error list eith the new errors
                lock (errorListProvider)
                {
                    RemoveStaleErrors(errorListProvider, path);
                    errorListProvider.Tasks.Add(new ErrorTask(new Exception("Unable to execute DartAnalzyer: " + ex.ToString())));
                    errorListProvider.Show();
                    return;
                }
            }

            // Update the error list eith the new errors
            lock (errorListProvider)
            {
                RemoveStaleErrors(errorListProvider, path);
                foreach (var error in errors)
                {
                    error.Navigate += (s, e) => errorListProvider.Navigate(error, new Guid(EnvDTE.Constants.vsViewKindCode));
                    errorListProvider.Tasks.Add(error);
                }
                errorListProvider.Show();
            }
        }
        private void ErrorTaskNavigate(object sender, EventArgs e)
        {
            ErrorTask task;

            try
            {
                task       = (ErrorTask)sender;
                task.Line += 1;
                _errorListProvider.Navigate(task, new Guid(EnvDTE.Constants.vsViewKindTextView));
                task.Line -= 1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #21
0
        private static void AddTask(ProjectItem projectItem, string message, TaskErrorCategory category, int line)
        {
            if (_initialized == false)
            {
                return;
            }

            try
            {
                var project  = projectItem.ContainingProject.FileName;
                var filename = projectItem.FileNames[0];

                IVsHierarchy hierarchyItem;
                _ivsSolution.GetProjectOfUniqueName(project, out hierarchyItem);

                var errorTask = new ErrorTask
                {
                    Category      = TaskCategory.BuildCompile,
                    ErrorCategory = category,
                    Text          = message,
                    Document      = filename,
                    Line          = line,
                    HierarchyItem = hierarchyItem
                };

                errorTask.Navigate += (sender, e) =>
                {
                    //there are two Bugs in the errorListProvider.Navigate method:
                    //    Line number needs adjusting
                    //    Column is not shown
                    errorTask.Line++;
                    var guid = new Guid(EnvDTE.Constants.vsViewKindCode);
                    _errorListProvider.Navigate(errorTask, guid);
                    errorTask.Line--;
                };

                _errorListProvider.Tasks.Add(errorTask);
            }
            catch (Exception exception)
            {
                Log.Error($"Failed to add task to Error List. {exception.Message}");
            }
        }
Пример #22
0
        internal void UpdateErrors(AnalysisErrorsNotification errorNotification)
        {
            errorProvider.SuspendRefresh();
            RemoveErrorsForFile(errorNotification.File);

            var errorTasks = errorNotification.Errors.Select(CreateErrorTask);

            foreach (var error in errorTasks)
            {
                error.Navigate += (s, e) =>
                {
                    error.Line++;                     // Line number seems 0-based in most places, but Navigate didn't get the memo :(
                    errorProvider.Navigate(error, new Guid(EnvDTE.Constants.vsViewKindCode));
                    error.Line--;
                };
                errorProvider.Tasks.Add(error);
            }
            errorProvider.ResumeRefresh();
            errorProvider.Show();
            errorProvider.ForceShowErrors();
        }
Пример #23
0
        public bool AugmentProject(Project project)
        {
            try
            {
                while (!Lexer.Empty)
                {
                    var sumtype = SumType.Parse(this);
                    if (sumtype != null)
                    {
                        project.RegisterSumType(sumtype.Name, sumtype.Type);
                        continue;
                    }

                    var strongalias = StrongAlias.Parse(this);
                    if (strongalias != null)
                    {
                        project.RegisterStrongAlias(strongalias.Name, strongalias.Type);
                        continue;
                    }

                    var weakalias = WeakAlias.Parse(this);
                    if (weakalias != null)
                    {
                        project.RegisterWeakAlias(weakalias.Name, weakalias.Type);
                        continue;
                    }

                    var structure = Structure.Parse(this);
                    if (structure != null)
                    {
                        project.RegisterStructureType(structure.Name, structure.Object);
                        continue;
                    }

                    var globals = GlobalBlock.Parse(this);
                    if (globals != null)
                    {
                        globals.AugmentProject(project);
                        continue;
                    }

                    var function = FunctionSignature.Parse(this);
                    if (function != null)
                    {
                        project.RegisterFunction(function);
                        continue;
                    }

                    if (!Lexer.Empty)
                    {
                        throw new SyntaxError("Syntax error", PeekToken(0));
                    }
                }
            }
            catch (SyntaxError ex)
            {
                var errorTask = new ErrorTask();
                errorTask.Text          = ex.Message;
                errorTask.Category      = TaskCategory.CodeSense;
                errorTask.ErrorCategory = TaskErrorCategory.Error;
                errorTask.Document      = Lexer.FileName;
                errorTask.Line          = (ex.Origin != null) ? (ex.Origin.Line) : 0;
                errorTask.Column        = (ex.Origin != null) ? (ex.Origin.Column) : 0;
                errorTask.Navigate     += (sender, e) =>
                {
                    ErrorProvider.Navigate(errorTask, VSConstants.LOGVIEWID.Code_guid);
                };

                ErrorProvider.Tasks.Add(errorTask);
                return(false);
            }

            return(true);
        }
Пример #24
0
        public static ErrorTask AddTask(this ErrorListProvider errorListProvider, Diagnostic diagnostic, DTEProject project)
        {
            if (errorListProvider == null)
            {
                throw new ArgumentNullException(nameof(errorListProvider));
            }
            if (diagnostic == null)
            {
                throw new ArgumentNullException(nameof(diagnostic));
            }
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            TaskErrorCategory category;

            switch (diagnostic.Severity)
            {
            case DiagnosticSeverity.Hidden:
                category = TaskErrorCategory.Message;
                break;

            case DiagnosticSeverity.Info:
                category = TaskErrorCategory.Message;
                break;

            case DiagnosticSeverity.Warning:
                category = TaskErrorCategory.Warning;
                break;

            case DiagnosticSeverity.Error:
                category = TaskErrorCategory.Error;
                break;

            default:
                category = TaskErrorCategory.Message;
                break;
            }

            var task = new ErrorTask
            {
                ErrorCategory = category,
                CanDelete     = true,
                Category      = TaskCategory.Misc,
                Text          = diagnostic.GetMessage(),
                Line          = diagnostic.Location.GetLineSpan().StartLinePosition.Line,
                Column        = diagnostic.Location.GetLineSpan().StartLinePosition.Character,
                Document      = diagnostic.Location.GetLineSpan().Path,
                HierarchyItem = project.GetProjectHierarchyItem()
            };

            task.Navigate += (sender, e) =>
            {
                //there are two Bugs in the errorListProvider.Navigate method:
                //    Line number needs adjusting
                //    Column is not shown
                task.Line++;
                errorListProvider.Navigate(task, new Guid(EnvDTE.Constants.vsViewKindCode));
                task.Line--;
            };

            errorListProvider.Tasks.Add(task);

            return(task);
        }
Пример #25
0
 /// <summary>
 /// Navigates to the source code associated with the specified task
 /// </summary>
 /// <param name="task">Error task</param>
 public void Navigate(ErrorTask task)
 {
     _errorListProvider.Navigate(task, VSConstants.LOGVIEWID_Primary);
 }
Пример #26
0
        public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag
        {
            if (errorListProvider == null)
            {
                dte                      = (DTE)ServiceProvider.GetService(typeof(DTE));
                events                   = dte.Events;
                docEvents                = events.DocumentEvents;
                errorListProvider        = new ErrorListProvider(ServiceProvider);
                docEvents.DocumentSaved += doc => { if (saveEvent != null)
                                                    {
                                                        saveEvent.Invoke(doc.FullName);
                                                    }
                };
            }

            var document = (ITextDocument)buffer.Properties[typeof(ITextDocument)];

            if (!filesStartedFor.Contains(document.FilePath))
            {
                IVsUIHierarchy hierarchy;
                uint           itemId;
                IVsWindowFrame frame;
                if (VsShellUtilities.IsDocumentOpen(ServiceProvider, document.FilePath, Guid.Empty, out hierarchy, out itemId, out frame))
                {
                    var tv = VsShellUtilities.GetTextView(frame);
                    IOleCommandTarget nextCommandTarget;
                    var cmdHandler = new CommandHandler(tv);
                    tv.AddCommandFilter(cmdHandler, out nextCommandTarget);
                    cmdHandler.NextCommandTarget = nextCommandTarget;
                }
                filesStartedFor.Add(document.FilePath);

                Action <string> handler = doc =>
                {
                    var lastMod = new FileInfo(doc).LastWriteTime;
                    if (lastDiagnosticSignature != lastMod)
                    {
                        lastDiagnosticSignature = lastMod;
                        errorListProvider.Tasks.Clear();
                        errorListProvider.Refresh();
                        aggregator.Clear();
                        if (MyControl.CurrentInstance != null)
                        {
                            MyControl.CurrentInstance.RestartInstance(doc);
                        }
                    }
                    var errors = Diagnostics.GetErrors(buffer, document);
                    foreach (var error in errors)
                    {
                        bool skip = aggregator.Any(entry =>
                                                   entry.Line == error.Line &&
                                                   entry.Column == error.Column &&
                                                   entry.FileName == error.FileName &&
                                                   entry.Message == error.Message
                                                   );
                        if (skip)
                        {
                            continue;
                        }
                        var errorTask = new ErrorTask
                        {
                            ErrorCategory = error.Severity,
                            Category      = TaskCategory.BuildCompile,
                            Text          = error.Message,
                            Document      = error.FileName,
                            Line          = error.Line,
                            Column        = error.Column,
                        };
                        errorTask.Navigate += (sender, args) =>
                        {
                            errorTask.Line++;
                            errorListProvider.Navigate(errorTask, new Guid("{7651A701-06E5-11D1-8EBD-00A0C90F26EA}") /* EnvDTE.Constants.vsViewKindCode */);
                            errorTask.Line--;
                        };
                        errorListProvider.Tasks.Add(errorTask);
                        aggregator.Add(error);
                    }
                    errorListProvider.Refresh();
                    errorListProvider.Show();
                };
                saveEvent += handler;
                saveEvent.Invoke(document.FilePath);
            }
            return(new ErrorTagger() as ITagger <T>);
        }