ErrorList plugin user's guide

Version 2.1.1 (May 31 2013)

Slava Pestov

Legal Notice

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no "Invariant Sections", "Front-Cover Texts" or "Back-Cover Texts", each as defined in the license. A copy of the license can be found in the file COPYING.DOC.txt included with jEdit.


Table of Contents

Introduction

The ErrorList plugin displays errors and warnings generated by other plugins. It does nothing on its own; for it to be useful, some plugins that support the error reporting API must be installed.

The error reporting API is particularly well-suited to reporting compiler errors and such; plugins that use this API include Console, JCompiler, and SideKick. If you would like to use it from your plugin, see the section called “The error reporting API”.

FileOpenerService and FastOpen/SmartOpen.

In projects with multiple subfolders, a build error message may not report the complete pathname of the file with the error, and ErrorList may not know where the file is. In such a case, it can use a FileOpenerService, such as FastOpen or SmartOpen, to open the file for you. Since each of these plugins can search the current project or the open buffers, this gives you flexibility on how ErrorList can open the files it is displaying errors for in the dockable. To use a FileOpenerService, simply install one of these plugins: SmartOpen or FastOpen.

The error list window

Plugins>Error List>Error List displays the error list window.

Errors are shown in a tree control, with each branch being a file, and each leaf an error. Clicking on a file will open that file; clicking on an error will open the file containing the error and move the caret to its location.

The buttons with the error and warning icons on the left of the window toolbar enable you to toggle the display of errors and warnings.

The error reporting API supports two types of errors; genuine errors and warnings. The two are differentiated with different-colored icons in the tree; errors have a red icon, warnings have a yellow one.

For information on keyboard-based navigation of the tree, see the section called “Additional commands”.

Error highlighting

The ErrorList plugin highlights errors in-place in the text area with a colored underline. The color depends on the error type; genuine errors have a red underline, warnings have a yellow one.

Hovering the mouse over a line with an error highlight will show a tooltip with the error message.

Error highlighting can be disabled in the Error List pane of the Plugin Options dialog box. The colors of the underlines can also be changed in that same option pane.

Error overview

When a buffer has errors, the ErrorList plugin displays a global overview of all errors in a vertical bar to the left of the text area's vertical scroll bar. Each error is shown as a thin horizontal line. The color depends on the error type; genuine errors have a red underline, warnings have a yellow one. Clicking on an error will scroll the text area to that location. Hovering the mouse over an error will show a tooltip with the error message.

The error overview can be disabled in the Error List pane of the Plugin Options dialog box. The colors of the highlights can also be changed in that same option pane.

Additional commands

The ErrorList plugin provides a few additional commands that can be bound to keyboard shortcuts in the Shortcuts pane of the Global Options dialog box.

Plugins>Error List>Go to Previous Error moves the caret to the error immediately before the one currently selected in the error list window. If no error is selected, the last error in the list is chosen. This will open the appropriate file if the error is in a different file.

Plugins>Error List>Go to Next Error moves the caret to the error immediately after the one currently selected in the error list window. If no error is selected, the first error in the list is chosen. This will open the appropriate file if the error is in a different file.

Plugins>Error List>Go to Previous File With Errors opens the file immediately before the one currently selected in the error list window. If no file is selected, the last file with errors is chosen.

Plugins>Error List>Go to Next File With Errors opens the file immediately after the one currently selected in the error list window. If no file is selected, the first file with errors is chosen.

Plugins>Error List>Toggle Display of Errors toggles the display of errors in the tree.

Plugins>Error List>Toggle Display of Warnings toggles the display of warnings in the tree.

ErrorList Options

Errorlist offers the following configurable options.

Automatically Display on Error

Show the errorlist whenever an error is found

Auto-close on no errors

Hide the errorlist when there are no errors

Auto-refocus on text area

Give the TextArea keyboard focus after the ErrorList is shown

Show Error Overview

Show totals (errors/warnings) at top of errorlist

Filename Filters

Select whether you want the glob pattern to be for inclusion or exclusion, and enter a glob pattern below. For example: *.{c,h} specifies all C source and header files. See Appendix D. "Glob Patterns" in the jEdit users guide for more details.

Show Icons instead of Underlines

To make jEdit more "eclipse-like" put icons in the gutter instead of underlines.

The error reporting API

The error reporting API is very simple. A plugin that wishes to use it must do these three things:

  • Specify that it requires the ErrorList plugin.

  • Register an "error source" at some stage, usually during startup.

  • Add errors to the error source when they occur.

The ErrorList plugin handles the rest (displaying errors in a list, error highlighting, and so on) automatically.

Note

All error list classes mentioned in this section are contained in the errorlist package. So you should add an import statement like the following to the start of your plugin's source file(s):

import errorlist.*;
Specifying dependencies

In order to give the user a helpful error message if the ErrorList plugin is not installed, your plugin should specify dependency properties. If your plugin's core class is named MyPlugin, the corresponding dependencies might look like so:

plugin.MyPlugin.depend.0=jedit 04.02.02.00
plugin.MyPlugin.depend.2=plugin errorlist.ErrorListPlugin 1.3

