Search code examples
eclipsextext

Automatic handling of errors/warnings


On a linking error, I can raise appropriate diagnostic (say MyDSL.MY_APPROPRIATE_DIAGNOSTIC) and then write, in MyDSLQuickfixProvider, a quick fix for it by annotating it in this way:

@Fix(MyDSL.MY_APPROPRIATE_DIAGNOSTIC)
public void fixMyAppropriateDiagnostic(final Issue issue, final IssueResolutionAcceptor acceptor) {
  ...
}

What about if I wanted to automatically resolve a diagnostic, i.e. automatically execute an IModification without propose it to the user as quick fix (imagine the quick fix for the diagnostic is unique)?

Is there a way to associate a (immediate) handling code to a diagnostic in a similar manner to what happens for (user-proposed) quick fixes?

Thanks in advance, Marco


Solution

  • There is no way to set a quick fix to be executed automatically. Your alternatives are:

    • Invoke the marker resolution code from somewhere else in your code. I.e. while marker resolutions are typically triggered explicitly on user request using the problems view, ruler buttons and similar UI, you could invoke them from anywhere. Be sure that you don't interfere with quickfixes, which are not from your plugin and make sure your users are not surprised by this non-eclipse workflow.

    • For some issues you may be able to instead create code completion rules or templates. Those are still not fully automatic as requested, but basically you can already "correct" partial user input that way and avoid flagging a violation for the complete input.