/plugins/ErrorList/tags/release-1-2-2/users-guide.xml

# · XML · 473 lines · 372 code · 97 blank · 4 comment · 0 complexity · dca87e30a220d7f9e3f5f62606459596 MD5 · raw file

  1. <?xml version="1.0"?>
  2. <!-- ErrorList user's guide -->
  3. <!-- (C) 2001 Slava Pestov -->
  4. <!-- jEdit buffer-local properties: -->
  5. <!-- :tabSize=1:indentSize=1:noTabs=true: -->
  6. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
  7. "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
  8. <book>
  9. <bookinfo><title>ErrorList plugin user's guide</title>
  10. <author><firstname>Slava</firstname><surname>Pestov</surname></author>
  11. <legalnotice><title>Legal Notice</title>
  12. <para>
  13. Permission is granted to copy, distribute and/or modify this document
  14. under the terms of the GNU Free Documentation License, Version 1.1 or
  15. any later version published by the Free Software Foundation; with no
  16. <quote>Invariant Sections</quote>, <quote>Front-Cover Texts</quote> or
  17. <quote>Back-Cover Texts</quote>, each as defined in the license. A copy of
  18. the license can be found in the file <filename>COPYING.DOC.txt</filename>
  19. included with jEdit.
  20. </para>
  21. </legalnotice>
  22. </bookinfo>
  23. <chapter id="intro"><title>Introduction</title>
  24. <para>
  25. The ErrorList plugin displays errors and warnings
  26. generated by other plugins. It does
  27. nothing on its own; for it to be useful, some plugins that support the
  28. error reporting API must be installed.
  29. </para>
  30. <para>
  31. The error reporting API is particularly well-suited to reporting compiler errors
  32. and such; plugins that use this API include Console, JCompiler, HTML and XML.
  33. If you would like to use it from your plugin, see <xref linkend="api" />.
  34. </para>
  35. </chapter>
  36. <chapter id="window"><title>The error list window</title>
  37. <para>
  38. <guimenu>Plugins</guimenu>&gt;<guisubmenu>Error
  39. List</guisubmenu>&gt;<guimenuitem>Error List</guimenuitem> displays the error
  40. list window. This window is floating by default, but it can be made to
  41. dock into the view in the <guibutton>Docking</guibutton> pane of the
  42. <guimenuitem>Global Options</guimenuitem> dialog box.
  43. </para>
  44. <para>
  45. Errors are shown in a tree control, with each branch being a file, and each
  46. leaf an error. Clicking on a file will open that file; clicking on an error
  47. will open the file containing the error and move the caret to its location.
  48. </para>
  49. <para>
  50. The error reporting API supports two types of errors; genuine errors and
  51. warnings. The two are differentiated with different-colored icons in the
  52. tree; errors have a red icon, warnings have a yellow one.
  53. </para>
  54. <para>
  55. For information on keyboard-based navigation of the tree, see
  56. <xref linkend="actions" />.
  57. </para>
  58. </chapter>
  59. <chapter id="highlight"><title>Error highlighting</title>
  60. <para>
  61. The ErrorList plugin also highlights errors in-place in the text area with
  62. a colored underline. The color depends on the error type; genuine errors
  63. have a red underline, warnings have a yellow one.
  64. </para>
  65. <para>
  66. Hovering the mouse over a line with an error highlight will show a tooltip
  67. with the error message.
  68. </para>
  69. <para>
  70. Error highlighting can be disabled in the <guibutton>Error List</guibutton> pane
  71. of the <guimenuitem>Global Options</guimenuitem> dialog box. The colors of
  72. the underlines can also be changed in that same option pane.
  73. </para>
  74. </chapter>
  75. <chapter id="actions"><title>Additional commands</title>
  76. <para>
  77. The ErrorList plugin provides a few additional commands that can be bound to
  78. keyboard shortcuts in the <guibutton>Shortcuts</guibutton> pane of the
  79. <guimenuitem>Global Options</guimenuitem> dialog box.
  80. </para>
  81. <para>
  82. <guimenu>Plugins</guimenu>&gt;<guisubmenu>Error
  83. List</guisubmenu>&gt;<guimenuitem>Go to Previous Error</guimenuitem> moves the
  84. caret to the error immediately before the one currently selected in the
  85. error list window. If no error is selected, the last error in the list is
  86. chosen. This will open the appropriate file if the error is in a
  87. different file.
  88. </para>
  89. <para>
  90. <guimenu>Plugins</guimenu>&gt;<guisubmenu>Error
  91. List</guisubmenu>&gt;<guimenuitem>Go to Next Error</guimenuitem> moves the
  92. caret to the error immediately after the one currently selected in the
  93. error list window. If no error is selected, the first error in the list is
  94. chosen. This will open the appropriate file if the error is in a
  95. different file.
  96. </para>
  97. <para>
  98. <guimenu>Plugins</guimenu>&gt;<guisubmenu>Error
  99. List</guisubmenu>&gt;<guimenuitem>Go to Previous File With Errors</guimenuitem>
  100. opens the file immediately before the one currently selected in the error
  101. list window. If no file is selected, the last file with errors is chosen.
  102. </para>
  103. <para>
  104. <guimenu>Plugins</guimenu>&gt;<guisubmenu>Error
  105. List</guisubmenu>&gt;<guimenuitem>Go to Next File With Errors</guimenuitem>
  106. opens the file immediately after the one currently selected in the error
  107. list window. If no file is selected, the first file with errors is chosen.
  108. </para>
  109. </chapter>
  110. <chapter id="api"><title>The error reporting API</title>
  111. <para>
  112. The error reporting API is very simple. A plugin that wishes to use it must
  113. do these three things:
  114. </para>
  115. <itemizedlist>
  116. <listitem><para>Specify that it requires the ErrorList and EditBus plugins.
  117. The error reporting API is spread between these two plugins for historical
  118. reasons.</para></listitem>
  119. <listitem><para>Register an <quote>error source</quote> at some stage,
  120. usually during startup.</para></listitem>
  121. <listitem><para>Add errors to the error source when they occur.</para></listitem>
  122. </itemizedlist>
  123. <para>
  124. The classes of the error reporting API, and the ErrorList plugin itself handle
  125. the rest automatically; displaying errors in a list, error highlighting, and
  126. so on.
  127. </para>
  128. <sect1 id="api-deps"><title>Specifying dependencies</title>
  129. <para>
  130. In order to give the user a helpful error message if the ErrorList
  131. plugin is not installed, your plugin should specify dependency properties.
  132. If your plugin's core class is named <classname>MyPlugin</classname>, the
  133. corresponding dependencies might look like so:
  134. </para>
  135. <programlisting>plugin.MyPlugin.depend.0=jedit 04.00.01.00
  136. plugin.MyPlugin.depend.2=plugin ErrorListPlugin 1.2</programlisting>
  137. <para>
  138. Note that the current version of the ErrorList plugin requires jEdit 4.0pre1
  139. or later, so your plugin should also require at least that jEdit version.
  140. If a newer version of the ErrorList plugin is available, you can
  141. specify higher version numbers than in the example above. However, all the
  142. API calls in this chapter are guaranteed to work with the above version,
  143. so in most cases you shouldn't worry about it.
  144. </para>
  145. </sect1>
  146. <sect1 id="api-register"><title>Creating and registering an error source</title>
  147. <para>
  148. Errors are managed by implementations of the
  149. <classname>errorlist.ErrorSource</classname> abstract class.
  150. Extending this class is a bit involved and requires writing a lot of
  151. low-level code; most
  152. plugins can use the <classname>errorlist.DefaultErrorSource</classname>
  153. class instead, which provides a very easy-to-use front-end.
  154. </para>
  155. <para>
  156. The constructor for the <classname>DefaultErrorSource</classname> class
  157. accepts one parameter; a string that will identify the error source.
  158. Currently, this identifier is not used, but in the future the ErrorList plugin
  159. might show which error comes from which plugin, for example.
  160. </para>
  161. <para>
  162. Typically, error sources will be registered in your plugin's
  163. <function>start()</function> method, but that does not have to be the case.
  164. The Console plugin, for example, maintains a separate error source for each
  165. console window, and registers an unregisters them as consoles are opened
  166. and closed.
  167. </para>
  168. <para>
  169. To add an error source to the list of registered error sources, you must call
  170. the static <function>registerErrorSource()</function> method of the
  171. <classname>errorlist.ErrorSource</classname> class.
  172. </para>
  173. <para>
  174. A corresponding <function>unregisterErrorSource()()</function> method also
  175. exists, for advanced uses of the API, like the Console plugin mentioned
  176. above.
  177. </para>
  178. <para>
  179. Putting all this together, a simple plugin core class
  180. <function>start()</function> method
  181. might look as follows:
  182. </para>
  183. <programlisting>public void start()
  184. {
  185. errorSource = new DefaultErrorSource("MyPlugin");
  186. ErrorSource.registerErrorSource(errorSource);
  187. // any other initialization your plugin
  188. // needs to perform
  189. }</programlisting>
  190. <para>
  191. Note that the newly-created error source is assigned to an instance variable.
  192. This allows the error source instance to be called upon later, when
  193. compiler errors are actually generated.
  194. </para>
  195. </sect1>
  196. <sect1 id="api-report"><title>Reporting errors</title>
  197. <para>
  198. A custom <classname>ErrorSource</classname> implementation would need to
  199. send the appropriate EditBus message when an error arrives, and then
  200. provide implementations of various <quote>getter</quote> methods that
  201. the ErrorList plugin would later call to obtain the error.
  202. Using <classname>DefaultErrorSource</classname> makes the task much easier.
  203. In fact, all that is involved is calling a single method on the appropriate
  204. <classname>DefaultErrorSource</classname> instance:
  205. </para>
  206. <funcsynopsis>
  207. <funcprototype>
  208. <funcdef>public void <function>addError</function></funcdef>
  209. <paramdef>DefaultErrorSource.DefaultError <parameter>error</parameter></paramdef>
  210. </funcprototype>
  211. </funcsynopsis>
  212. <para>
  213. The constructor of the <classname>DefaultErrorSource.DefaultError</classname>
  214. class is as follows:
  215. </para>
  216. <funcsynopsis>
  217. <funcprototype>
  218. <funcdef>public <function>DefaultError</function></funcdef>
  219. <paramdef>int <parameter>type</parameter></paramdef>
  220. <paramdef>String <parameter>path</parameter></paramdef>
  221. <paramdef>int <parameter>line</parameter></paramdef>
  222. <paramdef>int <parameter>start</parameter></paramdef>
  223. <paramdef>int <parameter>end</parameter></paramdef>
  224. <paramdef>String <parameter>message</parameter></paramdef>
  225. </funcprototype>
  226. </funcsynopsis>
  227. <itemizedlist>
  228. <listitem><para><varname>type</varname> - this should be either
  229. <classname>ErrorSource.ERROR</classname> or
  230. <classname>ErrorSource.WARNING</classname>.</para></listitem>
  231. <listitem><para><varname>path</varname> - the path name or URL of
  232. the file containing the error. If this is a relative path, it will
  233. be qualified relative to the current working directory
  234. (<literal>user.dir</literal> system property). However, it is best to qualify
  235. it beforehand, using the <function>MiscUtilities.constructPath()</function>
  236. method.</para></listitem>
  237. <listitem><para><varname>line</varname> - the line number in the file
  238. where the error occurred. Lines are numbered starting from zero; since most
  239. tools and compilers report line numbers starting from 1, you might need to
  240. subtract 1 from the number before passing it to this method.</para></listitem>
  241. <listitem><para><varname>start</varname> - an offset in the line where
  242. the error begins.</para></listitem>
  243. <listitem><para><varname>end</varname> - an offset in the line where
  244. the error ends. These two values are only used to give a more exact
  245. display for error highlighting, and if both are zero, the entire line will be
  246. highlighted.</para></listitem>
  247. <listitem><para><varname>message</varname> - the error message itself,
  248. as shown in the error list window and error highlighting tooltips.
  249. </para></listitem>
  250. </itemizedlist>
  251. <para>
  252. This method is fully thread safe; if your plugin generates errors from
  253. another thread, it can call this method without having to use any of the
  254. usual <function>SwingUtilities.invokeLater()</function> tricks required
  255. when calling non-thread safe methods.
  256. </para>
  257. <para>
  258. Here are two examples of <function>addError()</function> calls. The first
  259. adds a warning, covering the entire line, the second adds an error that
  260. only applies to a subset of the specified line:
  261. </para>
  262. <programlisting>errorSource.addError(new ErrorSource.DefaultError(
  263. ErrorSource.WARNING,path,line,0,0,
  264. "Are you sure this is what you intended?"));
  265. errorSource.addError(new ErrorSource.DefaultError(
  266. ErrorSource.WARNING,
  267. MiscUtilities.constructPath(directory,"input.src"),
  268. line,0,5,"First five characters of line are bad"));</programlisting>
  269. <para>
  270. Multiple-line messages can be created by calling the following method
  271. on the <classname>DefaultError</classname> instance before it is added
  272. to the error source (the last part is important, otherwise the extra
  273. messages will not be shown):
  274. </para>
  275. <funcsynopsis>
  276. <funcprototype>
  277. <funcdef>public void <function>addExtraMessage</function></funcdef>
  278. <paramdef>String <parameter>extra</parameter></paramdef>
  279. </funcprototype>
  280. </funcsynopsis>
  281. <para>
  282. That's basically all there is to it. There is one more method in the
  283. <classname>DefaultErrorSource</classname> class that needs to be mentioned:
  284. </para>
  285. <funcsynopsis>
  286. <funcprototype>
  287. <funcdef>public void <function>clear</function></funcdef>
  288. <void />
  289. </funcprototype>
  290. </funcsynopsis>
  291. <para>
  292. This method removes all errors from the error source. It is typically
  293. called before each invocation of the operation that generates errors;
  294. for example, the Console plugin clears its error source before each new
  295. command is run.
  296. </para>
  297. <para>
  298. This method reveals a limitation of the
  299. <classname>DefaultErrorSource</classname>
  300. class; errors cannot be removed selectively. The main reason this hasn't
  301. been implemented is lack of demand. If your plugin needs a means of only
  302. removing a subset of errors in an error source, feel free to modify the
  303. source for this class and contribute the changes back to the jEdit project.
  304. </para>
  305. </sect1>
  306. </chapter>
  307. <appendix id="changes"><title>Change log</title>
  308. <itemizedlist>
  309. <listitem><formalpara><title>Version 1.2.2</title><para>requires
  310. jEdit 4.0pre4.
  311. </para></formalpara>
  312. <itemizedlist>
  313. <listitem><para>Fixed possible <classname>NullPointerException</classname>
  314. under Java 2 version 1.4.
  315. </para></listitem>
  316. <listitem><para>Error highlight didn't work properly when soft wrap was
  317. enabled.
  318. </para></listitem>
  319. <listitem><para>If the <quote>show on error</quote> feature is enabled, the
  320. error list will now open in the currently focused view, not the most
  321. recently opened view as before.
  322. </para></listitem>
  323. </itemizedlist>
  324. </listitem>
  325. <listitem><formalpara><title>Version 1.2.1</title><para>requires
  326. jEdit 4.0pre4.
  327. </para></formalpara>
  328. <itemizedlist>
  329. <listitem><para>Updated to use jEdit 4.0pre4 text area extension API.
  330. </para></listitem>
  331. </itemizedlist>
  332. </listitem>
  333. <listitem><formalpara><title>Version 1.2</title><para>requires jEdit 4.0pre1.
  334. </para></formalpara>
  335. <itemizedlist>
  336. <listitem><para>Updated for jEdit 4.0 API changes.</para></listitem>
  337. <listitem><para>EditBus plugin merged with this one.</para></listitem>
  338. <listitem><para>Changes to error source API; see <xref linkend="api" />
  339. for details.</para></listitem>
  340. </itemizedlist>
  341. </listitem>
  342. <listitem><formalpara><title>Version 1.1.2</title><para>requires jEdit 3.2pre8
  343. and the EditBus plugin 1.1.</para></formalpara>
  344. <itemizedlist>
  345. <listitem><para>If the error list was open but not visible, the
  346. <guilabel>Show on error</guilabel> option would do nothing.</para></listitem>
  347. <listitem><para>If no error sources were registered, all highlights added
  348. after the error list would not be painted.</para></listitem>
  349. </itemizedlist>
  350. </listitem>
  351. <listitem><formalpara><title>Version 1.1.1</title><para>requires jEdit 3.2pre8
  352. and the EditBus plugin 1.1.</para></formalpara>
  353. <itemizedlist>
  354. <listitem><para>Line numbers in the tree are now increased by one, so that
  355. they match the textarea line numbers (Dirk Moebius)</para></listitem>
  356. <listitem><para>The commands "Next/Previous Error" and "Next/Previous File
  357. With Errors" now ensure that the newly selected error is visible
  358. (Dirk Moebius)</para></listitem>
  359. <listitem><para>Supports multiple-line error messages, introduced
  360. by EditBus 1.1</para></listitem>
  361. </itemizedlist>
  362. </listitem>
  363. <listitem><formalpara><title>Version 1.1</title><para>requires jEdit 3.2pre8
  364. and the EditBus plugin 1.0.1.</para></formalpara>
  365. <itemizedlist>
  366. <listitem><para>Errors are now shown in a tree, not a list</para></listitem>
  367. <listitem><para>Error highlighting does not highlight leading whitespace
  368. of lines, leading to better appearance</para></listitem>
  369. <listitem><para>Minor update for jEdit 3.2 selection API</para></listitem>
  370. <listitem><para>Documentation generated with DocBook</para></listitem>
  371. <listitem><para>Error reporting API documentation included</para></listitem>
  372. </itemizedlist>
  373. </listitem>
  374. </itemizedlist>
  375. </appendix>
  376. </book>