From e09b42e2bc90bb5197a447acf24cdbe175b68f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BE=AA?= Date: Mon, 28 Oct 2024 17:46:05 +1300 Subject: [PATCH] save --- build.sbt | 2 +- .../src/main/scala/chester/cli/CLI.scala | 2 +- .../chester/utils/io/impl/DefaultIO.scala | 4 +- .../chester/utils/io/impl/DefaultIO.scala | 28 ++++++++------ .../main/scala/chester/syntax/core/Term.scala | 38 ++++++++++--------- .../src/main/scala/chester/utils/io/IO.scala | 6 ++- 6 files changed, 45 insertions(+), 35 deletions(-) diff --git a/build.sbt b/build.sbt index a254b364a..288c4eaa8 100644 --- a/build.sbt +++ b/build.sbt @@ -40,7 +40,7 @@ up := { log.warn(s"Directory ${dir.getName} does not exist, skipping") } } - + log.success("Finished updating all dependencies") } diff --git a/cli/shared/src/main/scala/chester/cli/CLI.scala b/cli/shared/src/main/scala/chester/cli/CLI.scala index 190478fda..891a3a618 100644 --- a/cli/shared/src/main/scala/chester/cli/CLI.scala +++ b/cli/shared/src/main/scala/chester/cli/CLI.scala @@ -216,7 +216,7 @@ class CLI[F[_]](using |}""".stripMargin def initializePackageJson(): F[Unit] = { for { - currentDir <- IO.pwd + currentDir <- IO.workingDir packageJsonPath = io.pathOps.join(currentDir, "package.json") _ <- IO.writeString(packageJsonPath, content(io.pathOps.baseName(currentDir))) _ <- IO.println("Initialized package.json in the current directory.") diff --git a/platform0/js/src/main/scala/chester/utils/io/impl/DefaultIO.scala b/platform0/js/src/main/scala/chester/utils/io/impl/DefaultIO.scala index 5f62df9b0..5ac2e0473 100644 --- a/platform0/js/src/main/scala/chester/utils/io/impl/DefaultIO.scala +++ b/platform0/js/src/main/scala/chester/utils/io/impl/DefaultIO.scala @@ -30,6 +30,8 @@ implicit object DefaultIO extends IO[Future] { inline override def println(x: String): Future[Unit] = Future.successful(Predef.println(x)) + override inline def ask(x: String): String = ??? + inline override def readString(path: String): Future[String] = fsPromisesMod.readFile(path, BufferEncoding.utf8) @@ -59,7 +61,7 @@ implicit object DefaultIO extends IO[Future] { false } - inline override def pwd: Future[String] = + inline override def workingDir: Future[String] = Future.successful(processMod.^.cwd()) inline override def getHomeDir: Future[String] = diff --git a/platform0/jvm-native/src/main/scala/chester/utils/io/impl/DefaultIO.scala b/platform0/jvm-native/src/main/scala/chester/utils/io/impl/DefaultIO.scala index 37a951fcb..0afcdd7a8 100644 --- a/platform0/jvm-native/src/main/scala/chester/utils/io/impl/DefaultIO.scala +++ b/platform0/jvm-native/src/main/scala/chester/utils/io/impl/DefaultIO.scala @@ -53,14 +53,18 @@ implicit object DefaultIO extends IO[Id] { override inline def pathOps = DefaultPathOps override inline def println(x: String): Unit = Predef.println(x) + override inline def ask(x: String): String = { + Predef.print(x) + scala.io.StdIn.readLine() + } - override def pwd: os.Path = os2.pwd + override def workingDir: os.Path = os2.pwd override inline def readString(path: Path): String = - os.read(path.resolveFrom(pwd)) + os.read(path.resolveFrom(workingDir)) override inline def read(path: Path): Array[Byte] = - os.read.bytes(path.resolveFrom(pwd)) + os.read.bytes(path.resolveFrom(workingDir)) override inline def writeString( path: Path, @@ -68,18 +72,18 @@ implicit object DefaultIO extends IO[Id] { append: Boolean = false ): Unit = { if (append) { - os.write.append(path.resolveFrom(pwd), content) + os.write.append(path.resolveFrom(workingDir), content) } else { - os.write(path.resolveFrom(pwd), content) + os.write(path.resolveFrom(workingDir), content) } } override inline def write(path: Path, content: Array[Byte]): Unit = { - os.write(path.resolveFrom(pwd), content) + os.write(path.resolveFrom(workingDir), content) } override inline def removeWhenExists(path: Path): Boolean = { - os.remove(path.resolveFrom(pwd), true) + os.remove(path.resolveFrom(workingDir), true) } override inline def getHomeDir: Path = FilePath( @@ -87,10 +91,10 @@ implicit object DefaultIO extends IO[Id] { ) override inline def exists(path: Path): Boolean = - os.exists(path.resolveFrom(pwd)) + os.exists(path.resolveFrom(workingDir)) override inline def createDirRecursiveIfNotExists(path: Path): Unit = { - os.makeDir.all(path.resolveFrom(pwd)) + os.makeDir.all(path.resolveFrom(workingDir)) } override inline def downloadToFile(url: String, path: Path): Unit = @@ -104,7 +108,7 @@ implicit object DefaultIO extends IO[Id] { Files.setPosixFilePermissions(path.toNIO, perms) } - override inline def getAbsolutePath(path: Path): Path = path.resolveFrom(pwd) + override inline def getAbsolutePath(path: Path): Path = path.resolveFrom(workingDir) @ifndef("scalaNativeForTermux") override inline def call(command: Seq[String]): CommandOutput = { @@ -119,10 +123,10 @@ implicit object DefaultIO extends IO[Id] { } override def listFiles(path: Path): Id[Seq[Path]] = { - os.list(path.resolveFrom(pwd)) + os.list(path.resolveFrom(workingDir)) } override def isDirectory(path: Path): Id[Boolean] = { - os.isDir(path.resolveFrom(pwd)) + os.isDir(path.resolveFrom(workingDir)) } } diff --git a/syntax/src/main/scala/chester/syntax/core/Term.scala b/syntax/src/main/scala/chester/syntax/core/Term.scala index d95642308..9fcff0ea1 100644 --- a/syntax/src/main/scala/chester/syntax/core/Term.scala +++ b/syntax/src/main/scala/chester/syntax/core/Term.scala @@ -22,9 +22,9 @@ import scala.language.implicitConversions /* Type Hierarchy Naming Conventions: * * The codebase follows these suffix patterns: - * + * * - *C (e.g. LocalVC): Abstract "case class-like" traits that define the structure and behavior - * for a specific term type. These contain the common fields and methods that will be + * for a specific term type. These contain the common fields and methods that will be * implemented by concrete case classes. * * - *F (e.g. LocalVF): Function interfaces used for constructing terms. These define @@ -999,8 +999,8 @@ case class Function( @deprecated("not used") case class MatchingClause(meta: OptionTermMeta) extends WHNF { - override type ThisTree = MatchingClause - override def descent(f: Term => Term, g: TreeMap[Term]): MatchingClause = this + override type ThisTree = MatchingClause + override def descent(f: Term => Term, g: TreeMap[Term]): MatchingClause = this override def toDoc(using options: PrettierOptions): Doc = toString // TODO } @@ -2023,15 +2023,15 @@ trait ObjectCallTermC[Rec <: TermT[Rec]] extends UnevalT[Rec] { override type ThisTree <: ObjectCallTermC[Rec] def objectRef: Rec def cons: ObjectCallTermF[Rec, ThisTree] - + override def toTerm: ObjectCallTerm = ObjectCallTerm(objectRef.toTerm, meta) - + override def toDoc(using options: PrettierOptions): Doc = group("ObjectCall" <+> objectRef.toDoc) - + def cpy(objectRef: Rec = objectRef, meta: OptionTermMeta = meta): ThisTree = cons.apply(objectRef, meta) - + def descent(f: Rec => Rec, g: TreeMap[Rec]): Rec = thisOr( cpy(objectRef = f(objectRef)) ) @@ -2040,10 +2040,11 @@ trait ObjectCallTermC[Rec <: TermT[Rec]] extends UnevalT[Rec] { case class ObjectCallTerm( objectRef: Term, meta: OptionTermMeta -) extends Uneval with ObjectCallTermC[Term] { +) extends Uneval + with ObjectCallTermC[Term] { override type ThisTree = ObjectCallTerm override def cons: ObjectCallTermF[Term, ThisTree] = this.copy - + override def descent(f: Term => Term, g: TreeMap[Term]): ObjectCallTerm = thisOr( copy(objectRef = f(objectRef)) ) @@ -2051,22 +2052,22 @@ case class ObjectCallTerm( @FunctionalInterface trait ObjectTypeTermF[Rec <: TermT[Rec], ThisTree <: ObjectTypeTermC[Rec]] { - def apply(objectDef: ObjectStmtTerm, meta: OptionTermMeta): ThisTree + def apply(objectDef: ObjectStmtTerm, meta: OptionTermMeta): ThisTree } trait ObjectTypeTermC[Rec <: TermT[Rec]] extends TypeTermT[Rec] { override type ThisTree <: ObjectTypeTermC[Rec] def objectDef: ObjectStmtTerm def cons: ObjectTypeTermF[Rec, ThisTree] - + override def toTerm: ObjectTypeTerm = ObjectTypeTerm(objectDef, meta) - + override def toDoc(using options: PrettierOptions): Doc = Doc.text("ObjectType(") <> objectDef.name.toDoc <> Doc.text(")") - + def cpy(objectDef: ObjectStmtTerm = objectDef, meta: OptionTermMeta = meta): ThisTree = cons.apply(objectDef, meta) - + def descent(f: Rec => Rec, g: TreeMap[Rec]): Rec = thisOr( cpy(objectDef = g(objectDef)) ) @@ -2075,10 +2076,11 @@ trait ObjectTypeTermC[Rec <: TermT[Rec]] extends TypeTermT[Rec] { case class ObjectTypeTerm( objectDef: ObjectStmtTerm, meta: OptionTermMeta -) extends TypeTerm with ObjectTypeTermC[Term] { +) extends TypeTerm + with ObjectTypeTermC[Term] { override type ThisTree = ObjectTypeTerm override def cons: ObjectTypeTermF[Term, ThisTree] = this.copy - + override def descent(f: Term => Term, g: TreeMap[Term]): ObjectTypeTerm = thisOr( copy(objectDef = g(objectDef)) ) @@ -2186,4 +2188,4 @@ object NodeKind { case object ObjectCallTerm extends ConcreteNodeKind case object ObjectTypeTerm extends ConcreteNodeKind case object ObjectStmtTerm extends ConcreteNodeKind -} \ No newline at end of file +} diff --git a/utils/shared/src/main/scala/chester/utils/io/IO.scala b/utils/shared/src/main/scala/chester/utils/io/IO.scala index 813a87398..edf1475b4 100644 --- a/utils/shared/src/main/scala/chester/utils/io/IO.scala +++ b/utils/shared/src/main/scala/chester/utils/io/IO.scala @@ -24,11 +24,12 @@ implicit inline def summonPathOpsFromIO[F[_]](using trait IO[F[_]] { type Path - def pwd: F[Path] + def workingDir: F[Path] def pathOps: PathOps[Path] def println(x: String): F[Unit] + def ask(x: String): F[String] def readString(path: Path): F[String] @@ -84,7 +85,8 @@ object IO { } extension [F[_]](_io: IO.type)(using io: IO[F]) { - inline def pwd: F[io.Path] = io.pwd + inline def ask(inline x: String): F[String] = io.ask(x) + inline def workingDir: F[io.Path] = io.workingDir inline def readString(inline path: io.Path): F[String] = io.readString(path) inline def read(inline path: io.Path): F[Array[Byte]] = io.read(path) inline def writeString(