Skip to content

Commit

Permalink
Merge pull request #423 from rberenguel/fix/camel_case_autocompletion
Browse files Browse the repository at this point in the history
Fix/camel case autocompletion
  • Loading branch information
jvican authored Apr 8, 2018
2 parents 3dd5562 + 52a62dc commit 684942e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions frontend/src/main/scala/bloop/cli/completion/Case.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package bloop.cli.completion

import caseapp.core.Arg
import caseapp.Name

object Case {
private val Kebab = "-([a-z])".r
private val Camel = "([A-Z])".r

private def camelToKebab(camel: String): String = {
val m = Camel.pattern.matcher(camel)
val sb = new StringBuffer
while (m.find()) {
m.appendReplacement(sb, "-" + m.group().toLowerCase())
}
m.appendTail(sb)
sb.toString
}

def kebabizeArg(arg: Arg): Arg = {
val kebabizedExtraNames = arg.extraNames.map((n: Name) => Name(camelToKebab(n.name)))
arg.copy(extraNames = kebabizedExtraNames)
}
}
4 changes: 2 additions & 2 deletions frontend/src/main/scala/bloop/engine/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import bloop.bsp.BspServer
import scala.annotation.tailrec
import bloop.cli.{BspProtocol, CliOptions, Commands, ExitStatus, ReporterKind}
import bloop.cli.CliParsers.CommandsMessages
import bloop.cli.completion.Mode
import bloop.cli.completion.{Case, Mode}
import bloop.io.SourceWatcher
import bloop.io.Timer.timed
import bloop.reporter.ReporterConfig
Expand Down Expand Up @@ -231,7 +231,7 @@ object Interpreter {
command <- cmd.command
message <- CommandsMessages.messages.toMap.get(command)
arg <- message.args
completion <- cmd.format.showArg(command, arg)
completion <- cmd.format.showArg(command, Case.kebabizeArg(arg))
} state.logger.info(completion)
case Mode.Reporters =>
for {
Expand Down

0 comments on commit 684942e

Please sign in to comment.