diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-09-08 23:32:56 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-09-08 23:32:56 +1000 |
commit | 0a8c4b263e979a7ed9fc9172ebc5f51e8093f3d5 (patch) | |
tree | 24e76f91257145c5ba34b4f4317ce03bb1cb81e1 /src/repl | |
parent | 3f1352f3ff16b0588b0f6e05bdb0a76b4702e431 (diff) | |
download | scala-0a8c4b263e979a7ed9fc9172ebc5f51e8093f3d5.tar.gz scala-0a8c4b263e979a7ed9fc9172ebc5f51e8093f3d5.tar.bz2 scala-0a8c4b263e979a7ed9fc9172ebc5f51e8093f3d5.zip |
Camel Case and JavaBean completion
This is just too useful to leave on the cutting room floor.
```
scala> classOf[String].enclo<TAB>
scala> classOf[String].getEnclosing
getEnclosingClass getEnclosingConstructor getEnclosingMethod
scala> classOf[String].simpl<TAB>
scala> classOf[String].getSimpleName
type X = global.TTWD<TAB>
scala> type X = global.TypeTreeWithDeferredRefCheck
```
I revised the API of `matchingResults` as it was clunky to reuse
the filtering on accessibility and term/type-ness while providing
a custom name matcher.
Diffstat (limited to 'src/repl')
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/PresentationCompilerCompleter.scala | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/PresentationCompilerCompleter.scala b/src/repl/scala/tools/nsc/interpreter/PresentationCompilerCompleter.scala index f6b6ff440b..7cff24cfa3 100644 --- a/src/repl/scala/tools/nsc/interpreter/PresentationCompilerCompleter.scala +++ b/src/repl/scala/tools/nsc/interpreter/PresentationCompilerCompleter.scala @@ -77,14 +77,23 @@ class PresentationCompilerCompleter(intp: IMain) extends Completion with ScalaCo val tabAfterCommonPrefixCompletion = lastCommonPrefixCompletion.contains(buf.substring(0, cursor)) && matching.exists(_.symNameDropLocal == r.name) val doubleTab = tabCount > 0 && matching.forall(_.symNameDropLocal == r.name) if (tabAfterCommonPrefixCompletion || doubleTab) defStringCandidates(matching, r.name) + else if (matching.isEmpty) { + // Lenient matching based on camel case and on eliding JavaBean "get" / "is" boilerplate + val camelMatches: List[Member] = r.matchingResults(CompletionResult.camelMatch(_)).filterNot(isInterpreterWrapperMember) + val memberCompletions = camelMatches.map(_.symNameDropLocal.decoded).distinct.sorted + def allowCompletion = ( + (memberCompletions.size == 1) + || CompletionResult.camelMatch(r.name)(r.name.newName(StringOps.longestCommonPrefix(memberCompletions))) + ) + if (memberCompletions.isEmpty) Completion.NoCandidates + else if (allowCompletion) Candidates(cursor + r.positionDelta, memberCompletions) + else Candidates(cursor, "" :: memberCompletions) + } else if (matching.nonEmpty && matching.forall(_.symNameDropLocal == r.name)) + Completion.NoCandidates // don't offer completion if the only option has been fully typed already else { - if (matching.nonEmpty && matching.forall(_.symNameDropLocal == r.name)) - Completion.NoCandidates // don't offer completion if the only option has been fully typed already - else { - // regular completion - val memberCompletions: List[String] = matching.map(_.symNameDropLocal.decoded).distinct.sorted - Candidates(cursor + r.positionDelta, memberCompletions) - } + // regular completion + val memberCompletions: List[String] = matching.map(_.symNameDropLocal.decoded).distinct.sorted + Candidates(cursor + r.positionDelta, memberCompletions) } } lastCommonPrefixCompletion = |