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 |
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 <[hidden email]> 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 |
+1
Doru > On Feb 25, 2018, at 9:25 PM, Stephane Ducasse <[hidden email]> 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 <[hidden email]> 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 > -- www.tudorgirba.com www.feenk.com "Every thing has its own flow." |
In reply to this post by Stephane Ducasse-3
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 <[hidden email]> 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 <[hidden email]> 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 |
This is cool! Could this "help" also be included in Pharo's Help Browser? Peter On Sun, Feb 25, 2018 at 9:30 PM, Stephane Ducasse <[hidden email]> wrote: Marcus I thought that the context was about to represent what the |
> On 25 Feb 2018, at 21:44, Peter Uhnák <[hidden email]> wrote: > > This is cool! > > Could this "help" also be included in Pharo's Help Browser? > I added it to the class comment of SugsSuggestion.. for a Help Topic, it might be interesting to add some general “AST and how it is used by tools” section… Marcus |
In reply to this post by Stephane Ducasse-3
> On 25 Feb 2018, at 21:30, Stephane Ducasse <[hidden email]> wrote: > > 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? > The AST as coming from the Parser: no. The AST after name Analysis: yes. Which means you actually need the class to do name analysis (“Semantic Analysis”, implemented by OCASTSemanticAnalyzer). I think it will be easy: -> there is RubSmalltalkCodeMode / RubSmalltalkScriptingMode which models if the editor. is editing Doits or Methods (important for parsing!). -> RubSmalltalkCodeMode does have an ivar classOrMetaclass already. It is not set by most tools yet, though. -> we can easily add there (or in RubSmalltalkEditor) an “ast “ ivar and re-parse at every keystroke. So as soon as we make sure that all users of RubSmalltalkCodeMode correctly set the class, this will be all very simple. Marcus |
Added to: http://wiki.astares.com/pharo/607
> Gesendet: Montag, 26. Februar 2018 um 08:17 Uhr > Von: "Marcus Denker" <[hidden email]> > An: "Pharo Development List" <[hidden email]> > Betreff: Re: [Pharo-dev] Simplified AST "Suggestions" menu definitions > > > > > On 25 Feb 2018, at 21:30, Stephane Ducasse <[hidden email]> wrote: > > > > 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? > > > The AST as coming from the Parser: no. The AST after name Analysis: yes. > Which means you actually need the class to do name analysis (“Semantic Analysis”, > implemented by OCASTSemanticAnalyzer). > > I think it will be easy: > > -> there is RubSmalltalkCodeMode / RubSmalltalkScriptingMode which models if the editor. > is editing Doits or Methods (important for parsing!). > -> RubSmalltalkCodeMode does have an ivar classOrMetaclass already. It is not set by most tools yet, though. > -> we can easily add there (or in RubSmalltalkEditor) an “ast “ ivar and re-parse at every keystroke. > > So as soon as we make sure that all users of RubSmalltalkCodeMode correctly set the class, this will be all > very simple. > > Marcus > |
Free forum by Nabble | Edit this page |