diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-02-10 12:26:41 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-02-11 22:20:38 +1000 |
commit | 39a858de7a65b70ae35ce460e7746cae5e4d3fc4 (patch) | |
tree | 54aff920f4b150f0fe8bdd2d8eea7612ef7ffac3 /project/ParserUtil.scala | |
parent | 8f8f81b72ef07140952aeb76120bd032e35cc918 (diff) | |
download | scala-39a858de7a65b70ae35ce460e7746cae5e4d3fc4.tar.gz scala-39a858de7a65b70ae35ce460e7746cae5e4d3fc4.tar.bz2 scala-39a858de7a65b70ae35ce460e7746cae5e4d3fc4.zip |
Fix SBT tab completion of scala command
`scala -deprecation` (without a trailing script argument)
wasn't allowed. Now it is.
I also supported trailing whitespace on all commands.
Also fixed: a bug with completion of `scalac ./san<TAB>`.
It was completing as though the `./` had not been typed,
which threw the suggestion off by a few characters.
Diffstat (limited to 'project/ParserUtil.scala')
-rw-r--r-- | project/ParserUtil.scala | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/project/ParserUtil.scala b/project/ParserUtil.scala index f6658b146b..cdaf8831a5 100644 --- a/project/ParserUtil.scala +++ b/project/ParserUtil.scala @@ -9,41 +9,39 @@ object ParserUtil { p.map(x => x._1 + x._2) } - def EitherOr(a: Parser[String], b: Parser[String]): Parser[String] = { - a.flatMap[String] { - case "" => b - case x: String => - concat(Space.string ~ b).map[String]((s: String) => x + s) - } - } def Opt(a: Parser[String]) = a.?.map(_.getOrElse("")) val StringBasicNotStartingWithDash = notStartingWith(StringBasic, '-') val IsDirectoryFilter = new SimpleFileFilter(_.isDirectory) val JarOrDirectoryParser = FileParser(GlobFilter("*.jar") || IsDirectoryFilter) - def FileParser(filter: FileFilter, dirFilter: FileFilter = AllPassFilter, base: File = file(".")) = { + def FileParser(fileFilter: FileFilter, dirFilter: FileFilter = AllPassFilter, base: File = file(".")) = { def matching(prefix: String): List[String] = { val preFile = file(prefix) val cwd = base val parent = Option(preFile.getParentFile).getOrElse(cwd) if (preFile.exists) { if (preFile.isDirectory) { - preFile.*(IsDirectoryFilter.&&(dirFilter) || filter).get.map(_.getPath).toList + preFile.*(IsDirectoryFilter.&&(dirFilter) || fileFilter).get.map(_.getPath).toList } else { - List(preFile).filter(filter.accept).map(_.getPath) + List(preFile).filter(fileFilter.accept).map(_.getPath) } } else if (parent != null) { def ensureSuffix(s: String, suffix: String) = if (s.endsWith(suffix)) s else s + suffix - def pathOf(f: File): String = if (f.isDirectory && !filter.accept(f)) ensureSuffix(f.getPath, "/") else f.getPath - parent.*(GlobFilter(preFile.name + "*") && ((IsDirectoryFilter && dirFilter) || filter)).get.map(x => pathOf(if (parent == cwd) x.relativeTo(cwd).get else x)).toList + def pathOf(f: File): String = { + val f1 = if (preFile.getParentFile == null) f.relativeTo(cwd).getOrElse(f) else f + if (f1.isDirectory && !fileFilter.accept(f1)) ensureSuffix(f1.getPath, "/") else f1.getPath + } + val childFilter = GlobFilter(preFile.name + "*") && ((IsDirectoryFilter && dirFilter) || fileFilter) + val children = parent.*(childFilter).get + children.map(pathOf).toList } else Nil } def displayPath = Completions.single(Completion.displayOnly("<path>")) token(StringBasic, TokenCompletions.fixed((seen, level) => if (seen.isEmpty) displayPath else matching(seen) match { case Nil => displayPath case x :: Nil => - if (filter.accept(file(x))) + if (fileFilter.accept(file(x))) Completions.strict(Set(Completion.tokenDisplay(x.stripPrefix(seen), x))) else Completions.strict(Set(Completion.suggestion(x.stripPrefix(seen)))) |