Environment variable handling with metals debugger interation #492
Replies: 2 comments 1 reply
-
I have this in my dap.configurations.scala = {
{
type = "scala",
request = "launch",
name = "Run or Test Target",
metals = {
runType = "runOrTestFile",
envFile = ".env",
},
},
} Example of
If I need to run project form sbt I use a little alias e sbt run You can also take a look at https://direnv.net/ Also be careful and don't push this |
Beta Was this translation helpful? Give feedback.
-
This is not related to your question, sorry for the off-topic. But just wanted to mention that if you want per project configuration it may be dangerous to jut run everything in |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm experimenting with automatically loaded configurations and environment variables once a language server has been initialized. While I have this working wonderfully for C++ I do not get it working with Scala.
It would be cool if I could do project configuration like this because our Scala programs run in docker containers which utilize environment variables. But I do not want to clutter my neovim configuration with dozens of variables and debug configurations and this approach would allow me to check in the configuration for other colleagues to use as well.
Consider the following (partial) metals configuration:
Example projectconf.lua:
And finally a simple Scala program:
This works perfectly if I run it in a neovim terminal window with "sbt run" but it does not work with the dap integration. There the environment variables are not set!
My investigation revealed that indeed starting a debug session does not set the environment variables although a new jvm process is started for the debugee. Also setting environment variables via the configuration keys mentioned in the metals documentation does not work that way because it will only be loaded if the configuration happened before initializing the metals server. I'm suspecting that the environment variables present while metals was started are passed to the debugee but the newly set variables are not seen by the new process.
Edit: Manually restarting the metals server indeed fixes the issue but this is not a nice workflow :D
Does someone have an idea how to proceed here? Is there some way of forcing metals to read the environment on starting the debugger or something similar?
Beta Was this translation helpful? Give feedback.
All reactions