Marcus I thought that the context was about to represent what the
tools selected like the class currently selected.
You have this information in the AST?

Stef

On Sun, Feb 25, 2018 at 9:25 PM, Stephane Ducasse
<[email protected]> wrote:
> 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 <[email protected]> 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

Reply via email to