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

Reply via email to