Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Providing quick fixes when IMarker are not created using Xtext's API
Providing quick fixes when IMarker are not created using Xtext's API [message #1829410] Thu, 02 July 2020 22:13 Go to next message
Emmanuel Chebbi is currently offline Emmanuel ChebbiFriend
Messages: 123
Registered: February 2018
Senior Member
Hi,

I have a DSL which is validaded through a custom AbstractDeclarativeValidator. The editor shows error markers and I now wish to provide quick fixes.

Currently the markers are not created through the warning and error methods but "manually" through IFile::createMarker (the main reason is basically that the AST is transformed multiple times and we do not have the original EObjects/EStructuralFeature at the end). The issue is that I don't manage to make the editor aware of my quick fixes (i.e. no little bulb on which we could click).

My first try to solve the issue:

  1. Declare a custom marker type through the org.eclipse.core.resources.markers extension point
  2. Declare a custom quick fix provider through the org.eclipse.ui.ide.markerResolution extension point

Result: the Problems view shows that quick fixes are available and allows me to select one however the editor only shows the warning/error icons.

Second try:

  1. Extend DefaultQuickfixProvider to provide the quick fixes
  2. Create the Marker with some attributes I've found after digging into Xtext's source code:
    val marker = file.createMarker(MyMarkers.MY_WARNING) // also tried MarkerTypes.NORMAL_VALIDATION here
    marker.setAttribute(IMarker.MESSAGE, "My warning message")
    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING)
    marker.setAttribute(IMarker.CHAR_START, 0)
    marker.setAttribute(IMarker.CHAR_END, 0)
    marker.setAttribute(Issue.CODE_KEY, MyMarkers.MY_WARNING)
    marker.setAttribute(Issue.COLUMN_KEY, 0)
    marker.setAttribute(Issue.URI_KEY, URI.createPlatformResourceURI(file.fullPath.toString, true).toString)
    marker.setAttribute(IMarker.LINE_NUMBER, 0)
    marker.setAttribute(IMarker.LOCATION, "line: " + 0 + " " + file.fullPath.toString())
    marker.setAttribute("FIXABLE_KEY", true);

Result: the quick fix is shown in the editor and can be triggered but only when the editor has just been created. If I type anything the validator is called again and the bare warning/error icons are shown again: quick fixes are not available anymore. If I close the editor then open it again then the quick fix is shown as expected, until I type something.

I can only guess that some internal state is not set up properly and that my quick fixes are somehow discarded on refresh.

Third try:

  1. An old bug talks about the IResourceUIValidatorExtension interface which looks very promising. This interface is still available in Xtext's source code but I can't make it work. I tried:

    • To create a bindIResourceUIValidatorExtension() method in MyDslUiModule
    • To make my validator extend the interface
    • To add breakpoints everywhere in MarkerUpdaterImpl

  2. I searched for a relevant extension point but found nothing

Result: nothing happens, the methods/classes don't seem to be used anymore.

I'm running out of new ideas so would anyone have any advise to help me solve the issue?

Many thanks,
Emmanuel
Re: Providing quick fixes when IMarker are not created using Xtext's API [message #1829454 is a reply to message #1829410] Fri, 03 July 2020 21:58 Go to previous message
Emmanuel Chebbi is currently offline Emmanuel ChebbiFriend
Messages: 123
Registered: February 2018
Senior Member
After some time spent debugging I kind of "solved" the issue.

When the editor is opened, Xtext calls
iFile.findMarkers(IMarker.MARKER, true, IResource.DEPTH_ZERO)
to discover the markers, which works pretty well. However, I noticed that the marker is updated when I call
marker.setAttribute(IMarker.CHAR_END, 0)
in my validator. At this point the CODE_KEY attribute is not set (it is used to identify the fix) and thus Xtext cannot know there's a quick fix available. Not sure to understand what's going on exactly but putting this line at the end, i.e. after:
marker.setAttribute("FIXABLE_KEY", true);
solved the issue.

Not sure it will work with multiple markers but the issue doesn't look related to Xtext anyway. I may post in the Platform forum if I face further issues.
Previous Topic:Getting user types ID
Next Topic:Error in running workflow
Goto Forum:
  


Current Time: Fri Oct 30 14:44:22 GMT 2020

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

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

Back to the top