Skip to content

Commit

Permalink
added support for envFile
Browse files Browse the repository at this point in the history
  • Loading branch information
NecroKote committed Aug 7, 2024
1 parent 468b192 commit cd54dc6
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,24 @@ class KotlinDebugAdapter(

var cwd = (args["cwd"] as? String).let { if(it.isNullOrBlank()) projectRoot else Paths.get(it) }

// Cast from com.google.gson.internal.LinkedTreeMap
@Suppress("UNCHECKED_CAST")
val env = args["env"] as? Map<String, String> ?: mapOf()
val env = mutableMapOf<String, String>().apply {
(args["envFile"] as? String)?.let { Paths.get(it) }?.let { envFile ->
envFile.toFile().readLines()
.map { it.trim() }
.filter { it.isNotBlank() && !it.startsWith("#") }
.forEach {
val (key, value) = it.split("=", limit = 2)
set(key, value)
}
}

// apply 'env' from launch request overriding contents of 'envFile'
args.get("env")?.let { env ->
// Cast from com.google.gson.internal.LinkedTreeMap
@Suppress("UNCHECKED_CAST")
putAll(env as Map<String, String>)
}
}.toMap()

setupCommonInitializationParams(args)

Expand Down

0 comments on commit cd54dc6

Please sign in to comment.