Refactored API of CompletionEngine - caller now must set up an context pass it.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 21 Jan 2014 23:33:53 +0000
changeset 157 c71d2e62ece2
parent 156 9b02027653ed
child 158 d275ae2a0003
Refactored API of CompletionEngine - caller now must set up an context pass it. ComplectionContext now contains EditSupport instance and uses it to insert completions.
SmallSense__CompletionContext.st
SmallSense__CompletionEngine.st
SmallSense__EditSupport.st
SmallSense__GroovyCompletionEngineSimple.st
SmallSense__JavaCompletionEngineSimple.st
SmallSense__PO.st
SmallSense__SmalltalkCompletionEngine.st
SmallSense__SmalltalkParseNodeFinder.st
smallsense.rc
--- a/SmallSense__CompletionContext.st	Mon Jan 20 09:38:56 2014 +0000
+++ b/SmallSense__CompletionContext.st	Tue Jan 21 23:33:53 2014 +0000
@@ -3,7 +3,7 @@
 "{ NameSpace: SmallSense }"
 
 Object subclass:#CompletionContext
-	instanceVariableNames:'node position codeView language'
+	instanceVariableNames:'node position support'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'SmallSense-Core'
@@ -22,11 +22,15 @@
 !CompletionContext methodsFor:'accessing'!
 
 codeView
-    ^ codeView
+    ^ support codeView
+
+    "Modified: / 21-01-2014 / 23:16:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 language
-    ^ language
+    ^ support language
+
+    "Modified: / 21-01-2014 / 23:16:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 node
@@ -35,18 +39,14 @@
 
 position
     ^ position
+!
+
+support
+    ^ support
 ! !
 
 !CompletionContext methodsFor:'initialization'!
 
-codeView:something
-    codeView := something.
-!
-
-language:something
-    language := something.
-!
-
 node:nd position: pos
 
     node := nd.
@@ -54,6 +54,12 @@
 
     "Created: / 26-11-2011 / 16:22:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 16-10-2013 / 23:31:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+support: anEditSupport
+    support := anEditSupport.
+
+    "Modified: / 21-01-2014 / 23:31:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompletionContext methodsFor:'private'!
@@ -67,7 +73,7 @@
 
 wordBeforeCursorConsisitingOfCharactersMatching: characterMatchBlock
     | textView currentLine wordStart wordEnd |
-    textView := codeView.
+    textView := self codeView.
     textView isCodeView2 ifTrue:[textView := textView textView].
     currentLine := textView list at: textView cursorLine.
     currentLine isNil ifTrue:[ ^ '' ].
@@ -86,6 +92,7 @@
     ^ ''
 
     "Created: / 20-10-2013 / 00:17:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-01-2014 / 23:31:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompletionContext methodsFor:'queries'!
--- a/SmallSense__CompletionEngine.st	Mon Jan 20 09:38:56 2014 +0000
+++ b/SmallSense__CompletionEngine.st	Tue Jan 21 23:33:53 2014 +0000
@@ -3,7 +3,7 @@
 "{ NameSpace: SmallSense }"
 
 Object subclass:#CompletionEngine
-	instanceVariableNames:'codeView result'
+	instanceVariableNames:'codeView result context'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'SmallSense-Core'
@@ -20,13 +20,17 @@
 
 !CompletionEngine methodsFor:'completion'!
 
-complete
-    "Compute completion for `codeView`, taking all the information
-     from it. Returns a CompletionResult with computed completions"        
+complete: aCompletionContext
+    "Compute completion for given completion context, taking all the information
+     from it. Returns a CompletionResult with computed completions"
 
-    ^ self subclassResponsibility
+    context := aCompletionContext.
+    result := CompletionResult new.
+    codeView := context codeView.
+    result context: context.
+    ^ self complete.
 
-    "Modified (comment): / 02-10-2013 / 13:33:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 21-01-2014 / 23:07:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 completeFor: aCodeView2OrTextEditView
@@ -92,6 +96,17 @@
     "Modified: / 22-10-2013 / 12:13:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!CompletionEngine methodsFor:'completion-private'!
+
+complete
+    "Compute completion for `codeView`, taking all the information
+     from it. Returns a CompletionResult with computed completions"        
+
+    ^ self subclassResponsibility
+
+    "Modified (comment): / 02-10-2013 / 13:33:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !CompletionEngine class methodsFor:'documentation'!
 
 version_HG
