DoWhatIMeanSupport.st
changeset 5106 5303d78eb69a
parent 5104 b295c198a0d0
child 5107 0048f8cf82fd
child 5109 18c01df208c2
--- a/DoWhatIMeanSupport.st	Thu May 12 21:31:06 2016 +0200
+++ b/DoWhatIMeanSupport.st	Sat May 14 15:23:08 2016 +0200
@@ -1733,6 +1733,9 @@
     "Created: / 10-11-2006 / 14:00:53 / cg"
 !
 
+codeCompletionForBlockArgument:node into:actionBlock
+!
+
 codeCompletionForLiteralSymbol:nodeOrNil element:tokenOrNil considerAll:considerAll into:actionBlock
     "looking for all symbols is way too much and inprecise;
      experiment: only present symbols which are used by the class,
@@ -1947,6 +1950,7 @@
     nodeReceiver notNil ifTrue:[
         classesOfReceiver := self classesOfNode:nodeReceiver.
     ].
+Transcript show:node; show:' -> '; showCR:classesOfReceiver.
 ( node isVariable and:[node name = 'self']) ifTrue:[self halt].
 
     "/ if there is already space before the cursor, and the parent node is not a message,
@@ -2616,12 +2620,17 @@
 !
 
 codeCompletionForMessageTo:node into:actionBlock
-    "find good suggestions for a message send to node, with no input yet"
+    "find good suggestions for a message send to node, with no input yet.
+     I.e. right after a receiver (w.o. any input yet)"
     
     |knownClass suggestions selectorsImplementedInClass mostUseful editActions pos|
  
-    (knownClass := self classOfNode:node) isNil ifTrue:[^ self].
-
+    (knownClass := self classOfNode:node) isNil ifTrue:[
+        self classOfNode:node.
+        ^ self
+    ].
+    
+Transcript show:node; show:' -> '; showCR:knownClass.
     selectorsImplementedInClass := Set new.
 
     knownClass withAllSuperclassesDo:[:cls |
@@ -3069,6 +3078,9 @@
     "Modified: / 01-06-2012 / 20:31:36 / cg"
 !
 
+codeCompletionForTempVariable:node into:actionBlock
+!
+
 codeCompletionForVariable:node into:actionBlock
     |nonMetaClass crsrPos nm parent
      allVariables allDistances variablesAlreadyAdded nodeVal
@@ -4326,7 +4338,7 @@
             ^ self.
         ].
     ].
-    (source startsWith:'sel') ifTrue:[self halt].
+    "/ (source startsWith:'sel') ifTrue:[self halt].
     nodeParent := node parent.
 
     (node isVariable
@@ -4366,8 +4378,8 @@
                         and:[scope arguments last stop >= node stop]]].
                     ].        
         ].
