DoWhatIMeanSupport.st
changeset 5453 4e5f952f555d
parent 5451 32ed77c9d198
child 5462 6a7b577cd2b9
--- a/DoWhatIMeanSupport.st	Sun Feb 05 03:37:03 2017 +0100
+++ b/DoWhatIMeanSupport.st	Sun Feb 05 18:19:53 2017 +0100
@@ -2202,7 +2202,7 @@
                 parentNodeClassIfKnown := self classOfNode:parentNode.
                 (parentNodeClassIfKnown notNil and:[ parentNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[
                     "/ this is so common, that it deserves a special case:
-                    "/ if we complete an if after some boolean message e.g '(a == b) if'
+                    "/ if we complete an 'if' after some boolean message e.g '(a == b) if'
                     "/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic)
                     bestSelectors := self
                                         withoutSelectorsUnlikelyFor:parentNodeClassIfKnown
@@ -2225,14 +2225,15 @@
  
     (selector isUnarySelector and:[ node isMessage ]) ifTrue:[
         receiverNodeClassIfKnown := self classOfNode:nodeReceiver.
-        (receiverNodeClassIfKnown notNil and:[ receiverNodeClassIfKnown includesBehavior: Boolean ]) ifTrue:[
-            "/ this is so common, that it deserves a special case:
-            "/ if we complete an if after some boolean message e.g '(a == b) if'
-            "/ throw out the very unlikely ifNil, ifEmpty etc. messages (which are inherited by Object, but absolutely unrealistic)
-            bestSelectors := self
-                                withoutSelectorsUnlikelyFor:receiverNodeClassIfKnown
-                                from:bestSelectors
-                                forPartial:selector.
+
+        (receiverNodeClassIfKnown notNil) ifTrue:[
+            true "(receiverNodeClassIfKnown includesBehavior: Boolean)" ifTrue:[
+                bestSelectors := bestSelectors select:[:sel | receiverNodeClassIfKnown canUnderstand:sel].
+                bestSelectors := self
+                                    withoutSelectorsUnlikelyFor:receiverNodeClassIfKnown
+                                    from:bestSelectors
+                                    forPartial:selector.
+            ].
         ].
     ].
     
@@ -2666,7 +2667,7 @@
 
     "Created: / 10-11-2006 / 13:18:27 / cg"
     "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 01-05-2016 / 18:36:36 / cg"
+    "Modified: / 05-02-2017 / 12:59:16 / cg"
 !
 
 codeCompletionForMessageTo:node into:actionBlock
@@ -5605,10 +5606,18 @@
         ^ setOfTypes.
     ].
 
-    thisContext isRecursive ifTrue:[^ setOfTypes].
+    thisContext isRecursive ifTrue:[
+        |count|
+        count := 0.
+        thisContext withAllSendersDo:[:c | (c selector == thisContext selector) ifTrue:[count := count + 1 ]].
+        count > 10 ifTrue:[
+            ^ setOfTypes
+        ].
+    ].
 
     expr isVariable ifTrue:[
         varName := expr name.
+
         varName = 'self' ifTrue:[
             instanceOrNil notNil ifTrue:[
                 setOfTypes add:(instanceOrNil class).
@@ -5706,7 +5715,7 @@
 
     ^ setOfTypes
 
-    "Modified: / 07-06-2016 / 11:33:19 / cg"
+    "Modified: / 05-02-2017 / 12:58:40 / cg"
 !
 
 addClassesOfInstVarNamed:varName inClass:aClass to:setOfTypes
@@ -5993,7 +6002,13 @@
      When showing possible completions for a message,
      it is a good idea to know what the kind receiver is."
 
-    ^ self addClassesOfExpression:aNode inClass:classOrNil to:(IdentitySet new).
+    |dict|
+
+    dict := IdentitySet new.
+    self addClassesOfExpression:aNode inClass:classOrNil to:dict.
+    ^ dict.
+
+    "Modified: / 05-02-2017 / 12:40:16 / cg"
 !
 
 isNonDestructive:aMessageNode whenSentTo:receiverValue