Parser.st
changeset 1199 3ffc14d393a7
parent 1197 201542195f83
child 1200 aa96cdaf2780
--- a/Parser.st	Thu Oct 04 14:53:42 2001 +0200
+++ b/Parser.st	Thu Oct 04 16:19:46 2001 +0200
@@ -484,40 +484,9 @@
 
 !Parser class methodsFor:'error correction'!
 
-findBestSelectorsFor:aString
+findBest:nMax selectorsFor:aString in:aClassOrNil
     "collect known selectors with their spelling distances to aString;
-     return the 10 best suggestions"
-
-    |info n|
-
-    info := SortedCollection new.
-    info sortBlock:[:a :b | a value > b value].
-
-    n := 0.
-
-    Symbol allInstancesDo:[:sym |
-        |dist|
-
-        dist := aString spellAgainst:sym.
-        dist > 20 ifTrue:[
-            info add:(sym -> dist).
-            n := n + 1.
-            n > 10 ifTrue:[
-                info removeLast.
-            ]
-        ]
-    ].
-
-    ^ info asOrderedCollection collect:[:a | a key]
-
-    "Time millisecondsToRun:[Parser new findBestSelectorsFor:'foo']"
-    "Parser new findBestSelectorsFor:'findBestSel'"
-    "Parser new findBestSelectorsFor:'fildBestSelectrFr'"
-!
-
-findBestSelectorsFor:aString in:aClassOrNil
-    "collect known selectors with their spelling distances to aString;
-     return the 10 best suggestions. If the argument, aClassOrNil is not nil,
+     return the nMax best suggestions. If the argument, aClassOrNil is not nil,
      the message is assumed to be sent to instances of that class (i.e. offer
      corrections from that hierarchy only)"
 
@@ -536,11 +505,18 @@
         lcSym := sym asLowercase.
         (info contains:[:i | i key == sym]) ifFalse:[
             dist := lcSelector spellAgainst:lcSym.
+
+            (lcSym startsWith:lcSelector) ifTrue:[
+                dist := dist + (aString size * 10).
+            ].
+        
             (dist > 20 and:[mthd isObsolete not]) ifTrue:[
-                info add:(sym -> dist).
-                n := n + 1.
-                n > 10 ifTrue:[
-                    info removeLast.
+                (info contains:[:entry | entry key = sym]) ifFalse:[
+                    info add:(sym -> dist).
+                    n := n + 1.
+                    n > nMax ifTrue:[
+                        info removeLast.
+                    ]
                 ]
             ]
         ]
@@ -561,6 +537,28 @@
     ^ info asOrderedCollection collect:[:a | a key]
 
     "Modified: / 19.1.2000 / 16:43:37 / cg"
+!
+
+findBestSelectorsFor:aString
+    "collect known selectors with their spelling distances to aString;
+     return the 10 best suggestions"
+
+    ^ self findBestSelectorsFor:aString in:nil
+
+    "
+     Parser findBestSelectorsFor:'at'
+     Parser findBestSelectorsFor:'at:pu'
+    "
+!
+
+findBestSelectorsFor:aString in:aClassOrNil
+    "collect known selectors with their spelling distances to aString;
+     return the 10 best suggestions. If the argument, aClassOrNil is not nil,
+     the message is assumed to be sent to instances of that class (i.e. offer
+     corrections from that hierarchy only)"
+
+    ^ self
+        findBest:10 selectorsFor:aString in:aClassOrNil
 ! !
 
 !Parser class methodsFor:'evaluating expressions'!
@@ -5982,6 +5980,6 @@
 !Parser class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.303 2001-10-02 17:30:06 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.304 2001-10-04 14:19:46 cg Exp $'
 ! !
 Parser initialize!