diff --git a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/infrastructure/languageserver/ShutdownHookActivator.scala b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/infrastructure/languageserver/ShutdownHookActivator.scala index bb6aa2c99d05..e7e62603cbcc 100644 --- a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/infrastructure/languageserver/ShutdownHookActivator.scala +++ b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/infrastructure/languageserver/ShutdownHookActivator.scala @@ -36,8 +36,9 @@ class ShutdownHookActivator[F[+_, +_]: Exec: CovariantFlatMap] scheduled: List[UUID] = Nil ): Receive = { case RegisterShutdownHook(projectId, hook) => - val realHook = hook.asInstanceOf[ShutdownHook[F]] - val updated = hooks.updated(projectId, realHook :: hooks(projectId)) + val realHook = hook.asInstanceOf[ShutdownHook[F]] + val uniqueHooks = hooks(projectId).filter(!_.isSameKind(realHook)) + val updated = hooks.updated(projectId, realHook :: uniqueHooks) context.become(running(updated, scheduled)) case ProjectClosed(projectId) => diff --git a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/infrastructure/shutdown/ShutdownHook.scala b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/infrastructure/shutdown/ShutdownHook.scala index 030795f70c1b..74b4e7c15be5 100644 --- a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/infrastructure/shutdown/ShutdownHook.scala +++ b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/infrastructure/shutdown/ShutdownHook.scala @@ -9,4 +9,7 @@ trait ShutdownHook[F[+_, +_]] { */ def execute(): F[Nothing, Unit] + /** Checks if the provided `hook`` refers to the same kind of action as `this`` */ + def isSameKind(hook: ShutdownHook[F]): Boolean + } diff --git a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/MoveProjectDirCmd.scala b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/MoveProjectDirCmd.scala index 55d44606ca23..9c5e73583b8d 100644 --- a/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/MoveProjectDirCmd.scala +++ b/lib/scala/project-manager/src/main/scala/org/enso/projectmanager/service/MoveProjectDirCmd.scala @@ -47,4 +47,17 @@ class MoveProjectDirCmd[F[+_, +_]: CovariantFlatMap: ErrorChannel]( ) } + /** Returns the project ID to which this hook refers to */ + def getProjectId(): UUID = + projectId + + /** @inheritdoc */ + override def isSameKind(hook: ShutdownHook[F]): Boolean = { + hook match { + case cmd: MoveProjectDirCmd[_] => + projectId == cmd.getProjectId() + case _ => + false + } + } }