Extend QuickFix behaviour [message #777509] |
Tue, 10 January 2012 16:07 |
Darie Moldovan Messages: 67 Registered: November 2010 Location: Darmstadt, Germany |
Member |
|
|
Hi, by default, QuickFix is enabled in Xtext editors and it's working fine. Now, I want to extend that behaviour and add my own "fixes", as can be seen in the following example:
object obj1 (
...
)
object obj2 extends obj15 (
^^^^^
)
The underlined name in the above example points to an object that is not declared. This would automatically trigger the QuickFix mechanism of Xtext, which is right. It would then suggest something like "Change to obj1", which is nice.
But: I want to customize that behaviour and give the user the possibility to choose between several options, like:
- Change to ... (always shown, by default)
- Create object obj15 (my suggestion, how to add it here?)
- ...
I tried doing that following some tutorials I found on the web about implementing quickfix. The problem is that I cannot do the following two things:
- I don't know how to access what the user wrote (in this case: obj15), so that I can then add a suggestion in the quickfix list like "Create object obj15"
- I don't know how to add my own suggestions in the default list of the quickfix, as seen above
Quickfix works for me, I wrote the necessary classes in the validator and in the QuickFix class and they are called properly. the things that do not work are mentioned above.
Any help is kindly appreciated.
|
|
|
Re: Extend QuickFix behaviour [message #777534 is a reply to message #777509] |
Tue, 10 January 2012 16:36 |
|
Hi Darie,
You may want to have a look at the Domainmodel example (File / New / Example / Xtext Examples), there is an implementation example for quickfixes.
Quote:I don't know how to access what the user wrote (in this case: obj15)
You have to add everything that you need as context information in the user data when creating the validation issue in the validation class, e.g. the object name, and an issue code.
if (!Character.isUpperCase(entity.getName().charAt(0))) {
warning("Name should start with a capital",
DomainmodelPackage.Literals.ENTITY__NAME,
ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
IssueCodes.INVALID_TYPE_NAME,
entity.getName()); <-- the user data for quickfix!
}
Quote:I don't know how to add my own suggestions in the default list of the quickfix, as seen above
Just add @Fix methods for the same issue code to the quickfix provider.
Kind regards,
~Karsten
Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
|
|
|
|
|
Re: Extend QuickFix behaviour [message #778325 is a reply to message #778323] |
Thu, 12 January 2012 11:55 |
Darie Moldovan Messages: 67 Registered: November 2010 Location: Darmstadt, Germany |
Member |
|
|
I do agree with that, but first I must set some issue data in the MyDSLJavaValidator when I call
@Check
public void checkObject(Object object) {
error("Some message", null, INEXISTING_OBJECT, "");
^^^
I should here first determine what the user wrote (here: "obj15") and set this string as the issue data, to be able to get it's value in the quick fix method.
Otherwise the issueData won't contain anything (as it does right now in my case...).
But: I do not have access to what the user wrote. Do I have to search the document "by hand" for the incorrect text ("obj15")? If yes, do you have any suggestions for optimizing this search?
Thanks for your help.
Later edit: I took a look at the domain model example, I tried some of that code, it didn't help much. What concerns me is how you determine that entity.getName() in the MyDSLValidator (where you get it from), which Karsten mentioned in his first post.
[Updated on: Thu, 12 January 2012 11:58] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03608 seconds