Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metals sbt xdg specification #5796

Open
tgodzik opened this issue Oct 27, 2023 Discussed in #5775 · 9 comments
Open

metals sbt xdg specification #5796

tgodzik opened this issue Oct 27, 2023 Discussed in #5775 · 9 comments
Labels
bug Something that is making a piece of functionality unusable sbt Generic relation to sbt upstream-fix-needed Waiting on a fix upstream

Comments

@tgodzik
Copy link
Contributor

tgodzik commented Oct 27, 2023

Discussed in #5775

Originally posted by untainsYD October 21, 2023
When I import an sbt build in metals (Linux 6.5.8-arch1-1/VSCode), it creates a ~/.sbt folder in the home directory, ignoring the XDG specification. Even though I have set SBT_OPTS in .zprofile as follows, it is still being ignored:

export SBT_OPTS="$SBT_OPTS \
    -Dsbt.ivy.home=$XDG_CACHE_HOME/ivy \
    -Dsbt.boot.directory=$XDG_CACHE_HOME/sbt/boot \
    -Dsbt.preloaded=$XDG_CACHE_HOME/sbt/preloaded \
    -Dsbt.global.base=$XDG_CACHE_HOME/sbt \
    -Dsbt.global.staging=$XDG_CACHE_HOME/sbt/staging \
    -Dsbt.global.zinc=$XDG_CACHE_HOME/sbt/zinc \
    -Dsbt.dependency.base=$XDG_CACHE_HOME/sbt/dependency \
    -Dsbt.repository.config=$XDG_CONFIG_HOME/sbt/repositories \
    -Dsbt.global.settings=$XDG_CONFIG_HOME/sbt/global \
    -Dsbt.global.plugins=$XDG_CONFIG_HOME/sbt/plugins \
    -Dmaven.repo.local=$XDG_CACHE_HOME/maven/repository \
    -Divy.settings.dir=$XDG_CONFIG_HOME/ivy2 \
    -Divy.home=$XDG_CACHE_HOME/ivy2 \
    -Divy.cache.dir=$XDG_CACHE_HOME/ivy2/cache"

I have configured the Custom sbt launcher to propagate environment variables, but it doesn't seem to be effective.

> ls -lah ~/.sbt/boot
Permissions Size User      Group     Date Modified Name
drwxr-xr-x     - untainsYD untainsYD 21 Oct 23:27   scala-2.12.18
.rw-r--r--     0 untainsYD untainsYD 21 Oct 23:39   sbt.boot.lock
.rw-r--r--     0 untainsYD untainsYD 21 Oct 23:27   update.log

How can i force metals sbt to start the server in order to my SBT_OPTS?

@tgodzik tgodzik added this to Triage in Metals Issue Board via automation Oct 27, 2023
@untainsYD
Copy link

If you will need an sbt file or smth like that, just mention me.

@tgodzik tgodzik added sbt Generic relation to sbt bug Something that is making a piece of functionality unusable labels Nov 3, 2023
@kasiaMarek
Copy link
Contributor

kasiaMarek commented Dec 8, 2023

The issue seems to be the bsp config generated by sbt (.bsp/sbt.json). The args for starting the server are:

[some-path]/java -Xms100m -Xmx100m -classpath [some-path]/sbt-launch.jar -Dsbt.script=[some-path]/sbt xsbt.boot.Boot -bsp

Which will work if -Dsbt.boot.directory=... is added explicitly but won't pick up sbt opts. I feel like maybe sbt should pass those options when generating the config.

If one manually adds this option to args in .bsp/sbt.json it will work as expected, the problem is that sbt regenerates .bsp/sbt.json a lot, so this would have to be fixed constantly.

In metals we could insert such options when we start the sbt server, but that would work under the assumption that we know how the command for starting the server looks like, which is suboptimal, since metals should be oblivious to such things.

@tgodzik
Copy link
Contributor Author

tgodzik commented Dec 8, 2023

Shouldn't the environment variable work though? We start the process, so maybe we must make sure these variables are passed to sbt? We can suggest to restart if they changed.

@tgodzik
Copy link
Contributor Author

tgodzik commented Jan 17, 2024

It seems that it's not possible to fix this while launching via launcher, instead we should check if sbt is available on PATH and use it. For most advanced users it should be on the PATH.

Alternatively, you should be able to specify path to sbt by hand in the settings and it should work. (to be checked)

@kasiaMarek
Copy link
Contributor

@untainsYD did setting sbt script in metals settings actually solved the issue for you?

@kasiaMarek kasiaMarek moved this from To do to In progress in Metals Issue Board Jan 31, 2024
@kasiaMarek kasiaMarek added the needs more information Use if we need more information for a specific ticket label Feb 2, 2024
@kasiaMarek kasiaMarek removed this from In progress in Metals Issue Board Feb 2, 2024
Copy link

github-actions bot commented Mar 4, 2024

This issue was closed because no new information was added for the last 30 days. If you have any relevant information, feel free to add it and reopen the issue.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2024
@untainsYD
Copy link

@untainsYD did setting sbt script in metals settings actually solved the issue for you?

No, it didn't, i have sbt option set, but nothing changed
image

It always recreates ~/.sbt folder in home directory.
image

@tgodzik
Copy link
Contributor Author

tgodzik commented Mar 8, 2024

Looks like maybe the env variable is not forwarded to Metals. Might be useful to start VS Code using code command from console. We should be forwarding the environment variable correctly otherwise 🤔

@kasiaMarek
Copy link
Contributor

kasiaMarek commented Mar 13, 2024

I don't think it will work right now. So it seems that starting sbt server using.../java ... xsbt.boot.Boot -bsp causes .sbt to be created (one would have to pass Dsbt.boot.directory= arg to it). This command isn't generated by Metals but by sbt via sbt bspConfig command, so an upstream fix seems to be needed here. Here is the sbt issue sbt/sbt#7469.

@kasiaMarek kasiaMarek reopened this Mar 13, 2024
@kasiaMarek kasiaMarek added upstream-fix-needed Waiting on a fix upstream and removed needs more information Use if we need more information for a specific ticket labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is making a piece of functionality unusable sbt Generic relation to sbt upstream-fix-needed Waiting on a fix upstream
Projects
None yet
Development

No branches or pull requests

3 participants