DoWhatIMeanSupport.st
changeset 5106 5303d78eb69a
parent 5104 b295c198a0d0
child 5107 0048f8cf82fd
child 5109 18c01df208c2
equal deleted inserted replaced
5104:b295c198a0d0 5106:5303d78eb69a
  1731     ^ choice
  1731     ^ choice
  1732 
  1732 
  1733     "Created: / 10-11-2006 / 14:00:53 / cg"
  1733     "Created: / 10-11-2006 / 14:00:53 / cg"
  1734 !
  1734 !
  1735 
  1735 
       
  1736 codeCompletionForBlockArgument:node into:actionBlock
       
  1737 !
       
  1738 
  1736 codeCompletionForLiteralSymbol:nodeOrNil element:tokenOrNil considerAll:considerAll into:actionBlock
  1739 codeCompletionForLiteralSymbol:nodeOrNil element:tokenOrNil considerAll:considerAll into:actionBlock
  1737     "looking for all symbols is way too much and inprecise;
  1740     "looking for all symbols is way too much and inprecise;
  1738      experiment: only present symbols which are used by the class,
  1741      experiment: only present symbols which are used by the class,
  1739      and classes in that class category, or at least: implemented as method.
  1742      and classes in that class category, or at least: implemented as method.
  1740      We'll see..."
  1743      We'll see..."
  1945     parentNode := node parent.
  1948     parentNode := node parent.
  1946     nodeReceiver := node receiver.
  1949     nodeReceiver := node receiver.
  1947     nodeReceiver notNil ifTrue:[
  1950     nodeReceiver notNil ifTrue:[
  1948         classesOfReceiver := self classesOfNode:nodeReceiver.
  1951         classesOfReceiver := self classesOfNode:nodeReceiver.
  1949     ].
  1952     ].
       
  1953 Transcript show:node; show:' -> '; showCR:classesOfReceiver.
  1950 ( node isVariable and:[node name = 'self']) ifTrue:[self halt].
  1954 ( node isVariable and:[node name = 'self']) ifTrue:[self halt].
  1951 
  1955 
  1952     "/ if there is already space before the cursor, and the parent node is not a message,
  1956     "/ if there is already space before the cursor, and the parent node is not a message,
  1953     "/ do not attempt to complete the current message.
  1957     "/ do not attempt to complete the current message.
  1954     "/ If it is a message, we will look for parent-message completion also below (best2 stuff)
  1958     "/ If it is a message, we will look for parent-message completion also below (best2 stuff)
  2614     "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2618     "Modified: / 16-02-2010 / 10:33:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  2615     "Modified: / 01-05-2016 / 18:36:36 / cg"
  2619     "Modified: / 01-05-2016 / 18:36:36 / cg"
  2616 !
  2620 !
  2617 
  2621 
  2618 codeCompletionForMessageTo:node into:actionBlock
  2622 codeCompletionForMessageTo:node into:actionBlock
  2619     "find good suggestions for a message send to node, with no input yet"
  2623     "find good suggestions for a message send to node, with no input yet.
       
  2624      I.e. right after a receiver (w.o. any input yet)"
  2620     
  2625     
  2621     |knownClass suggestions selectorsImplementedInClass mostUseful editActions pos|
  2626     |knownClass suggestions selectorsImplementedInClass mostUseful editActions pos|
  2622  
  2627  
  2623     (knownClass := self classOfNode:node) isNil ifTrue:[^ self].
  2628     (knownClass := self classOfNode:node) isNil ifTrue:[
  2624 
  2629         self classOfNode:node.
       
  2630         ^ self
       
  2631     ].
       
  2632     
       
  2633 Transcript show:node; show:' -> '; showCR:knownClass.
  2625     selectorsImplementedInClass := Set new.
  2634     selectorsImplementedInClass := Set new.
  2626 
  2635 
  2627     knownClass withAllSuperclassesDo:[:cls |
  2636     knownClass withAllSuperclassesDo:[:cls |
  2628         cls ~~ Object ifTrue:[
  2637         cls ~~ Object ifTrue:[
  2629             selectorsImplementedInClass addAll:cls selectors.
  2638             selectorsImplementedInClass addAll:cls selectors.
  3067     "Created: / 10-11-2006 / 13:46:44 / cg"
  3076     "Created: / 10-11-2006 / 13:46:44 / cg"
  3068     "Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  3077     "Modified: / 16-02-2010 / 10:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
  3069     "Modified: / 01-06-2012 / 20:31:36 / cg"
  3078     "Modified: / 01-06-2012 / 20:31:36 / cg"
  3070 !
  3079 !
  3071 
  3080 
       
  3081 codeCompletionForTempVariable:node into:actionBlock
       
  3082 !
       
  3083 
  3072 codeCompletionForVariable:node into:actionBlock
  3084 codeCompletionForVariable:node into:actionBlock
  3073     |nonMetaClass crsrPos nm parent
  3085     |nonMetaClass crsrPos nm parent
  3074      allVariables allDistances variablesAlreadyAdded nodeVal
  3086      allVariables allDistances variablesAlreadyAdded nodeVal
  3075      char getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc
  3087      char getDistanceComputeBlockWithWeight addWithFactorBlock allTheBest bestAssoc
  3076      globalFactor localFactor selectorOfMessageToNode implementors argIdx namesUsed kwPart editActions suggestions nameIsOK longerNames setOfNames otherArgNames
  3088      globalFactor localFactor selectorOfMessageToNode implementors argIdx namesUsed kwPart editActions suggestions nameIsOK longerNames setOfNames otherArgNames
  4324             "/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'.
  4336             "/ Transcript showCR:'No parseNode found (syntax error before or in comment?)'.
  4325             self information:'No parseNode found (syntax error before or in comment?)'.
  4337             self information:'No parseNode found (syntax error before or in comment?)'.
  4326             ^ self.
  4338             ^ self.
  4327         ].
  4339         ].
  4328     ].
  4340     ].
  4329     (source startsWith:'sel') ifTrue:[self halt].
  4341     "/ (source startsWith:'sel') ifTrue:[self halt].
  4330     nodeParent := node parent.
  4342     nodeParent := node parent.
  4331 
  4343 
  4332     (node isVariable
  4344     (node isVariable
  4333     and:[ nodeParent notNil
  4345     and:[ nodeParent notNil
  4334     and:[ nodeParent isMessage
  4346     and:[ nodeParent isMessage
  4364                         and:[scope arguments notEmpty
  4376                         and:[scope arguments notEmpty
  4365                         and:[scope arguments first start <= node start
  4377                         and:[scope arguments first start <= node start
  4366                         and:[scope arguments last stop >= node stop]]].
  4378                         and:[scope arguments last stop >= node stop]]].
  4367                     ].        
  4379                     ].        
  4368         ].
  4380         ].
  4369         nodeIsInTemporaries ifTrue:[ ^ self ]. "/ no completion in a tempvar decl 
  4381         nodeIsInTemporaries ifTrue:[ self codeCompletionForTempVariable:node into:actionBlock. ^ self ]. 
  4370         nodeIsInBlockArguments ifTrue:[ ^ self ]. "/ no completion in a tempvar decl 
  4382         nodeIsInBlockArguments ifTrue:[ self codeCompletionForBlockArgument:node into:actionBlock. ^ self ]. 
  4371 
  4383 
  4372         "/ for variable completion, cursor must be right after the node 
  4384         "/ for variable completion, cursor must be right after the node 
  4373         codeView characterPositionOfCursor = (node stop + 1) ifTrue:[
  4385         codeView characterPositionOfCursor = (node stop + 1) ifTrue:[
  4374             codeView characterBeforeCursor ~= Character space ifTrue:[
  4386             codeView characterBeforeCursor ~= Character space ifTrue:[
  4375                 self codeCompletionForVariable:node into:actionBlock.
  4387                 self codeCompletionForVariable:node into:actionBlock.
  4741     ].    
  4753     ].    
  4742     ^ setOfTypes
  4754     ^ setOfTypes
  4743 !
  4755 !
  4744 
  4756 
  4745 addClassesOfExpression:expr inClass:classOrNil to:setOfTypes
  4757 addClassesOfExpression:expr inClass:classOrNil to:setOfTypes
  4746     |cls exprVal varName varScope instVarClass sym|
  4758     |cls exprVal varName varScope instVarClass classVarClass poolVarClass sym|
  4747     
  4759     
  4748     expr isLiteral ifTrue:[
  4760     expr isLiteral ifTrue:[
  4749         exprVal := expr value.
  4761         exprVal := expr value.
  4750         cls := exprVal class.         
  4762         cls := exprVal class.         
  4751         (exprVal isArray or:[ exprVal isByteArray or:[ exprVal isString ]]) ifTrue:[
  4763         (exprVal isArray or:[ exprVal isByteArray or:[ exprVal isString ]]) ifTrue:[
  4791                 ^ setOfTypes
  4803                 ^ setOfTypes
  4792             ].    
  4804             ].    
  4793         ].
  4805         ].
  4794         
  4806         
  4795         classOrNil notNil ifTrue:[
  4807         classOrNil notNil ifTrue:[
       
  4808             "/ inst var
  4796             instVarClass := classOrNil whichClassDefinesInstVar:varName.
  4809             instVarClass := classOrNil whichClassDefinesInstVar:varName.
  4797             instVarClass notNil ifTrue:[
  4810             instVarClass notNil ifTrue:[
  4798                 setOfTypes addAll:(self classesOfInstVarNamed:varName inClass:instVarClass).
  4811                 setOfTypes addAll:(self classesOfInstVarNamed:varName inClass:instVarClass).
       
  4812                 ^ setOfTypes
  4799             ].    
  4813             ].    
  4800         ].
  4814         
       
  4815             "/ class vars
       
  4816             classVarClass := classOrNil theNonMetaclass whichClassDefinesClassVar:varName.
       
  4817             classVarClass notNil ifTrue:[
       
  4818                 "/ see what is currently there
       
  4819                 setOfTypes add:(classVarClass classVarAt:varName asSymbol) class.
       
  4820                 ^ setOfTypes
       
  4821             ].    
       
  4822             varName isUppercaseFirst ifTrue:[
       
  4823                 "/ private class
       
  4824                 varName knownAsSymbol ifTrue:[
       
  4825                     cls := classOrNil theNonMetaclass privateClassesAt:varName asSymbol.
       
  4826                     cls notNil ifTrue:[
       
  4827                         setOfTypes add:(cls theMetaclass).
       
  4828                         ^ setOfTypes
       
  4829                     ].    
       
  4830                 ].    
       
  4831             ].
       
  4832             "/ pool vars
       
  4833             poolVarClass := classOrNil theNonMetaclass whichPoolDefinesPoolVar:varName.
       
  4834             poolVarClass notNil ifTrue:[
       
  4835                 "/ see what is currently there
       
  4836                 setOfTypes add:(poolVarClass classVarAt:varName asSymbol) class.
       
  4837                 ^ setOfTypes
       
  4838             ].    
       
  4839         ].
       
  4840         
  4801         varName isUppercaseFirst ifTrue:[
  4841         varName isUppercaseFirst ifTrue:[
  4802             sym := varName asSymbolIfInterned.
  4842             sym := varName asSymbolIfInterned.
  4803             sym notNil ifTrue:[
  4843             sym notNil ifTrue:[
  4804                 exprVal := (Smalltalk at:sym).
  4844                 exprVal := (Smalltalk at:sym).
  4805                 exprVal notNil ifTrue:[
  4845                 exprVal notNil ifTrue:[
  5146 valueAndKindOfVariable:aVariableName
  5186 valueAndKindOfVariable:aVariableName
  5147     "when showing possible completions for a variable,
  5187     "when showing possible completions for a variable,
  5148      it is a good idea to know what the reveiver's value is.
  5188      it is a good idea to know what the reveiver's value is.
  5149      Sigh - returns nil as value both if unknown AND if a real nil is there"
  5189      Sigh - returns nil as value both if unknown AND if a real nil is there"
  5150 
  5190 
  5151     |nodeVal con privateClass pool sym|
  5191     |nodeVal con classInstVarClass classVarClass privateClass pool sym nameSpace topNameSpace|
  5152 
  5192 
  5153     aVariableName isUppercaseFirst ifTrue:[
  5193     aVariableName isUppercaseFirst ifTrue:[
  5154         classOrNil notNil ifTrue:[
  5194         classOrNil notNil ifTrue:[
  5155             (classOrNil theNonMetaclass classVarNames includes:aVariableName) ifTrue:[
  5195             classOrNil isMeta ifTrue:[
  5156                 nodeVal := classOrNil theNonMetaclass classVarAt:aVariableName.
  5196                 "/ class instVars
       
  5197                 (classInstVarClass := classOrNil whichClassDefinesInstVar:aVariableName) notNil ifTrue:[
       
  5198                     nodeVal := classInstVarClass theNonMetaclass instVarNamed:aVariableName.
       
  5199                     ^ { nodeVal . #classInstVariable }
       
  5200                 ].    
       
  5201             ].
       
  5202             "/ class vars
       
  5203             (classVarClass := classOrNil theNonMetaclass whichClassDefinesClassVar:aVariableName) notNil ifTrue:[
       
  5204                 nodeVal := classVarClass classVarAt:aVariableName asSymbol.
  5157                 ^ { nodeVal . #classVariable }
  5205                 ^ { nodeVal . #classVariable }
  5158             ].
  5206             ].    
       
  5207 
  5159             privateClass := classOrNil theNonMetaclass privateClasses detect:[:cls | cls nameWithoutPrefix = aVariableName] ifNone:nil.
  5208             privateClass := classOrNil theNonMetaclass privateClasses detect:[:cls | cls nameWithoutPrefix = aVariableName] ifNone:nil.
  5160             privateClass notNil ifTrue:[
  5209             privateClass notNil ifTrue:[
  5161                 nodeVal := privateClass.
  5210                 nodeVal := privateClass.
  5162                 ^ { nodeVal . #privateClass }
  5211                 ^ { nodeVal . #privateClass }
  5163             ].
  5212             ].
  5164             pool := classOrNil theNonMetaclass sharedPools detect:[:pool | pool classVariableNames includes:aVariableName] ifNone:nil.
  5213             pool := classOrNil theNonMetaclass whichPoolDefinesPoolVar:aVariableName.
  5165             pool notNil ifTrue:[
  5214             pool notNil ifTrue:[
  5166                 nodeVal := pool classVarAt:aVariableName.
  5215                 nodeVal := pool classVarAt:aVariableName.
  5167                 ^ { nodeVal . #poolVariable }
  5216                 ^ { nodeVal . #poolVariable }
  5168             ].
  5217             ].
       
  5218             ((nameSpace := classOrNil nameSpace) notNil and:[nameSpace ~~ Smalltalk]) ifTrue:[
       
  5219                 nameSpace isNameSpace ifTrue:[
       
  5220                     nodeVal := nameSpace at:aVariableName asSymbol.
       
  5221                     ^ { nodeVal . #nameSpaceVariable }
       
  5222                 ].
       
  5223                 nodeVal := nameSpace privateClassNamed:aVariableName asSymbol.
       
  5224                 ^ { nodeVal . #privateClass }
       
  5225             ].    
       
  5226             ((topNameSpace := classOrNil topNameSpace) notNil 
       
  5227             and:[topNameSpace ~~ nameSpace
       
  5228             and:[topNameSpace ~~ Smalltalk]]) ifTrue:[
       
  5229                 nodeVal := topNameSpace at:aVariableName asSymbol.
       
  5230                 ^ { nodeVal . #nameSpaceVariable }
       
  5231             ].    
  5169         ].
  5232         ].
  5170         (sym := aVariableName asSymbolIfInterned) notNil ifTrue:[
  5233         (sym := aVariableName asSymbolIfInterned) notNil ifTrue:[
  5171             nodeVal := Smalltalk at:sym.
  5234             nodeVal := Smalltalk at:sym.
  5172             (nodeVal notNil or:[Smalltalk includesKey:sym]) ifTrue:[     
  5235             (nodeVal notNil or:[Smalltalk includesKey:sym]) ifTrue:[     
  5173                 ^ { nodeVal . #global }
  5236                 ^ { nodeVal . #global }