--- a/SmallSense__SmalltalkCompletionEngine.st Tue Nov 19 13:02:56 2013 +0000
+++ b/SmallSense__SmalltalkCompletionEngine.st Wed Feb 26 19:06:00 2014 +0100
@@ -4,12 +4,43 @@
CompletionEngine subclass:#SmalltalkCompletionEngine
instanceVariableNames:'collector'
- classVariableNames:''
+ classVariableNames:'Debug'
poolDictionaries:''
category:'SmallSense-Smalltalk'
!
+!SmalltalkCompletionEngine class methodsFor:'initialization'!
+
+initialize
+ "Invoked at system start or when the class is dynamically loaded."
+
+ "/ please change as required (and remove this comment)
+
+ Debug := false.
+
+ "Modified: / 22-01-2014 / 09:08:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!SmalltalkCompletionEngine class methodsFor:'accessing'!
+
+debug
+ ^ Debug
+
+ "Created: / 22-01-2014 / 09:08:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+debug: aBoolean
+ Debug := aBoolean .
+ "
+ self debug: true.
+ self debug: false.
+ "
+
+ "Created: / 22-01-2014 / 09:08:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 22-01-2014 / 19:42:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!SmalltalkCompletionEngine class methodsFor:'utilities'!
resultSetFor: mode source: source class: class line: line column: col
@@ -43,26 +74,6 @@
"Modified (format): / 02-10-2013 / 13:09:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
-!SmalltalkCompletionEngine methodsFor:'completion'!
-
-complete
- "Compute completion for `codeView`, taking all the information
- from it. Returns a CompletionResult with computed completions"
-
- | class |
-
- class := codeView isCodeView2
- ifTrue: [ codeView klass ]
- ifFalse: [ codeView editedClass ].
- class isNil ifTrue:[
- class := UndefinedObject.
- ].
- ^ self complete: codeView codeAspect source: codeView contents class: class line: codeView cursorLine column: codeView cursorCol
-
- "Created: / 02-10-2013 / 13:32:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 04-10-2013 / 08:18:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
!SmalltalkCompletionEngine methodsFor:'completion-helpers'!
javaClassesDo: aBlock
@@ -110,15 +121,13 @@
ns keysDo:[:nm|
(nm startsWith: prefix) ifTrue:[
cls := ns classNamed: nm.
- (JavaPackage isNil or:[cls isJavaPackage not]) ifTrue:[
- cls notNil ifTrue:[
- cls isBehavior ifTrue:[
- result add:(ClassPO new subject: cls; showPrefix: cls isJavaClass).
- ] ifFalse:[
- result add:(VariablePO globalVariable: cls).
- ]
+ (cls notNil and:[cls name = nm]) ifTrue:[
+ (JavaPackage isNil or:[cls isJavaPackage not]) ifTrue:[
+ result add:(ClassPO new subject: cls; showPrefix: cls isJavaClass).
]
- ]
+ ] ifFalse:[
+ result add:(VariablePO globalVariable: nm)
+ ].
].
].
ns ~~ Smalltalk ifTrue:[
@@ -139,7 +148,7 @@
]
"Created: / 26-11-2011 / 17:29:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 20-10-2013 / 02:40:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 25-11-2013 / 11:48:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
addJavaClassesInPackage: prefix
@@ -164,6 +173,11 @@
| classes seen |
classes := type classes.
+ "/ Hack for Boolean: ifTrue:iFalse: etc are not defined
+ "/ in Boolean ?!!?
+ (classes size == 1 and:[classes anElement == Boolean ]) ifTrue:[
+ classes := Array with: True with: False.
+ ].
classes size == 1 ifTrue:[
classes anElement == JavaPackage class ifTrue:[
"/ Special hack for JAVA: for pattern `JAVA java lang reflect`
@@ -188,7 +202,7 @@
].
seen := Set new.
- type classesDo: [:each |
+ classes do: [:each |
| class |
class := each.
@@ -217,7 +231,7 @@
].
"Created: / 26-11-2011 / 17:03:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 22-10-2013 / 12:13:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-01-2014 / 19:48:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
addPools
@@ -256,10 +270,26 @@
"Add Instance variables"
klass := collector klass.
[ klass notNil ] whileTrue:[
- klass instVarNames do:[:nm |
- result add: (VariablePO instanceVariable: nm in: klass).
- ].
- klass := klass superclass.
+ | usedInstVars |
+
+ usedInstVars := collector parser usedInstVars.
+ klass instVarNames do:[:nm |
+ | po |
+
+ po := VariablePO instanceVariable: nm in: klass.
+ "/ Raise relevance if the instvar is already used in the code...
+ (usedInstVars includes: nm) ifTrue:[
+ po relevance: (po relevance + 10).
+ ].
+
+ result add: po.
+ ].
+ "/ When on class side (i.e., in class method), do not complete
+ "/ instance variables of Class / ClassDescription / Behaviour
+ "/ as STC won't compile such code.
+ klass := (klass isMetaclass and:[klass superclass == Class])
+ ifTrue:[nil]
+ ifFalse:[klass superclass].
].
"Add pseudo variables"
#(self super here thisContext) do:[:nm|
@@ -273,6 +303,11 @@
collector parser methodVars ? #() do:[:nm|
result add: (VariablePO variable: nm).
].
+ "Add literals"
+ #(#true #false #nil ) do:[:nm|
+ result add: (SnippetPO new subject: nm).
+ ].
+
n := node.
[ n notNil ] whileTrue:[
@@ -284,11 +319,30 @@
]
"Created: / 31-07-2013 / 00:32:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 18-09-2013 / 00:28:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-01-2014 / 19:42:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!SmalltalkCompletionEngine methodsFor:'completion-private'!
+complete
+ "Compute completion for `codeView`, taking all the information
+ from it. Returns a CompletionResult with computed completions"
+
+ | class |
+
+ codeView := context codeView.
+ class := codeView isCodeView2
+ ifTrue: [ codeView klass ]
+ ifFalse: [ codeView editedClass ].
+ class isNil ifTrue:[
+ class := UndefinedObject.
+ ].
+ ^ self complete: codeView codeAspect source: codeView contents class: class line: codeView cursorLine column: codeView cursorCol
+
+ "Created: / 02-10-2013 / 13:32:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 21-01-2014 / 23:20:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
complete: mode source: source class: class line: lineNrArg column: colNrArg
| inferencer lineNr colNr |
@@ -335,20 +389,17 @@
completeAtLine:line column:col collector:coll
"find most possible codeCompletion object"
-
- | context |
+
+ | nodeToPosition |
collector := coll.
(collector tree isNil or:[collector tree == #Error]) ifTrue:[
^ nil
].
- context := SmalltalkParseNodeFinder new
- findNodeIn: collector source tree: collector tree
- line: line column: col.
- context codeView: codeView.
- context language: SmalltalkLanguage instance.
- result context: context.
-
+ nodeToPosition := SmalltalkParseNodeFinder new
+ findNodeIn: collector source tree: collector tree comments: collector parser commentPositions
+ line: line column: col.
+ context node: nodeToPosition key position: nodeToPosition value.
context isAfterNode ifTrue:[
self completeAfter:context node.
@@ -368,7 +419,7 @@
"Created: / 04-03-2011 / 13:01:14 / Jakub <zelenja7@fel.cvut.cz>"
"Modified: / 08-04-2011 / 10:52:59 / Jakub <zelenja7@fel.cvut.cz>"
"Created: / 26-11-2011 / 17:05:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 17-10-2013 / 00:34:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 29-01-2014 / 10:36:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
completeBefore:node
@@ -399,6 +450,10 @@
| type |
type := node receiver inferedType.
+ Debug ifTrue:[
+ Transcript showCR: '--> completing messages for ' , type printString.
+ ].
+
type isUnknownType ifFalse:[
self addMethodsForType: type.
"/ If the type is union of more than 6 types, then
@@ -420,7 +475,7 @@
"Created: / 07-03-2011 / 18:59:02 / Jakub <zelenja7@fel.cvut.cz>"
"Modified: / 08-04-2011 / 09:31:51 / Jakub <zelenja7@fel.cvut.cz>"
"Created: / 26-11-2011 / 17:07:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 16-10-2013 / 15:53:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 22-01-2014 / 09:10:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!SmalltalkCompletionEngine class methodsFor:'documentation'!
@@ -431,6 +486,8 @@
!
version_SVN
- ^ '$Id: SmallSenseRecognizer.st 7826 2011-11-27 09:48:43Z vranyj1 $'
+ ^ '$Id: SmallSense__SmalltalkCompletionEngine.st,v 1.2 2014/02/12 14:49:29 sr Exp $'
! !
+
+SmalltalkCompletionEngine initialize!