@@ -256,12 +256,14 @@ public List<Completion> completionsFor(final CompletionProvider provider, String
256256 JythonScriptParser .print ("codeWithoutLastLine:\n " + codeWithoutLastLine );
257257 }
258258 final DotAutocompletions da = JythonScriptParser .parseAST (code ).getLast ().find (varName , DotAutocompletions .EMPTY );
259+ final String fullPre = lastLine .substring (crop );
260+ final String pre = fullPre .substring (0 , fullPre .lastIndexOf (seed ));
259261 final String lowerCaseSeed = seed .toLowerCase ();
260262 List <Completion > list = da .get ().stream ()
261263 .filter (s -> s .getReplacementText ().toLowerCase ().contains (lowerCaseSeed ))
262- .map (s -> s .getCompletion (provider , lastLine . substring ( crop ) + s .getReplacementText (). substring ( seed . length () )))
264+ .map (s -> s .getCompletion (provider , pre + s .getReplacementText ()))
263265 .collect (Collectors .toList ());
264- sortCompletions (list , lowerCaseSeed );
266+ sortCompletions (list , seed );
265267 return list ;
266268 }
267269
@@ -275,7 +277,6 @@ private static String removeLastOptionalDot(final String s) {
275277 }
276278
277279 /**
278- * NB: Case-insensitive sorting
279280 * @param completions The list of completions
280281 * @param pre the text just before the current caret position that could
281282 * be the start of something auto-completable.
@@ -284,16 +285,17 @@ private void sortCompletions(final List<Completion> completions, final String pr
284285 Collections .sort (completions , new Comparator <Completion >() {
285286 int prefix1Index = Integer .MAX_VALUE ;
286287 int prefix2Index = Integer .MAX_VALUE ;
288+
287289 @ Override
288290 public int compare (final Completion o1 , final Completion o2 ) {
289291 prefix1Index = Integer .MAX_VALUE ;
290292 prefix2Index = Integer .MAX_VALUE ;
291- if (o1 .getReplacementText ().toLowerCase (). startsWith (pre ))
293+ if (o1 .getReplacementText ().startsWith (pre ))
292294 prefix1Index = 0 ;
293- if (o2 .getReplacementText ().toLowerCase (). startsWith (pre ))
295+ if (o2 .getReplacementText ().startsWith (pre ))
294296 prefix2Index = 0 ;
295297 if (prefix1Index == prefix2Index )
296- return o1 .compareTo (o2 );
298+ return o1 .getReplacementText (). compareTo (o2 . getReplacementText () );
297299 else
298300 return prefix1Index - prefix2Index ;
299301 }
0 commit comments