This is cool! This is also why I started to do a pass (first reverse engineering how ecompletion is working) We should regularly improve the infrastructure of our tools to enable the next generation. I love that! marcus because indeed this code needs love. On Sun, Feb 25, 2018 at 7:23 PM, Marcus Denker <marcus.denker@inria.fr> wrote:
Hi,
I started to simplidy the âSmartSuggestionsâ code. What does it do? It adds the âsuggestionsâ menu to the editor context menu, this shows operations that make sense for the AST node a the cursor position.
-> removed lots of state from SugsSuggestion (label, position, â¦). Instead uses methods. -> simplified how to define new suggestions.
Here is a small example: a menu to browse the defintion of variables. First we need to make a suclass of SugsSuggestion.
1) add a subclass of SugsSuggestion
SugsSuggestion subclass: #SugsBrowseVariableDefintion instanceVariableNames: '' classVariableNames: '' package: 'SmartSuggestions-Suggestion'
2) define on the class side a method that defines for which AST nodes you want the menu to be shown. Here is is all Variable Nodes:
nodes ^{RBVariableNode}
3) On the instance side, we just need to define a label
label ^ 'Browse Variable definition' translated
4) and we need to define #execute which just implements what is supposed to happen:
execute | semanticVariable | semanticVariable := context selectedNode binding. semanticVariable isInstance ifTrue: [ ^semanticVariable slot definingClass browse ]. semanticVariable isTemp ifTrue: [ ^semanticVariable scope node method browse ]. semanticVariable isClassVariable ifTrue: [ ^semanticVariable scope getClass browse ]. semanticVariable isGlobal ifTrue: [ Smalltalk globals inspect ].
DONE. The simplified SmartSuggestions are in the latest Pharo7, so you can play with the code there, the SugsBrowseVariableDefintion is not (yet?) in Pharo7. (maybe someone wants to submit it?)
Next steps: - get rid of the âContextâ and instead embed the AST in the editor. This will be nice for *many* other clients (AST Node navigation, code completion, syntax highlightingâ¦)
- liberate the AST menu entries from the âsuggestionsâ submenu: they should just appear in the standard editor context menu.
Marcus