SmallSense__CompletionEngine.st
changeset 192 f27ce6dac101
parent 187 7baeeea7d8ae
child 201 9a0df215823a
child 205 43bee6463c53
--- a/SmallSense__CompletionEngine.st	Tue Apr 08 15:03:38 2014 +0200
+++ b/SmallSense__CompletionEngine.st	Tue Apr 08 21:46:51 2014 +0200
@@ -12,6 +12,31 @@
 
 !CompletionEngine class methodsFor:'accessing'!
 
+exactMatcher
+    "Return a match block returning true, if given selector start with given prefix"
+
+    ^ [ :prefix :selector | selector startsWith: prefix ]
+
+    "Created: / 08-04-2014 / 21:31:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+inexactMatcher
+    "Return a match block returning true, if given prefix matches given selector"
+
+    ^ [ :prefix :selector |
+        prefix size < 5 ifTrue:[ 
+            selector startsWith: prefix.  
+        ] ifFalse:[ 
+            | part |
+
+            part := selector copyTo: (prefix size min: selector size).
+            (prefix levenshteinTo: part) < 15
+        ].
+    ].
+
+    "Created: / 08-04-2014 / 21:30:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 matcher
     "Return a match block returning true, if given prefix matches given selector"
 
@@ -68,28 +93,37 @@
 !CompletionEngine methodsFor:'completion-individual'!
 
 addMethodsStartingWith: prefix
-    ^ self addMethodsStartingWith: prefix filter: nil
+    ^ self addMethodsStartingWith: prefix stripOff: nil filter: nil
 
     "Created: / 24-07-2013 / 13:10:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-10-2013 / 17:59:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-04-2014 / 21:36:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+addMethodsStartingWith: prefix stripOff: stripoffPrefix 
+    ^ self addMethodsStartingWith: prefix stripOff: stripoffPrefix filter: nil
+
+    "Created: / 08-04-2014 / 21:36:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-addMethodsStartingWith: prefix filter: filterOrNil
-    ^ self addMethodsStartingWith: prefix filter: filterOrNil matcher: CompletionEngine matcher.
+addMethodsStartingWith: prefix stripOff: stripoffPrefix filter: filterOrNil
+    | matcher |
 
-    "Created: / 03-10-2013 / 17:56:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 02-04-2014 / 23:30:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    matcher := stripoffPrefix isEmptyOrNil ifTrue:[ CompletionEngine inexactMatcher ] ifFalse:[ CompletionEngine exactMatcher ].
+    ^ self addMethodsStartingWith: prefix stripOff: stripoffPrefix filter: filterOrNil matcher: matcher.
+
+    "Created: / 08-04-2014 / 21:35:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-addMethodsStartingWith: prefix filter: filterOrNil matcher: matcher
-    | selectors filter |
+addMethodsStartingWith: prefix stripOff: stripoffPrefix filter: filterOrNil matcher: matcher
+    | matchPrefix selectors filter |
 
     selectors := Dictionary new.
+    matchPrefix := stripoffPrefix isNil ifTrue:[ prefix ] ifFalse:[ stripoffPrefix , prefix ]. 
     filter := filterOrNil  isNil ifTrue:[ [:method | true ] ] ifFalse:[ filterOrNil  ].
 
     Smalltalk allClassesDo:[:class|
         class selectorsAndMethodsDo:[:selector :mthd |             
-            (mthd isSynthetic not and:[(filter value: mthd) and:[ matcher value: prefix value: selector]]) ifTrue:[
+            (mthd isSynthetic not and:[(filter value: mthd) and:[ matcher value: matchPrefix value: selector]]) ifTrue:[
                 | class skip |
 
                 class := mthd mclass superclass.
@@ -115,10 +149,11 @@
     selectors keysAndValuesDo: [:selector :classes|
         result add:(MethodPO 
                 name:selector
-                class:(classes size == 1 ifTrue:[classes anElement] ifFalse:[classes])).
+                class:(classes size == 1 ifTrue:[classes anElement] ifFalse:[classes])
+                stripOff: stripoffPrefix)
     ]
 
-    "Created: / 02-04-2014 / 23:17:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 08-04-2014 / 21:34:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompletionEngine methodsFor:'completion-private'!