Community
Participate
Working Groups
Created attachment 175821 [details] Implementation of a SuggestionProvider Currently quickfixes can only be applied to validation errors. However, often quickfixes are useful for extending the current model (similar to "assign to local variable" in JDT). I attached a patch that I created in discussion with Sebastian (Zarnekow). The patch contains a SuggestionProvider which allows the user to register custom quickfixes/suggestions. There are two types of suggestions currently supported: 1. a text-based quickfix (Suggestion) 2. a model-based quickfix (SemanticSuggestion) The patch contains: - implementation of the SuggestionProvider - integration into XtextQuickAssistProcessor - extended QuickfixProviderFragment - example test case Note: the test languages must be regenerated.
See also bug 324942
Postponed to M3
Created attachment 206740 [details] Updated patch to version 2.2
First off I think this would be a great piece of functionality to add to Xtext. Here some minor comments and suggestions regarding the patch: - SuggestionResolutionAcceptor.Factory.Default#createAcceptor() seems to have inherited some local variable names from SuggestionModificationContext.Factory.Default#createModificationContext(). - DefaultSuggestionProvider#eObjectAtOffsetHelper should be Guice injected - A guard against null being returned from XtextDocumentUtil#get() in DefaultSuggestionProvider#getSelectedElement() would probably not hurt - I think the name SuggestionResolutionAcceptor is a bit strange as I thought the suggestion is the resolution (to a non existant issue :-)). What about just SuggestionAcceptor? - Should the new methods XtextQuickAssistProcessor#computeIssueFixes() and #computeSuggestions() be protected instead of private? - DomainModelSuggestionProvider should be called DomainmodelSuggestionProvider (with a lowercase m) Further the supplied Domainmodel example doesn't seem to work very well. The quick assist is for instance not available when the cursor is in the region of the type to be imported, as the context object isn't the expected Property object. Also when applying the quick assist properly I get NPEs in the log (see below) and the replaced type reference ends up as "void". I assume the Domainmodel example should expect JvmTypeReference objects instead. But this would probably require overriding DefaultSuggestionProvider#getSelectedElement() to use EObjectAtOffsetHelper#getCrossReferenceNode() or something.
Thanks for the feedback, Knut. We discussed the quick assist feature, too. We came to the conclusion that we want a more homogeneous implementation for QuickFixes and QuickAssists (no new term 'suggestion'). Furthermore we need additional information, that is clearly available on the JFace level but hidden due to the introduced layers of abstraction, e.g. the current selection, the source viewer and the possibility to create rich completion proposals instead of simple modifications. To put a long story short: the patch is a nice starting point. But the feature still needs polishing and cleanup.
Makes sense.
See also https://github.com/eclipse/xtext-eclipse/issues/610