--- a/SmallSense__EditSupport.st	Mon Jan 20 09:38:56 2014 +0000
+++ b/SmallSense__EditSupport.st	Tue Jan 21 23:33:53 2014 +0000
@@ -34,6 +34,12 @@
 
 !EditSupport methodsFor:'accessing'!
 
+codeView
+    ^ textView
+
+    "Created: / 21-01-2014 / 23:13:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 language
     ^ self subclassResponsibility.
 
@@ -158,6 +164,12 @@
     "Modified: / 20-01-2014 / 09:24:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+insertElectric: text ignoreKeystrokes: ignore    
+    self insertElectric:text advanceCursorBy:nil ignoreKeystrokes: ignore
+
+    "Created: / 21-01-2014 / 23:29:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 insertElectricBlockOpenedBy: openText closedBy: closeText
     | indent lines autoIndent |
 
@@ -332,12 +344,16 @@
             ex proceed.
         ]
         do: [
-            result := completionEngineClass new completeFor: codeView 
+            | context |
+
+            context := CompletionContext new.
+            context support: self.
+            result := completionEngineClass new complete: context
         ].
     ^ result.
 
     "Created: / 27-09-2013 / 13:21:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 02-10-2013 / 13:31:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-01-2014 / 23:17:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !EditSupport methodsFor:'private-scanning'!
--- a/SmallSense__GroovyCompletionEngineSimple.st	Mon Jan 20 09:38:56 2014 +0000
+++ b/SmallSense__GroovyCompletionEngineSimple.st	Tue Jan 21 23:33:53 2014 +0000
@@ -9,13 +9,14 @@
 	category:'SmallSense-Groovy'
 !
 
-!GroovyCompletionEngineSimple methodsFor:'completion'!
+!GroovyCompletionEngineSimple methodsFor:'completion-private'!
 
 complete
     super complete.
-    result context language: GroovyLanguage instance.
+    context language: GroovyLanguage instance.
     ^ result.
 
     "Created: / 17-10-2013 / 00:39:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-01-2014 / 23:21:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
--- a/SmallSense__JavaCompletionEngineSimple.st	Mon Jan 20 09:38:56 2014 +0000
+++ b/SmallSense__JavaCompletionEngineSimple.st	Tue Jan 21 23:33:53 2014 +0000
@@ -12,42 +12,6 @@
 
 !JavaCompletionEngineSimple methodsFor:'completion'!
 
