Fixes issue #4 - Use levenshtein distance when computing prefix-based selector completion.
Levenshtein distance is used for all prefixes longer then 4 characters. The limit is set to 15.
--- a/SmallSense__CompletionController.st Tue Apr 01 18:01:57 2014 +0200
+++ b/SmallSense__CompletionController.st Wed Apr 02 23:42:42 2014 +0200
@@ -231,10 +231,11 @@
the complection window should be closed or false
if it shall be kept open."
- | matches word |
+ | prefix matcher matches |
- word := support wordBeforeCursor.
- matches := completionView list select:[:po | po stringToComplete startsWith: word ].
+ matcher := CompletionEngine matcher.
+ prefix := support wordBeforeCursor.
+ matches := completionView list select:[:po | matcher value: prefix value: po stringToComplete ].
matches notEmptyOrNil ifTrue:[
matches size == 1 ifTrue:[
completionView selection: matches anElement.
@@ -258,7 +259,7 @@
^ false.
"Created: / 27-09-2013 / 16:16:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified (format): / 18-01-2014 / 23:24:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 02-04-2014 / 23:32:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CompletionController methodsFor:'private-API'!
--- a/SmallSense__CompletionEngine.st Tue Apr 01 18:01:57 2014 +0200
+++ b/SmallSense__CompletionEngine.st Wed Apr 02 23:42:42 2014 +0200
@@ -10,6 +10,25 @@
!
+!CompletionEngine class methodsFor:'accessing'!
+
+matcher
+ "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: / 02-04-2014 / 23:30:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!CompletionEngine class methodsFor:'testing'!
isAbstract
@@ -56,6 +75,13 @@
!
addMethodsStartingWith: prefix filter: filterOrNil
+ ^ self addMethodsStartingWith: prefix filter: filterOrNil matcher: CompletionEngine 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>"
+!
+
+addMethodsStartingWith: prefix filter: filterOrNil matcher: matcher
| selectors filter |
selectors := Dictionary new.
@@ -63,7 +89,7 @@
Smalltalk allClassesDo:[:class|
class selectorsAndMethodsDo:[:selector :mthd |
- ((selector startsWith: prefix) and:[mthd isSynthetic not and:[filter value: mthd]]) ifTrue:[
+ (mthd isSynthetic not and:[(filter value: mthd) and:[ matcher value: prefix value: selector]]) ifTrue:[
| class skip |
class := mthd mclass superclass.
@@ -92,8 +118,7 @@
class:(classes size == 1 ifTrue:[classes anElement] ifFalse:[classes])).
]
- "Created: / 03-10-2013 / 17:56:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 22-10-2013 / 12:13:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 02-04-2014 / 23:17:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!CompletionEngine methodsFor:'completion-private'!