Note that the current version of the ErrorList plugin requires jEdit 4.2pre2 or later, so your plugin should also require at least that jEdit version. If a newer version of the ErrorList plugin is available, you can specify higher version numbers than in the example above. However, all the API calls in this section are guaranteed to work with the above version, so in most cases you shouldn't worry about it.

Creating and registering an error source

Errors are managed by implementations of the errorlist.ErrorSource abstract class. Extending this class is a bit involved and requires writing a lot of low-level code; most plugins can use the errorlist.DefaultErrorSource class instead, which provides a very easy-to-use front-end.

The constructor for the DefaultErrorSource class accepts two parameters; the first is a string that will identify the error source. Currently, this identifier is not used, but in the future the ErrorList plugin might show which error comes from which plugin, for example. The second argument is the View that errors should be shown in. Plugins that send errors should take care to send them to the correct View's ErrorList, so that they do not appear in all Views.

Error sources should be registered when the user first invokes your plugins. A plugin can create any number of error sources. The Console plugin, for example, maintains a separate error source for each console window, and registers an unregisters them as each command is executed.

To add an error source to the list of registered error sources, you must call the static registerErrorSource() method of the errorlist.ErrorSource class.

A corresponding unregisterErrorSource() method must be called before your plugin is unloaded to avoid leaking memory.

Reporting errors

A custom ErrorSource implementation would need to send the appropriate EditBus message when an error arrives, and then provide implementations of various "getter" methods that the ErrorList plugin would later call to obtain the error. Using DefaultErrorSource makes the task much easier. In fact, all that is involved is calling a single method on the appropriate DefaultErrorSource instance:

public void addError(DefaultErrorSource.DefaultError error);
 

The constructor of the DefaultErrorSource.DefaultError class is as follows:

public DefaultError(int type,
 String path,
 int line,
 int start,
 int end,
 String message);
 
  • type - this should be either ErrorSource.ERROR or ErrorSource.WARNING.

  • path - the path, filename, or URL of the file containing the error. If this is just a filename, ErrorList will use a FileOpenerService to open the buffer.

  • line - the line number in the file where the error occurred. Lines are numbered starting from zero; since most tools and compilers report line numbers starting from 1, you might need to subtract 1 from the number before passing it to this method.

  • start - an offset in the line where the error begins.

  • end - an offset in the line where the error ends. These two values are only used to give a more exact display for error highlighting, and if both are zero, the entire line will be highlighted.

  • message - the error message itself, as shown in the error list window and error highlighting tooltips.

This method is fully thread safe; if your plugin generates errors from another thread, it can call this method without having to use any of the usual SwingUtilities.invokeLater() tricks required when calling non-thread safe methods.

Here are two examples of addError() calls. The first adds a warning, covering the entire line, the second adds an error that only applies to a subset of the specified line:

errorSource.addError(new ErrorSource.DefaultError(
    ErrorSource.WARNING,path,line,0,0,
    "Are you sure this is what you intended?"));
errorSource.addError(new ErrorSource.DefaultError(
    ErrorSource.WARNING,
    MiscUtilities.constructPath(directory,"input.src"),
    line,0,5,"First five characters of line are bad"));

Multiple-line messages can be created by calling the following method on the DefaultError instance before it is added to the error source (the last part is important, otherwise the extra messages will not be shown):

public void addExtraMessage(String extra);
 

That's basically all there is to it. There is one more method in the DefaultErrorSource class that needs to be mentioned:

public void clear(void); 
 

This method removes all errors from the error source. It is typically called before each invocation of the operation that generates errors; for example, the Console plugin clears its error source before each new command is run.

public void removeFileErrors(void); 
 

For more selective error removal, this method can be used to remove errors associated with one file only.

Performance Considerations

Only create and register an ErrorSource instance when necessary. Do not do this in your plugin's start() method, since that forces the ErrorList to be loaded, etc. The "lazy" fashion is the best: Register the error source only after sending the first error.

