From 6af2338ad489993184032dcb39aa6703ce98ee89 Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Thu, 29 Jul 2021 11:02:53 +0300 Subject: [PATCH] Return Project Name when Creating a Project (#1908) Add projectName field to the project/create result --- docs/language-server/protocol-project-manager.md | 3 ++- .../protocol/ProjectManagementApi.scala | 2 +- .../requesthandler/ProjectCreateHandler.scala | 4 ++-- .../enso/projectmanager/service/ProjectService.scala | 4 ++-- .../projectmanager/service/ProjectServiceApi.scala | 5 +++-- .../enso/projectmanager/ProjectManagementOps.scala | 7 +++++-- .../protocol/ProjectManagementApiSpec.scala | 12 +++++++++--- .../protocol/ProjectOpenSpecBase.scala | 4 ++-- 8 files changed, 26 insertions(+), 15 deletions(-) diff --git a/docs/language-server/protocol-project-manager.md b/docs/language-server/protocol-project-manager.md index 85c7aa71830..80a4cd2b704 100644 --- a/docs/language-server/protocol-project-manager.md +++ b/docs/language-server/protocol-project-manager.md @@ -362,8 +362,9 @@ interface ProjectCreateRequest { #### Result ```typescript -interface ProjectOpenResponse { +interface ProjectCreateResponse { projectId: UUID; + projectName: string; } ``` diff --git a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/protocol/ProjectManagementApi.scala b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/protocol/ProjectManagementApi.scala index 2a78e0cfbb8..ea0de6860f6 100644 --- a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/protocol/ProjectManagementApi.scala +++ b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/protocol/ProjectManagementApi.scala @@ -29,7 +29,7 @@ object ProjectManagementApi { missingComponentAction: Option[MissingComponentAction] ) - case class Result(projectId: UUID) + case class Result(projectId: UUID, projectName: String) implicit val hasParams = new HasParams[this.type] { type Params = ProjectCreate.Params diff --git a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/requesthandler/ProjectCreateHandler.scala b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/requesthandler/ProjectCreateHandler.scala index 8d9c7cd4a9b..a900aad7093 100644 --- a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/requesthandler/ProjectCreateHandler.scala +++ b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/requesthandler/ProjectCreateHandler.scala @@ -52,14 +52,14 @@ class ProjectCreateHandler[F[+_, +_]: Exec: CovariantFlatMap: ErrorChannel]( ) } _ = logger.trace(s"Creating project using engine $actualVersion") - projectId <- projectService.createUserProject( + project <- projectService.createUserProject( progressTracker = self, name = params.name, engineVersion = actualVersion, projectTemplate = params.projectTemplate, missingComponentAction = missingComponentAction ) - } yield ProjectCreate.Result(projectId) + } yield ProjectCreate.Result(project.id, project.name) } } diff --git a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/ProjectService.scala b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/ProjectService.scala index 9309e7b9413..44a7cdf996c 100644 --- a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/ProjectService.scala +++ b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/ProjectService.scala @@ -85,7 +85,7 @@ class ProjectService[ engineVersion: SemVer, projectTemplate: Option[String], missingComponentAction: MissingComponentAction - ): F[ProjectServiceFailure, UUID] = for { + ): F[ProjectServiceFailure, Project] = for { projectId <- gen.randomUUID() _ <- log.debug( "Creating project [{}, {}, {}].", @@ -131,7 +131,7 @@ class ProjectService[ .mapError(toServiceFailure) _ <- log.debug("Project [{}] updated in repository [{}].", projectId, repo) _ <- log.info("Project created [{}].", project) - } yield projectId + } yield project /** @inheritdoc */ override def deleteUserProject( diff --git a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/ProjectServiceApi.scala b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/ProjectServiceApi.scala index e36d87e6a79..5fdc410f7b9 100644 --- a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/ProjectServiceApi.scala +++ b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/ProjectServiceApi.scala @@ -9,6 +9,7 @@ import org.enso.projectmanager.data.{ ProjectMetadata, RunningLanguageServerInfo } +import org.enso.projectmanager.model.Project /** A contract for the Project Service. * @@ -23,7 +24,7 @@ trait ProjectServiceApi[F[+_, +_]] { * @param engineVersion Enso version to use for the new project * @param projectTemplate the name of the project template * @param missingComponentAction specifies how to handle missing components - * @return projectId + * @return project */ def createUserProject( progressTracker: ActorRef, @@ -31,7 +32,7 @@ trait ProjectServiceApi[F[+_, +_]] { engineVersion: SemVer, projectTemplate: Option[String], missingComponentAction: MissingComponentAction - ): F[ProjectServiceFailure, UUID] + ): F[ProjectServiceFailure, Project] /** Deletes a user project. * diff --git a/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/ProjectManagementOps.scala b/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/ProjectManagementOps.scala index 8ce75ca54a9..7b2a7c388e3 100644 --- a/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/ProjectManagementOps.scala +++ b/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/ProjectManagementOps.scala @@ -17,6 +17,7 @@ trait ProjectManagementOps { this: BaseServerSpec => def createProject( name: String, + nameSuffix: Option[Int] = None, projectTemplate: Option[String] = None, missingComponentAction: Option[MissingComponentAction] = None )(implicit client: WsTestClient): UUID = { @@ -37,13 +38,15 @@ trait ProjectManagementOps { this: BaseServerSpec => } """ client.send(request) - val projectId = getGeneratedUUID + val projectId = getGeneratedUUID + val projectName = nameSuffix.fold(name)(n => s"${name}_$n") client.expectJson(json""" { "jsonrpc":"2.0", "id":0, "result": { - "projectId": $projectId + "projectId": $projectId, + "projectName": $projectName } } """) diff --git a/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectManagementApiSpec.scala b/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectManagementApiSpec.scala index 0545cd2ac75..712c9252b15 100644 --- a/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectManagementApiSpec.scala +++ b/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectManagementApiSpec.scala @@ -129,7 +129,8 @@ class ProjectManagementApiSpec "jsonrpc" : "2.0", "id" : 1, "result" : { - "projectId" : $getGeneratedUUID + "projectId" : $getGeneratedUUID, + "projectName" : "Foo" } } """) @@ -213,7 +214,11 @@ class ProjectManagementApiSpec implicit val client = new WsTestClient(address) createProject(projectName, projectTemplate = Some("default")) - createProject(projectName, projectTemplate = Some("default")) + createProject( + projectName, + projectTemplate = Some("default"), + nameSuffix = Some(1) + ) val projectDir = new File(userProjectDir, "Foo_1") val packageFile = new File(projectDir, "package.yaml") @@ -238,7 +243,8 @@ class ProjectManagementApiSpec "jsonrpc" : "2.0", "id" : 1, "result" : { - "projectId" : $getGeneratedUUID + "projectId" : $getGeneratedUUID, + "projectName" : "Foo" } } """) diff --git a/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectOpenSpecBase.scala b/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectOpenSpecBase.scala index bd1d45d6f98..a87640821c4 100644 --- a/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectOpenSpecBase.scala +++ b/lib/scala/project-manager/src/test/scala/org/enso/projectmanager/protocol/ProjectOpenSpecBase.scala @@ -33,7 +33,7 @@ abstract class ProjectOpenSpecBase engineVersion = defaultVersion, missingComponentAction = MissingComponentAction.Fail ) - ordinaryProject = Runtime.default.unsafeRun(ordinaryAction) + ordinaryProject = Runtime.default.unsafeRun(ordinaryAction).id val brokenName = "Projbroken" val brokenAction = projectService.createUserProject( progressTracker = blackhole, @@ -42,7 +42,7 @@ abstract class ProjectOpenSpecBase engineVersion = defaultVersion, missingComponentAction = MissingComponentAction.Fail ) - brokenProject = Runtime.default.unsafeRun(brokenAction) + brokenProject = Runtime.default.unsafeRun(brokenAction).id // TODO [RW] this hack should not be necessary with #1273 val projectDir = new File(userProjectDir, brokenName)