Building a fully functional code editor based on the JFace Text framework: Part 7th

Source: Internet
Author: User

Quick Assistant

The basic purpose of quick Assistant (fast help) is to provide some quick solutions to errors in the source code. Fast means that the solution is simple enough or a pattern enough to be done automatically by the program. Of course, fast help is not a solution to the deep-seated problems, but generally we write code, the most committed is a number of small errors, so quick help is a very useful function.

In the Java editor, quick help looks like the following image:

Figure 1. Quick Help in the Java editor

As you can see, both the name and the interface, quick Help is very similar to the Content Assistant feature I mentioned. In fact, they are similar in architecture and implementation.

The quick Help is based on Annotation (callout), and we've covered in part V of this series How to create a callout and show it. A callout contains a type of information, such as an error or warning or just a hint. The basic idea of quick help is to determine if the cursor is in the right place, check the annotation type, and trigger quick help if you are interested in a type, such as an error.

Because of its similarity to the content hints, let's just take a look at how we can help quickly.

Implement Quick Help

In the present example, I have already shown the grammatical errors. Because quick help can be triggered for annotation types, I intend to add an error type: undelcared Variable (undeclared variable), as in the following example:

Listing 1. Incorrect syntax, variable b not declared

a = 3;
a = b;

A is assigned two times, the first time with a constant, and the second is to assign the value of variable b to variable a. If the syntax of this code is not problematic according to the current parser grammar, the semantics are problematic because B is not declared.

For this new type of error, I would argue that the user may have typed the variable name incorrectly, so that the list of declared variable names is displayed, and if the user chooses one, the undeclared variable is replaced with the declared variable. For the original mistake, I do not provide quick help, so that everyone can see the difference.

Implementing support at the bottom

To increase the type of error, you need to modify the parser grammar, I have finished this section, all undeclared variables are saved to a list. Again, the sharedparser is enhanced to get these undeclared variables.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.