DoWhatIMeanSupport.st
changeset 4368 442517f0d19d
parent 4367 dd00d1570f88
child 4369 810a78e62f88
equal deleted inserted replaced
4367:dd00d1570f88 4368:442517f0d19d
  1529     ^ nil
  1529     ^ nil
  1530 
  1530 
  1531     "Created: / 28-08-2013 / 16:34:53 / cg"
  1531     "Created: / 28-08-2013 / 16:34:53 / cg"
  1532 !
  1532 !
  1533 
  1533 
  1534 codeCompletionForLiteralSymbol:node into:actionBlock
  1534 codeCompletionForLiteralSymbol:node considerAll:considerAll into:actionBlock
  1535     "looking for all symbols is way too much and inprecise;
  1535     "looking for all symbols is way too much and inprecise;
  1536      experiment: only present symbols which are used by the class,
  1536      experiment: only present symbols which are used by the class,
  1537      and classes in that class category. We'll see..."
  1537      and classes in that class category. We'll see..."
  1538 
  1538 
  1539     |sym possibleCompletions longest editAction start stop addSymbol|
  1539     |sym possibleCompletions longest editAction start stop addSymbol|
  1556                     possibleCompletions add:aSymbol
  1556                     possibleCompletions add:aSymbol
  1557                 ].
  1557                 ].
  1558             ].
  1558             ].
  1559         ].
  1559         ].
  1560 
  1560 
  1561     classOrNil notNil ifTrue:[
  1561     (considerAll or:[classOrNil isNil]) ifTrue:[
       
  1562         Symbol allInstancesDo:addSymbol.
       
  1563     ] ifFalse:[
  1562         Smalltalk allClassesInCategory:classOrNil do:[:cls |
  1564         Smalltalk allClassesInCategory:classOrNil do:[:cls |
  1563             cls theNonMetaclass instAndClassMethodsDo:[:mthd |
  1565             cls theNonMetaclass instAndClassMethodsDo:[:mthd |
  1564                 mthd usedSymbols do:addSymbol
  1566                 mthd usedSymbols do:addSymbol
  1565             ]
  1567             ]
  1566         ].
  1568         ].
  1567     ] ifFalse:[
       
  1568         Symbol allInstancesDo:addSymbol.
       
  1569     ].
  1569     ].
  1570 
  1570 
  1571     possibleCompletions sort.
  1571     possibleCompletions sort.
  1572 
  1572 
  1573     longest := possibleCompletions longestCommonPrefix.
  1573     longest := possibleCompletions longestCommonPrefix.
  2946      Either one may geive better results (for example, when completing
  2946      Either one may geive better results (for example, when completing
  2947      after a keyword selector, and the remaining code would lead to a syntactically
  2947      after a keyword selector, and the remaining code would lead to a syntactically
  2948      legal, but stupid message send to be parsed...
  2948      legal, but stupid message send to be parsed...
  2949      (which happens often after inserting)"
  2949      (which happens often after inserting)"
  2950 
  2950 
  2951     |node checkedNode characterBeforeCursor nodeIsInTemporaries|
  2951     |node checkedNode characterPositionOfCursor characterBeforeCursor nodeIsInTemporaries|
       
  2952 
       
  2953     characterPositionOfCursor := codeView characterPositionOfCursor.
  2952 
  2954 
  2953     "/ this is too naive and stupid; if there is a syntactic error,
  2955     "/ this is too naive and stupid; if there is a syntactic error,
  2954     "/ we will not find a node for a long time (stepping back more and more,
  2956     "/ we will not find a node for a long time (stepping back more and more,
  2955     "/ until reaching the beginning). This leads to a thousand and more times reparsing
  2957     "/ until reaching the beginning). This leads to a thousand and more times reparsing
  2956     "/ without any progress.
  2958     "/ without any progress.
  2970     ].
  2972     ].
  2971 
  2973 
  2972     (node isVariable
  2974     (node isVariable
  2973     and:[ node parent notNil
  2975     and:[ node parent notNil
  2974     and:[ node parent isMessage
  2976     and:[ node parent isMessage
  2975     and:[ node stop < (codeView characterPositionOfCursor-1) ]]]) ifTrue:[
  2977     and:[ node stop < (characterPositionOfCursor-1) ]]]) ifTrue:[
  2976         node := node parent.
  2978         node := node parent.
  2977     ].
  2979     ].
  2978 
  2980 
  2979     characterBeforeCursor := codeView characterBeforeCursor.
  2981     characterBeforeCursor := codeView characterBeforeCursor.
  2980     characterBeforeCursor isNil ifTrue:[ "at begin of line" ^ self].
  2982     characterBeforeCursor isNil ifTrue:[ "at begin of line" ^ self].
  2986             and:[ node parent isSequence 
  2988             and:[ node parent isSequence 
  2987             and:[ node parent temporaries notEmptyOrNil
  2989             and:[ node parent temporaries notEmptyOrNil
  2988             and:[ node stop <= node parent temporaries last stop ]]].
  2990             and:[ node stop <= node parent temporaries last stop ]]].
  2989         nodeIsInTemporaries ifFalse:[
  2991         nodeIsInTemporaries ifFalse:[
  2990             "/ cursor must be right after the variable
  2992             "/ cursor must be right after the variable
  2991             codeView characterPositionOfCursor == (node stop + 1) ifTrue:[
  2993             characterPositionOfCursor == (node stop + 1) ifTrue:[
  2992                 self codeCompletionForVariable:node into:actionBlock.
  2994                 self codeCompletionForVariable:node into:actionBlock.
  2993             ]
  2995             ]
  2994         ].
  2996         ].
  2995         ^ self.
  2997         ^ self.
  2996     ].
  2998     ].
  2997 
  2999 
  2998     node isLiteral ifTrue:[
  3000     node isLiteral ifTrue:[
  2999         "/ cursor must be right after the literal
  3001         "/ cursor must be right after the literal
  3000         codeView characterPositionOfCursor == (node stop + 1) ifTrue:[
  3002         characterPositionOfCursor == (node stop + 1) ifTrue:[
  3001             node value isSymbol ifTrue:[
  3003             node value isSymbol ifTrue:[
  3002                 self codeCompletionForLiteralSymbol:node into:actionBlock.
  3004                 self codeCompletionForLiteralSymbol:node considerAll:false into:actionBlock.
  3003                 ^ self.
  3005                 ^ self.
  3004             ].
  3006             ].
  3005         ].
  3007         ].
       
  3008         "/ however, user may want to complete a symbol inside a literal array!!
       
  3009         node value isArray ifTrue:[
       
  3010             node token isLiteralArray ifTrue:[
       
  3011                 |elementBeforeCursor|
       
  3012 
       
  3013                 elementBeforeCursor := node token value detect:[:anElementToken | characterPositionOfCursor == (anElementToken stop + 1)] ifNone:nil.
       
  3014                 (elementBeforeCursor notNil and:[ elementBeforeCursor value isSymbol ]) ifTrue:[
       
  3015                     self codeCompletionForLiteralSymbol:elementBeforeCursor considerAll:true into:actionBlock.
       
  3016                     ^ self.
       
  3017                 ].
       
  3018             ].
       
  3019         ].
       
  3020         
  3006         "/ huh - completing strings, numbers or what?
  3021         "/ huh - completing strings, numbers or what?
  3007         (node parent notNil
  3022         (node parent notNil
  3008             and:[ node parent isMessage
  3023             and:[ node parent isMessage
  3009             and:[ node parent isKeyword ]]) 
  3024             and:[ node parent isKeyword ]]) 
  3010         ifFalse:[
  3025         ifFalse:[
  3014         node := node parent.
  3029         node := node parent.
  3015     ].
  3030     ].
  3016 
  3031 
  3017     checkedNode := node.
  3032     checkedNode := node.
  3018     [checkedNode notNil] whileTrue:[
  3033     [checkedNode notNil] whileTrue:[
  3019         (codeView characterPositionOfCursor < (checkedNode stop ? source size)) ifTrue:[
  3034         (characterPositionOfCursor < (checkedNode stop ? source size)) ifTrue:[
  3020             self information:'Inside a message node'.
  3035             self information:'Inside a message node'.
  3021             ^ self.
  3036             ^ self.
  3022         ].
  3037         ].
  3023 
  3038 
  3024         checkedNode isMessage ifTrue:[
  3039         checkedNode isMessage ifTrue:[
  3780 ! !
  3795 ! !
  3781 
  3796 
  3782 !DoWhatIMeanSupport class methodsFor:'documentation'!
  3797 !DoWhatIMeanSupport class methodsFor:'documentation'!
  3783 
  3798 
  3784 version
  3799 version
  3785     ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.139 2013-09-03 11:54:28 cg Exp $'
  3800     ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.140 2013-09-03 12:14:25 cg Exp $'
  3786 !
  3801 !
  3787 
  3802 
  3788 version_CVS
  3803 version_CVS
  3789     ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.139 2013-09-03 11:54:28 cg Exp $'
  3804     ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.140 2013-09-03 12:14:25 cg Exp $'
  3790 ! !
  3805 ! !
  3791 
  3806