-complete
-    
-    | position entry node context |
-
-    position := codeView characterPositionOfCursor.
-    codeView syntaxElements notEmptyOrNil ifTrue:[
-        entry := codeView syntaxElements atCharacterPosition: position - 1. 
-        entry notNil ifTrue:[
-            node := entry node
-        ].
-        codeView syntaxElements tree notNil ifTrue:[
-            classTree := (codeView syntaxElements tree types ? #()) detect:[:t | (position - 1) between: t declarationSourceStart and: t declarationSourceEnd ] ifNone:[nil].
-            classTree notNil ifTrue:[
-                methodTree := (classTree methods ? #()) detect:[:m | (position - 1) between: m declarationSourceStart and: m declarationSourceEnd ] ifNone:[nil].
-            ]
-        ].
-    ].
-
-    context := CompletionContext new.
-    context node: node position: position.
-    context codeView: codeView.
-    context language: JavaLanguage instance.
-         result context: context.         
-
-    node isNil ifTrue:[
-        self completeSimple.
-    ] ifFalse:[
-        self completeNode: node.
-    ].
-
-    ^ result
-
-    "Created: / 02-10-2013 / 13:55:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 20-10-2013 / 02:19:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
 completeNode: node
     Transcript 
         show: 'Java Simple Completion on node: ';
@@ -289,6 +253,40 @@
     "Created: / 03-10-2013 / 18:01:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!JavaCompletionEngineSimple methodsFor:'completion-private'!
+
+complete
+    
+    | position entry node |
+
+    position := context codeView characterPositionOfCursor.
+    codeView syntaxElements notEmptyOrNil ifTrue:[
+        entry := codeView syntaxElements atCharacterPosition: position - 1. 
+        entry notNil ifTrue:[
+            node := entry node
+        ].
+        codeView syntaxElements tree notNil ifTrue:[
+            classTree := (codeView syntaxElements tree types ? #()) detect:[:t | (position - 1) between: t declarationSourceStart and: t declarationSourceEnd ] ifNone:[nil].
+            classTree notNil ifTrue:[
+                methodTree := (classTree methods ? #()) detect:[:m | (position - 1) between: m declarationSourceStart and: m declarationSourceEnd ] ifNone:[nil].
+            ]
+        ].
+    ].
+
+    context node: node position: position.
+
+    node isNil ifTrue:[
+        self completeSimple.
+    ] ifFalse:[
+        self completeNode: node.
+    ].
+
+    ^ result
+
+    "Created: / 02-10-2013 / 13:55:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-01-2014 / 23:22:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !JavaCompletionEngineSimple class methodsFor:'documentation'!
 
 version_HG
--- a/SmallSense__PO.st	Mon Jan 20 09:38:56 2014 +0000
+++ b/SmallSense__PO.st	Tue Jan 21 23:33:53 2014 +0000
@@ -150,10 +150,10 @@
     stringAlreadyWritten := self stringAlreadyWritten.
     stringToInsert := stringToComplete copyFrom: (stringAlreadyWritten size + 1).
     textView isCodeView2 ifTrue:[textView := textView textView].
-    textView undoableDo:[
-        (stringToComplete startsWith: stringAlreadyWritten) ifTrue:[
-            textView insertStringAtCursor: stringToInsert.
-        ] ifFalse:[
+    (stringToComplete startsWith: stringAlreadyWritten) ifTrue:[
+        context support insertElectric: stringToInsert ignoreKeystrokes: stringToInsert
+    ] ifFalse:[
+       textView undoableDo:[
             | startCol endCol |
 
             endCol := textView cursorCol - 1.
@@ -165,7 +165,7 @@
     textView cursorCol: textView cursorCol - stringToComplete size + (po cursorColumnAfterCompleteForLanguage: context language).
 
     "Created: / 17-10-2013 / 01:08:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 20-10-2013 / 01:46:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-01-2014 / 23:30:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !PO methodsFor:'displaying'!
--- a/SmallSense__SmalltalkCompletionEngine.st	Mon Jan 20 09:38:56 2014 +0000
+++ b/SmallSense__SmalltalkCompletionEngine.st	Tue Jan 21 23:33:53 2014 +0000
@@ -43,26 +43,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
@@ -298,6 +278,25 @@
 
 !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 |
 
@@ -344,20 +343,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 
+    nodeToPosition := SmalltalkParseNodeFinder new 
                     findNodeIn: collector source tree: collector tree 
                     line: line column: col.
-    context codeView: codeView.
-    context language: SmalltalkLanguage instance.
-    result context: context.
-
+    context node: nodeToPosition key position: nodeToPosition value.
 
     context isAfterNode ifTrue:[
         self completeAfter:context node.
@@ -377,7 +373,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: / 21-01-2014 / 23:21:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 completeBefore:node
--- a/SmallSense__SmalltalkParseNodeFinder.st	Mon Jan 20 09:38:56 2014 +0000
+++ b/SmallSense__SmalltalkParseNodeFinder.st	Tue Jan 21 23:33:53 2014 +0000
@@ -31,10 +31,10 @@
 
     position := pos - 1.
     self visit: tree.
-    ^CompletionContext node: match ? previous position: pos.
+    ^(match ? previous) ->  pos.
 
     "Created: / 26-11-2011 / 15:37:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 24-09-2013 / 22:29:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-01-2014 / 23:18:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !SmalltalkParseNodeFinder methodsFor:'visiting'!
--- a/smallsense.rc	Mon Jan 20 09:38:56 2014 +0000
+++ b/smallsense.rc	Tue Jan 21 23:33:53 2014 +0000
@@ -25,7 +25,7 @@
       VALUE "LegalCopyright", "Copyright Claus Gittinger 1988-2011\nCopyright eXept Software AG 1998-2011\0"
       VALUE "ProductName", "Smalltalk/X\0"
       VALUE "ProductVersion", "6.2.3.0\0"
-      VALUE "ProductDate", "Mon, 20 Jan 2014 09:32:44 GMT\0"
+      VALUE "ProductDate", "Tue, 21 Jan 2014 23:32:00 GMT\0"
     END
 
   END