From 459b2349ba3adc64adfdb2e71a503a739a07843b Mon Sep 17 00:00:00 2001 From: "Evgeniia.Fedotova" Date: Tue, 16 Jan 2024 22:21:40 +0100 Subject: [PATCH] add opportunity to call 'cd ..' -- change working directory to a parent directory --- .../api/models/fileSystemRelated/ChangeDirectory.kt | 5 ++++- .../research/ideFormerPlugin/api/models/utils/ApiUtils.kt | 1 + .../server/requests/fileSystemRelated/getChangeDirectory.kt | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ide-former-plugin/ide-core/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/api/models/fileSystemRelated/ChangeDirectory.kt b/ide-former-plugin/ide-core/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/api/models/fileSystemRelated/ChangeDirectory.kt index 556d826..9053e52 100644 --- a/ide-former-plugin/ide-core/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/api/models/fileSystemRelated/ChangeDirectory.kt +++ b/ide-former-plugin/ide-core/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/api/models/fileSystemRelated/ChangeDirectory.kt @@ -15,7 +15,10 @@ class ChangeDirectory( val currentProjectDirectory = ideStateKeeper.currentProjectDirectory currentProjectDirectory.refresh() - val targetDir = currentProjectDirectory.findSubdirectoryRecursively(targetDirectoryName) + val targetDir = when(targetDirectoryName) { + PARENT_DIRECTORY_NAME -> currentProjectDirectory.parentDirectory ?: error("No parent directory") + else -> currentProjectDirectory.findSubdirectoryRecursively(targetDirectoryName) + } previousDirectory = currentProjectDirectory ideStateKeeper.currentProjectDirectory = targetDir diff --git a/ide-former-plugin/ide-core/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/api/models/utils/ApiUtils.kt b/ide-former-plugin/ide-core/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/api/models/utils/ApiUtils.kt index d176958..4ce16de 100644 --- a/ide-former-plugin/ide-core/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/api/models/utils/ApiUtils.kt +++ b/ide-former-plugin/ide-core/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/api/models/utils/ApiUtils.kt @@ -6,6 +6,7 @@ import org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileClasses import org.jetbrains.research.ideFormerPlugin.api.models.fileRelated.fileFunctions.* const val DEFAULT_DIRECTORY_NAME = "." +const val PARENT_DIRECTORY_NAME = ".." const val UNCALLED_EXECUTE_BEFORE_RESULT_GETTING = "Execute() must be called before getting the result. The property storing the result has not been initialized yet" diff --git a/ide-former-plugin/ide-server/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/server/requests/fileSystemRelated/getChangeDirectory.kt b/ide-former-plugin/ide-server/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/server/requests/fileSystemRelated/getChangeDirectory.kt index ef89a79..ecfa3f1 100644 --- a/ide-former-plugin/ide-server/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/server/requests/fileSystemRelated/getChangeDirectory.kt +++ b/ide-former-plugin/ide-server/src/main/kotlin/org/jetbrains/research/ideFormerPlugin/server/requests/fileSystemRelated/getChangeDirectory.kt @@ -26,7 +26,7 @@ fun Routing.getChangeDirectory(logger: Logger, ideStateKeeper: IdeStateKeeper) { logger.info("Change directory api method was saved on the api methods stack") val response = targetDirName?.let { - "$PROJECT_DIR_WAS_CHANGED_TO $targetDirName." + "$PROJECT_DIR_WAS_CHANGED_TO '$targetDirName'." } ?: PROJECT_DIR_REMAINS_THE_SAME call.respondJson(response)