A. Change log
  • Version 2.2.  Requires Java 1.6, and jEdit 5.0

    • Revisited #3596333: Preserve contents when floating/docking.

  • Version 2.1.  Requires Java 1.6, and jEdit 5.0

    • Fixed #3573458: ErrorList does not work with SymLinks (Patrick Eibl)

    • Fixed errors not appearing without manual dockable activation, a bug introduced in version 2.0 (#3556671 Jarek Czekalski)

    • Added squiggle underline style (Matthieu Casanova)

    • "Clear Errors" no longer clears errors in all views (Alan Ezust).

    • Fixed #3596333: bad initial contents when creating a new view (Alan Ezust).

    • German localization (Robert Schwenn)

  • Version 2.0.  Requires Java 1.6, and jEdit 5.0pre1.

    • Uses jEdit 5's FileOpenerService for filenames when no full path is supplied to the DefaultError. (#3481157 - Alan Ezust)

    • New API for specifying the View of an ErrorSource. (#2106739 - Alan Ezust)

    • Fixed a deadlock and concurrency issues. (#3526070, #3530999 Jarek Czekalski)

    • Fixed errors appearing twice at first time. (#3028049 Jarek Czekalski)

    • French localization (jojaba_67)

  • Version 1.9. requires Java 1.5, and jEdit 4.3.

    • Fixed deadlock condition arising from new EditBus behavior in jEdit 4.4 (Kazutoshi Satoda)

  • Version 1.8. requires Java 1.5, and jEdit 4.3pre7.

    • display error.extraMessages in GutterIcon (Dwayne Bernard - # 1854405)

    • Remembers state of error/warning buttons (Shlomy Reinstein)

    • Automatically Show on Errors no longer shows when only hidden warnings pass through (#2907190 - Shlomy Reinstein)

    • No longer displays ErrorList when adding a zero-length ErrorSource. (#1869137 - Alan Ezust)

    • Enable multiple errors at different offsets in a same line. (Patch #2011885 - kerik)

  • Version 1.7. requires Java 1.5, and jEdit 4.3pre7.

    • DefaultErrorSource.DefaultError has new method: setFilePath() (for SshConsole).

  • Version 1.6. requires Java 1.5, and jEdit 4.3pre7.

    • New option to hide warnings (patch 1719791 by Shlomy Reinstein)

    • New options to filter files based on filename globs. (Shlomy Reinstein)

    • New option to show icons instead of underlines under errors (Shlomy Reinstein, 1653073)

    • Improved keyboard Handling when ErrorList has focus (patch 1729970 by k_satoda)

  • Version 1.5. requires Java 1.4, and jEdit 4.2 final.

    • Bugfix to avoid displaying duplicate errors (k_satoda).

    • New option: autoRefocusTextArea: When ErrorList gets focus, it now deliberately passes the focus back to the current jEditTextArea. (ezust)

  • Version 1.4. requires jEdit 4.2final.

    • Add option to close error list after no errors remain (Gerd Knops).

    • Option "Automatically display on error" no longer causes ErrorList to request the focus, so that the cursor stays in the edit pane (Dirk Moebius).

  • Version 1.3.2. requires jEdit 4.2pre8.

    • After adding and adding an error source, removing and adding it again would not add the error source to the EditBus, so it would not receive notifications of buffers being opened, and as a result floating positions for errors would not be created.

    • Fix display of selected entires in the error list when using the GTK look and feel.

    • New icons for errors and warnings.

  • Version 1.3.1. requires jEdit 4.2pre2.

    • Show on error option didn't always work.

    • Fixed exception when using GTK+ look and feel.

    • Fixed assorted problems when file paths contained symbolic links.

  • Version 1.3. requires jEdit 4.2pre2.

    • Added optional "error overview" to the right of the text area (on by default).

    • Added buttons to the error list window for going to the next and previous error and file with errors, respectively.

    • Fixed problem with errors appearing twice when the Show on error option was on.

    • Fixed problems with soft wrap.

    • Fixed problems with split views.

    • Updated for jEdit 4.2 API changes.

    • Added removeFileErrors() method to DefaultErrorSource class.

    • Performance improvements.

  • Version 1.2.3. requires jEdit 4.1pre2.

    • The error list no longer flashes like a deprived man due to constant tree collapsing and expansion if errors are being added in a background thread.

    • Error tool tips were not shown for some errors.

    • Highlighter no longer paints wavy lines, since with some fonts this would result in the line extending below the bottom of the text descent. Now the error highlights are plain vanilla underlines.

    • Fixed minor issue with error tree root node.

    • Updated code to use a few 4.1 API additions.

  • Version 1.2.2. requires jEdit 4.0pre4.

    • Fixed possible NullPointerException under Java 2 version 1.4.

    • Error highlight didn't work properly when soft wrap was enabled.

    • If the "show on error" feature is enabled, the error list will now open in the currently focused view, not the most recently opened view as before.

  • Version 1.2.1. requires jEdit 4.0pre4.

    • Updated to use jEdit 4.0pre4 text area extension API.

  • Version 1.2. requires jEdit 4.0pre1.

  • Version 1.1.2. requires jEdit 3.2pre8 and the EditBus plugin 1.1.

    • If the error list was open but not visible, the Show on error option would do nothing.

    • If no error sources were registered, all highlights added after the error list would not be painted.

  • Version 1.1.1. requires jEdit 3.2pre8 and the EditBus plugin 1.1.

    • Line numbers in the tree are now increased by one, so that they match the textarea line numbers (Dirk Moebius)

    • The commands "Next/Previous Error" and "Next/Previous File With Errors" now ensure that the newly selected error is visible (Dirk Moebius)

    • Supports multiple-line error messages, introduced by EditBus 1.1

  • Version 1.1. requires jEdit 3.2pre8 and the EditBus plugin 1.0.1.

    • Errors are now shown in a tree, not a list

    • Error highlighting does not highlight leading whitespace of lines, leading to better appearance

    • Minor update for jEdit 3.2 selection API

    • Documentation generated with DocBook

    • Error reporting API documentation included