Bug 321684 - [quickfixes] Add support for quickfixes without validation errors
Summary: [quickfixes] Add support for quickfixes without validation errors
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 1.0.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-04 05:01 EDT by Sebastian Benz CLA
Modified: 2018-03-24 16:06 EDT (History)
10 users (show)

See Also:


Attachments
Implementation of a SuggestionProvider (42.45 KB, patch)
2010-08-04 05:01 EDT, Sebastian Benz CLA
no flags Details | Diff
Updated patch to version 2.2 (36.11 KB, patch)
2011-11-09 16:55 EST, Michael Clay CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Benz CLA 2010-08-04 05:01:29 EDT
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.
Comment 1 Sebastian Zarnekow CLA 2010-09-21 07:39:57 EDT
See also bug 324942
Comment 2 Sebastian Zarnekow CLA 2010-09-21 07:40:17 EDT
Postponed to M3
Comment 3 Michael Clay CLA 2011-11-09 16:55:02 EST
Created attachment 206740 [details]
Updated patch to version 2.2
Comment 4 Knut Wannheden CLA 2011-11-11 08:42:45 EST
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.
Comment 5 Sebastian Zarnekow CLA 2011-11-11 08:54:20 EST
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.
Comment 6 Knut Wannheden CLA 2011-11-11 08:58:11 EST
Makes sense.
Comment 7 Tamas Miklossy CLA 2018-03-24 16:06:36 EDT
See also https://github.com/eclipse/xtext-eclipse/issues/610