changed:
authorClaus Gittinger <cg@exept.de>
Fri, 01 Jun 2012 20:42:42 +0200
changeset 4130 9ee47cc0138c
parent 4129 65e5f7358a70
child 4131 c7dde0b20bfd
changed: #codeCompletionForMethod:inClass:codeView: #findNodeForInterval:in:allowErrors:mustBeMethod:
DoWhatIMeanSupport.st
--- a/DoWhatIMeanSupport.st	Mon May 21 10:10:53 2012 +0200
+++ b/DoWhatIMeanSupport.st	Fri Jun 01 20:42:42 2012 +0200
@@ -529,8 +529,7 @@
     |crsrPos
      selectorSoFar matchingSelectors
      selectors distances best rest 
-     allExistingMethods namesOfArguments 
-     nameBag namesByCount|  
+     allExistingMethods nameBag namesByCount selectors1 selectors2|  
 
     crsrPos := codeView characterPositionOfCursor - 1.
 
@@ -543,28 +542,42 @@
 
         (crsrPos >= partToken start
         and:[crsrPos <= partToken stop]) ifTrue:[
-            matchingSelectors := Smalltalk allClasses
+            (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
+                matchingSelectors := Smalltalk allClasses
                                     inject:(Set new)
                                     into:[:theSet :eachClass |
                                         |md|
 
-                                        (classOrNil notNil and:[classOrNil isMeta]) ifTrue:[
-                                            md := eachClass theMetaclass methodDictionary
-                                        ] ifFalse:[
-                                            md := eachClass theNonMetaclass methodDictionary
-                                        ].
+                                        md := eachClass theMetaclass methodDictionary.
                                         theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
                                         theSet.
                                     ].
+                "/ dont forget the stuff in the class-line
+                Metaclass withAllSuperclassesDo:[:cls |
+                    matchingSelectors addAll:(cls methodDictionary keys select:[:sel |sel startsWith:selectorSoFar]).
+                ].
+            ] ifFalse:[
+                matchingSelectors := Smalltalk allClasses
+                                    inject:(Set new)
+                                    into:[:theSet :eachClass |
+                                        |md|
+
+                                        md := eachClass theNonMetaclass methodDictionary.
+                                        theSet addAll:(md keys select:[:sel |sel startsWith:selectorSoFar]).
+                                        theSet.
+                                    ].
+            ].
             selectors := matchingSelectors asOrderedCollection.
+
             "/ if there is only one, and user has already entered it, he might want to complete the argument-name    
             (selectors size == 1 
             and:[selectors first = selectorSoFar]) ifTrue:[
+                selectorSoFar numArgs == 0 ifTrue:[ ^ self ].
+
                 allExistingMethods := (Smalltalk allImplementorsOf:selectorSoFar asSymbol)
-                                            collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
-                namesOfArguments := allExistingMethods collect:[:eachMethod | eachMethod methodArgNames].
+                                        collect:[:cls | cls compiledMethodAt:selectorSoFar asSymbol].
                 nameBag := Bag new.
-                namesOfArguments do:[:eachNameVector | nameBag add:(eachNameVector at:argNr)].
+                allExistingMethods do:[:eachMethod | nameBag addAll:(eachMethod methodArgNames ? #())].
                 namesByCount := nameBag valuesAndCounts sort:[:a :b | a value < b value].   
                 "/ take the one which occurs most often     
                 best := self askUserForCompletion:'argument' for:codeView at: node start from:(namesByCount collect:[:a | a key]).
@@ -580,23 +593,40 @@
                     info:'completion'.
                 codeView cursorToCharacterPosition:(crsrPos + best size - 1).    
             ] ifFalse:[
-                distances := selectors collect:[:each | each spellAgainst:selectorSoFar].
-                distances sortWith:selectors.
-                selectors reverse.
-                best := self askUserForCompletion:'selector' for:codeView at: node start from:selectors.
+                "the ones implemented in superclasses are shown first"
+                classOrNil notNil ifTrue:[
+                    selectors1 := selectors select:[:sel | classOrNil respondsTo:sel].  "/ in super
+                    selectors2 := selectors reject:[:sel | selectors1 includes:sel ].   "/ not in super
+                ] ifFalse:[
+                    selectors1 := selectors
+                ].
+
+                distances := selectors1 collect:[:each | each spellAgainst:selectorSoFar].
+                distances sortWith:selectors1.
+                selectors1 reverse.
+                selectors := selectors1.
+
+                selectors2 notEmptyOrNil ifTrue:[
+                    distances := selectors2 collect:[:each | each spellAgainst:selectorSoFar].
+                    distances sortWith:selectors2.
+                    selectors2 reverse.
+                    selectors1 := selectors1 collect:[:sel | sel allBold].
+                    selectors := selectors1,selectors2.
+                ].
+                
+                best := self askUserForCompletion:'selector' for:codeView at:(node start) from:selectors.
                 best isNil ifTrue:[^ self].
 
                 rest := best copyFrom:selectorSoFar size.
-
                 codeView
                     undoableDo:[ 
                         codeView 
-                            replaceFromCharacterPosition:crsrPos 
-                            to:crsrPos 
+                            replaceFromCharacterPosition:crsrPos+1 
+                            to:crsrPos+1 
                             with:rest 
                     ]
                     info:'Completion'.
-                codeView cursorToCharacterPosition:(crsrPos + rest size - 1).    
+                codeView cursorToCharacterPosition:(crsrPos+1 + rest size - 1).    
             ].
             codeView cursorRight. "/ kludge to make it visible   
         ].
@@ -605,7 +635,7 @@
     "Modified: / 04-07-2006 / 18:48:26 / fm"
     "Created: / 10-11-2006 / 13:46:44 / cg"
     "Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 06-07-2011 / 14:17:07 / cg"
+    "Modified: / 01-06-2012 / 20:31:36 / cg"
 !
 
 codeCompletionForVariable:node inClass:classOrNil codeView:codeView
@@ -993,7 +1023,7 @@
 
     interval isEmpty ifTrue: [^ nil].
     RBParser isNil ifTrue: [^ nil].
-
+    LastSource := nil.
     source = LastSource ifTrue:[
         tree := LastParseTree.
     ] ifFalse:[
@@ -1051,7 +1081,7 @@
                         nodeGenerationCallback:nodeGenerationHook.   
             ].
         ].
-        ^ firstIntersectingNode
+        firstIntersectingNode notNil ifTrue:[ ^ firstIntersectingNode ].
     ].
 
     ^ self findNodeForInterval:interval inParseTree:tree.
@@ -2243,5 +2273,5 @@
 !DoWhatIMeanSupport class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.91 2012-01-13 11:26:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.92 2012-06-01 18:42:42 cg Exp $'
 ! !