@@ -103,9 +103,25 @@ object Reader {
103
103
}
104
104
object customCompletionMatcher extends CompletionMatcherImpl {
105
105
override def compile (options : util.Map [LineReader .Option , lang.Boolean ], prefix : Boolean , line : CompletingParsedLine , caseInsensitive : Boolean , errors : Int , originalGroupName : String ): Unit = {
106
- super .compile(options, prefix, line, caseInsensitive, errors, originalGroupName)
107
- // TODO Use Option.COMPLETION_MATCHER_TYPO(false) in once https://github.com/jline/jline3/pull/646
108
- matchers.remove(matchers.size() - 2 )
106
+ val errorsReduced = line.wordCursor() match {
107
+ case 0 | 1 | 2 | 3 => 0 // disable JLine's levenshtein-distance based typo matcher for short strings
108
+ case 4 | 5 => math.max(errors, 1 )
109
+ case _ => errors
110
+ }
111
+ super .compile(options, prefix, line, caseInsensitive, errorsReduced, originalGroupName)
112
+
113
+ // TODO JLINE All of this can/must be removed after the next JLine upgrade
114
+ matchers.remove(matchers.size() - 2 ) // remove ty
115
+ val wd = line.word();
116
+ val wdi = if (caseInsensitive) wd.toLowerCase() else wd
117
+ val typoMatcherWord = if (prefix) wdi.substring(0 , line.wordCursor()) else wdi
118
+ val fixedTypoMatcher = typoMatcher(
119
+ typoMatcherWord,
120
+ errorsReduced,
121
+ ! caseInsensitive, // Fixed in JLine https://github.com/jline/jline3/pull/647, remove the negation when upgrading!
122
+ originalGroupName
123
+ )
124
+ matchers.add(matchers.size - 2 , fixedTypoMatcher)
109
125
}
110
126
111
127
override def matches (candidates : JList [Candidate ]): JList [Candidate ] = {
@@ -323,12 +339,15 @@ class Completion(delegate: shell.Completion) extends shell.Completion with Compl
323
339
result.candidates.filter(_.name == parsedLineWord) match {
324
340
case Nil =>
325
341
case exacts =>
326
- lineReader.getTerminal.writer.println()
327
- for (cc <- exacts)
328
- lineReader.getTerminal.writer.println(cc.declString())
329
- lineReader.callWidget(LineReader .REDRAW_LINE )
330
- lineReader.callWidget(LineReader .REDISPLAY )
331
- lineReader.getTerminal.flush()
342
+ val declStrings = exacts.map(_.declString()).filterNot(_ == " " )
343
+ if (declStrings.nonEmpty) {
344
+ lineReader.getTerminal.writer.println()
345
+ for (declString <- declStrings)
346
+ lineReader.getTerminal.writer.println(declString)
347
+ lineReader.callWidget(LineReader .REDRAW_LINE )
348
+ lineReader.callWidget(LineReader .REDISPLAY )
349
+ lineReader.getTerminal.flush()
350
+ }
332
351
}
333
352
}
334
353
}
0 commit comments