-
-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove pre Scala 3.0 final hacks, future proof some Scala 3 stuff (#1288
- Loading branch information
1 parent
f7e4c22
commit 4a9e698
Showing
7 changed files
with
83 additions
and
539 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
amm/compiler/src/main/scala-3.0.0-3.1.2/dotty/ammonite/compiler/AmmCompletionExtras.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package dotty.ammonite.compiler | ||
|
||
import dotty.tools.dotc.core.NameOps._ | ||
import dotty.tools.dotc.core.Names.{Name, termName} | ||
import dotty.tools.dotc.core.StdNames.nme | ||
import dotty.tools.dotc.interactive.Completion | ||
import dotty.tools.dotc.util.Chars.{isOperatorPart, isScalaLetter} | ||
|
||
trait AmmCompletionExtras { | ||
|
||
private val bslash = '\\' | ||
private val isDot = (x: Char) => x == '.' | ||
private val brackets = List('[',']','(',')','{','}') | ||
|
||
private def label(name: Name): String = { | ||
|
||
def maybeQuote(name: Name, recurse: Boolean): String = | ||
if (recurse && name.isTermName) | ||
name.asTermName.qualToString(maybeQuote(_, true), maybeQuote(_, false)) | ||
// initially adapted from | ||
// https://github.com/scala/scala/blob/decbd53f1bde4600c8ff860f30a79f028a8e431d/ | ||
// src/reflect/scala/reflect/internal/Printers.scala#L573-L584 | ||
else if (name == nme.CONSTRUCTOR) "this" | ||
else { | ||
val decName = name.decode.toString | ||
val hasSpecialChar = decName.exists { ch => | ||
brackets.contains(ch) || ch.isWhitespace || isDot(ch) | ||
} | ||
def isOperatorLike = (name.isOperatorName || decName.exists(isOperatorPart)) && | ||
decName.exists(isScalaLetter) && | ||
!decName.contains(bslash) | ||
lazy val term = name.toTermName | ||
|
||
val needsBackTicks = hasSpecialChar || | ||
isOperatorLike || | ||
nme.keywords(term) && term != nme.USCOREkw | ||
|
||
if (needsBackTicks) s"`$decName`" | ||
else decName | ||
} | ||
|
||
maybeQuote(name, true) | ||
} | ||
|
||
|
||
def maybeBackticked(input: String, hasBackTick: Boolean): Completion = | ||
Completion(label(termName(input)), "", Nil) | ||
def backtick(completion: Completion): Completion = | ||
if (completion.label.startsWith("`")) completion | ||
else completion.copy(label = label(termName(completion.label))) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
amm/compiler/src/main/scala-3.1.3+/dotty/ammonite/compiler/AmmCompletionExtras.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dotty.ammonite.compiler | ||
|
||
import dotty.tools.dotc.interactive.Completion | ||
|
||
trait AmmCompletionExtras { | ||
|
||
def maybeBackticked(input: String, hasBackTick: Boolean): Completion = | ||
Completion.backtickCompletions(Completion(input, "", Nil), hasBackTick) | ||
def backtick(completion: Completion): Completion = | ||
Completion.backtickCompletions(completion, completion.label.startsWith("`")) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.