@@ -126,9 +126,25 @@ object Reader {
126
126
}
127
127
object customCompletionMatcher extends CompletionMatcherImpl {
128
128
override def compile (options : util.Map [LineReader .Option , lang.Boolean ], prefix : Boolean , line : CompletingParsedLine , caseInsensitive : Boolean , errors : Int , originalGroupName : String ): Unit = {
129
- super .compile(options, prefix, line, caseInsensitive, errors, originalGroupName)
130
- // TODO Use Option.COMPLETION_MATCHER_TYPO(false) in once https://github.com/jline/jline3/pull/646
131
- matchers.remove(matchers.size() - 2 )
129
+ val errorsReduced = line.wordCursor() match {
130
+ case 0 | 1 | 2 | 3 => 0 // disable JLine's levenshtein-distance based typo matcher for short strings
131
+ case 4 | 5 => math.max(errors, 1 )
132
+ case _ => errors
133
+ }
134
+ super .compile(options, prefix, line, caseInsensitive, errorsReduced, originalGroupName)
135
+
136
+ // TODO JLINE All of this can/must be removed after the next JLine upgrade
137
+ matchers.remove(matchers.size() - 2 ) // remove ty
138
+ val wd = line.word();
139
+ val wdi = if (caseInsensitive) wd.toLowerCase() else wd
140
+ val typoMatcherWord = if (prefix) wdi.substring(0 , line.wordCursor()) else wdi
141
+ val fixedTypoMatcher = typoMatcher(
142
+ typoMatcherWord,
143
+ errorsReduced,
144
+ ! caseInsensitive, // Fixed in JLine https://github.com/jline/jline3/pull/647, remove the negation when upgrading!
145
+ originalGroupName
146
+ )
147
+ matchers.add(matchers.size - 2 , fixedTypoMatcher)
132
148
}
133
149
134
150
override def matches (candidates : JList [Candidate ]): JList [Candidate ] = {
@@ -350,12 +366,15 @@ class Completion(delegate: shell.Completion) extends shell.Completion with Compl
350
366
result.candidates.filter(_.name == parsedLineWord) match {
351
367
case Nil =>
352
368
case exacts =>
353
- lineReader.getTerminal.writer.println()
354
- for (cc <- exacts)
355
- lineReader.getTerminal.writer.println(cc.declString())
356
- lineReader.callWidget(LineReader .REDRAW_LINE )
357
- lineReader.callWidget(LineReader .REDISPLAY )
358
- lineReader.getTerminal.flush()
369
+ val declStrings = exacts.map(_.declString()).filterNot(_ == " " )
370
+ if (declStrings.nonEmpty) {
371
+ lineReader.getTerminal.writer.println()
372
+ for (declString <- declStrings)
373
+ lineReader.getTerminal.writer.println(declString)
374
+ lineReader.callWidget(LineReader .REDRAW_LINE )
375
+ lineReader.callWidget(LineReader .REDISPLAY )
376
+ lineReader.getTerminal.flush()
377
+ }
359
378
}
360
379
}
361
380
}
0 commit comments