-        nodeIsInTemporaries ifTrue:[ ^ self ]. "/ no completion in a tempvar decl 
-        nodeIsInBlockArguments ifTrue:[ ^ self ]. "/ no completion in a tempvar decl 
+        nodeIsInTemporaries ifTrue:[ self codeCompletionForTempVariable:node into:actionBlock. ^ self ]. 
+        nodeIsInBlockArguments ifTrue:[ self codeCompletionForBlockArgument:node into:actionBlock. ^ self ]. 
 
         "/ for variable completion, cursor must be right after the node 
         codeView characterPositionOfCursor = (node stop + 1) ifTrue:[
@@ -4743,7 +4755,7 @@
 !
 
 addClassesOfExpression:expr inClass:classOrNil to:setOfTypes
-    |cls exprVal varName varScope instVarClass sym|
+    |cls exprVal varName varScope instVarClass classVarClass poolVarClass sym|
     
     expr isLiteral ifTrue:[
         exprVal := expr value.
@@ -4793,11 +4805,39 @@
         ].
         
         classOrNil notNil ifTrue:[
+            "/ inst var
             instVarClass := classOrNil whichClassDefinesInstVar:varName.
             instVarClass notNil ifTrue:[
                 setOfTypes addAll:(self classesOfInstVarNamed:varName inClass:instVarClass).
+                ^ setOfTypes
+            ].    
+        
+            "/ class vars
+            classVarClass := classOrNil theNonMetaclass whichClassDefinesClassVar:varName.
+            classVarClass notNil ifTrue:[
+                "/ see what is currently there
+                setOfTypes add:(classVarClass classVarAt:varName asSymbol) class.
+                ^ setOfTypes
+            ].    
+            varName isUppercaseFirst ifTrue:[
+                "/ private class
+                varName knownAsSymbol ifTrue:[
+                    cls := classOrNil theNonMetaclass privateClassesAt:varName asSymbol.
+                    cls notNil ifTrue:[
+                        setOfTypes add:(cls theMetaclass).
+                        ^ setOfTypes
+                    ].    
+                ].    
+            ].
+            "/ pool vars
+            poolVarClass := classOrNil theNonMetaclass whichPoolDefinesPoolVar:varName.
+            poolVarClass notNil ifTrue:[
+                "/ see what is currently there
+                setOfTypes add:(poolVarClass classVarAt:varName asSymbol) class.
+                ^ setOfTypes
             ].    
         ].
+        
         varName isUppercaseFirst ifTrue:[
             sym := varName asSymbolIfInterned.
             sym notNil ifTrue:[
@@ -5148,24 +5188,47 @@
      it is a good idea to know what the reveiver's value is.
      Sigh - returns nil as value both if unknown AND if a real nil is there"
 
-    |nodeVal con privateClass pool sym|
+    |nodeVal con classInstVarClass classVarClass privateClass pool sym nameSpace topNameSpace|
 
     aVariableName isUppercaseFirst ifTrue:[
         classOrNil notNil ifTrue:[
-            (classOrNil theNonMetaclass classVarNames includes:aVariableName) ifTrue:[
-                nodeVal := classOrNil theNonMetaclass classVarAt:aVariableName.
+            classOrNil isMeta ifTrue:[
+                "/ class instVars
+                (classInstVarClass := classOrNil whichClassDefinesInstVar:aVariableName) notNil ifTrue:[
+                    nodeVal := classInstVarClass theNonMetaclass instVarNamed:aVariableName.
+                    ^ { nodeVal . #classInstVariable }
+                ].    
+            ].
+            "/ class vars
+            (classVarClass := classOrNil theNonMetaclass whichClassDefinesClassVar:aVariableName) notNil ifTrue:[
+                nodeVal := classVarClass classVarAt:aVariableName asSymbol.
                 ^ { nodeVal . #classVariable }
-            ].
+            ].    
+
             privateClass := classOrNil theNonMetaclass privateClasses detect:[:cls | cls nameWithoutPrefix = aVariableName] ifNone:nil.
             privateClass notNil ifTrue:[
                 nodeVal := privateClass.
                 ^ { nodeVal . #privateClass }
             ].
-            pool := classOrNil theNonMetaclass sharedPools detect:[:pool | pool classVariableNames includes:aVariableName] ifNone:nil.
+            pool := classOrNil theNonMetaclass whichPoolDefinesPoolVar:aVariableName.
             pool notNil ifTrue:[
                 nodeVal := pool classVarAt:aVariableName.
                 ^ { nodeVal . #poolVariable }
             ].
+            ((nameSpace := classOrNil nameSpace) notNil and:[nameSpace ~~ Smalltalk]) ifTrue:[
+                nameSpace isNameSpace ifTrue:[
+                    nodeVal := nameSpace at:aVariableName asSymbol.
+                    ^ { nodeVal . #nameSpaceVariable }
+                ].
+                nodeVal := nameSpace privateClassNamed:aVariableName asSymbol.
+                ^ { nodeVal . #privateClass }
+            ].    
+            ((topNameSpace := classOrNil topNameSpace) notNil 
+            and:[topNameSpace ~~ nameSpace
+            and:[topNameSpace ~~ Smalltalk]]) ifTrue:[
+                nodeVal := topNameSpace at:aVariableName asSymbol.
+                ^ { nodeVal . #nameSpaceVariable }
+            ].    
         ].
         (sym := aVariableName asSymbolIfInterned) notNil ifTrue:[
             nodeVal := Smalltalk at:sym.