Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext quick fix provider not run?
Xtext quick fix provider not run? [message #1776780] Tue, 21 November 2017 15:14 Go to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 261
Registered: July 2009
Senior Member
Hi,

I'm building an Xtext language with Xtext 2.12. I want to provide quick fixes in response to an issue identified during validation.

In my validator, I provide an issue code and relevant issue data. In the QuickFixProvider that has been generated in my *.ui project, I have a suitable method with an @Fix(CODE) annotation in which I analyse the issue data and register appropriate resolutions.

Unfortunately, it seems that this method is never invoked. The plugin.xml seems to register org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator against appropriate extension points. I cannot see where this is bound in any of the modules, but it is explicitly mentioned in the extension definition. Looking at the code of that, this should call my fix method (my quickfixprovider is bound as the IssueResolutionProvider in the UI module). I placed a breakpoint in AbstractIssueResolutionProviderAdapter#getResolutions (which, should call out to the actual IssueResolutionProvider---that is my code---to get the quick fixes), but this seems never to be reached.

As a result, when I ask for quick fixes on my issue marker, Eclipse simply tells me that there aren't any.

The documentation (https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#quick-fixes) mentions the need to use QuickfixProviderFragment2 in the MWE2 workflow to generate the QuickFixProvider class. However, this seems outdated as that class is already being generated. It is also not clear to me where I would need to call this fragment in my workflow (I currently use the workflow that Xtext initially generated for me).

What am I missing?

Many thanks,

Steffen
Re: Xtext quick fix provider not run? [message #1776781 is a reply to message #1776780] Tue, 21 November 2017 15:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12322
Registered: July 2009
Senior Member
can you share a complete reproducible example project?
how does your validator look like? does it produce the correct code
did you test with the hello world grammar (uncomment validator and quickfix)


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext quick fix provider not run? [message #1776783 is a reply to message #1776781] Tue, 21 November 2017 15:34 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 261
Registered: July 2009
Senior Member
Hi Christian,

I haven't got a minimal example project at the moment, but can try and build one. The validator is fairly standard, except that it produces the specific issue only in the EXPENSIVE check mode. This isn't done through a specific sub-annotation, but by explicitly checking the check mode (so that I can provide a warning about incomplete validation otherwise). It does produce the correct code and there are tests for that, too. BTW, is there a way in which I can test quick fixes other than running a runtime Eclipse and going through the steps?

I'll go and build a basic test project now.

Many thanks,

Steffen
Re: Xtext quick fix provider not run? [message #1776784 is a reply to message #1776783] Tue, 21 November 2017 15:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12322
Registered: July 2009
Senior Member
you would have a look at the xtext code to find something you can use to test.
did you debug the

org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator.hasResolutions(IMarker)
and
org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator.getResolutions(IMarker)

for the quickfixes?


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext quick fix provider not run? [message #1776789 is a reply to message #1776784] Tue, 21 November 2017 16:02 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 261
Registered: July 2009
Senior Member
Hi Christian,

As I said, I had put a breakpoint into getResolutions, but somehow this didn't get called. I had not put a breakpoint into hasResolutions.

Just tested this with the default DSML. There it seemed to work at first, but I was eventually able to replicate the issue there, too. In doing some more testing, I think I have narrowed the issue down a little more and am beginning to think this is an issue in Xtext. Here's what happens in more detail:

1. I choose to "validate" my model and the error marker is created.
2. In the errors list, this is shown with a lightbulb icon (I assume this means that hasResolutions has returned successfully for it).
3. When I click on the error marker in the Problems view, and select to see quick fixes, Eclipse tells me that there are no quick fixes. When I try and access quick fixes directly through the editor, this doesn't seem to happen. I only saw this for the default DSML so far, for my default there is still the warning marker on the same model element, which overlaps the error marker so that I cannot actually see the error marker in the editor.

So, the problem seems to be with getResolutions doing subtly different things depending on where it is called from. I will try and debug this some more to see what's going on.

BTW, is there a way in which in a validator I can remove an existing marker? In my example, I initially create a warning marker to flag that a more expensive validation is available, but has not been run for every edit. When the user explicitly invokes "validate", I would like to remove that warning and, possibly, replace it with an error marker if needed.

Many thanks,

Steffen
Re: Xtext quick fix provider not run? [message #1776791 is a reply to message #1776789] Tue, 21 November 2017 16:12 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 261
Registered: July 2009
Senior Member
It seems that in the above case on line 96 MarkerResolutionGenerator decides that the marker is no longer valid. I suspect that this may be something to do with how it obtains an editor and how I generate the annotation, but need to do more debugging to really understand what's going on. I won't be able to get round to this today any more, but will report back as soon as I have found out more.

Many thanks,

Steffen
Re: Xtext quick fix provider not run? [message #1776792 is a reply to message #1776791] Tue, 21 November 2017 16:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12322
Registered: July 2009
Senior Member
can you make the example check expensive as well?

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext quick fix provider not run? [message #1776810 is a reply to message #1776792] Tue, 21 November 2017 20:31 Go to previous message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 261
Registered: July 2009
Senior Member
OK, I figured out what was causing the problem. This was to do with how I had defined the expensive validation. I originally had code like the one below (shown here for the default example language):

@Check
def checkGreetinOgStartsWithCapital(Greeting greeting) {
    if (!Character.isUpperCase(greeting.name.charAt(0))) {
        if (checkMode.shouldCheck(CheckType.EXPENSIVE)) {
            warning('Name should start with a capital', MyDslPackage.Literals.GREETING__NAME, INVALID_NAME)
        }
    }
}


While this worked well for my validator (and allowed me to write some fairly compact code all in one place), it confused MarkerResolutionGenerator. I have now rewritten my code with an explict EXPENSIVE marker as below and it works.

@Check(EXPENSIVE)
def checkGreetinOgStartsWithCapital(Greeting greeting) {
    if (!Character.isUpperCase(greeting.name.charAt(0))) {
        warning('Name should start with a capital', MyDslPackage.Literals.GREETING__NAME, INVALID_NAME)
    }
}
Previous Topic:Content Assist in Web Editor
Next Topic:Error: Cyclic resolution of lazy links
Goto Forum:
  


Current Time: Thu Oct 18 15:55:02 GMT 2018

Powered by FUDForum. Page generated in 0.03272 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top