Metals: Incorrect entries for -P:semanticdb:targetroot in Test/scalacOptions

Created on 19 Nov 2020  Â·  5Comments  Â·  Source: scalameta/metals

Describe the bug

The Test/scalacOptions also contains the -P:semanticdb:targetroot of Compile/scalacOptions.

This will break source navigation in tests if the incorrect targetroot appears after the correct one. (I do not know how to reproduce this part but I have a project with 100+ subproject where this occurs.)

To Reproduce

Steps to reproduce the behavior:

  1. As a simple example project, you can clone https://github.com/asflierl/sglicko2 in the develop branch
  2. Add a project/metals.sbt containing addSbtPlugin("org.scalameta" % "sbt-metals" % "0.9.5")
  3. Run the SBT shell
  4. Look at the output of show Test / scalacOptions
sbt:sglicko2> show Test / scalacOptions
[info] * -unchecked
[info] * -deprecation
[info] * -language:_
[info] * -encoding
[info] * UTF-8
[info] * -Ybackend-parallelism
[info] * 16
[info] * -opt:l:inline
[info] * -opt-inline-from:sglicko2.**
[info] * -opt-warnings:_
[info] * -target:jvm-1.8
[info] * -Xplugin:/Users/cookies/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalameta/semanticdb-scalac_2.13.3/4.3.24/semanticdb-scalac_2.13.3-4.3.24.jar
[info] * -Yrangepos
[info] * -P:semanticdb:sourceroot:/Users/cookies/code/sglicko2
[info] * -P:semanticdb:targetroot:/Users/cookies/code/sglicko2/target/scala-2.13/meta
[info] * -P:semanticdb:synthetics:on
[info] * -P:semanticdb:failures:warning
[info] * -P:semanticdb:targetroot:/Users/cookies/code/sglicko2/target/scala-2.13/test-meta

Expected behavior

The line [info] * -P:semanticdb:targetroot:/Users/cookies/code/sglicko2/target/scala-2.13/meta should not be present.

Additional context

I suspect the problem might arise from Compile / semanticdbOptions already containing duplicate entries and a --= somewhere only removing the first occurrence:

sbt:sglicko2> show Compile / semanticdbOptions
[info] * -Yrangepos
[info] * -P:semanticdb:targetroot:/Users/cookies/code/sglicko2/target/scala-2.13/meta
[info] * -P:semanticdb:sourceroot:/Users/cookies/code/sglicko2
[info] * -P:semanticdb:targetroot:/Users/cookies/code/sglicko2/target/scala-2.13/meta
[info] * -Yrangepos
[info] * -P:semanticdb:synthetics:on
[info] * -P:semanticdb:failures:warning

similarly

sbt:sglicko2> show Test / semanticdbOptions
[info] * -Yrangepos
[info] * -P:semanticdb:sourceroot:/Users/cookies/code/sglicko2
[info] * -P:semanticdb:targetroot:/Users/cookies/code/sglicko2/target/scala-2.13/meta
[info] * -Yrangepos
[info] * -P:semanticdb:synthetics:on
[info] * -P:semanticdb:failures:warning
[info] * -P:semanticdb:targetroot:/Users/cookies/code/sglicko2/target/scala-2.13/test-meta
[info] * -P:semanticdb:sourceroot:/Users/cookies/code/sglicko2
[info] * -P:semanticdb:targetroot:/Users/cookies/code/sglicko2/target/scala-2.13/test-meta
[info] * -Yrangepos
[info] * -P:semanticdb:synthetics:on
[info] * -P:semanticdb:failures:warning

Thanks for your assistance.

bug sbt sbt server

All 5 comments

Thanks for the report @asflierl. This looks oddly familiar to https://github.com/scalameta/metals/issues/2189, which I had hoped fixed this issue, but it looks like not fully. I'll take a closer look.

FYI adding Compile / semanticdbOptions ~= (_.distinct) provides a temporary fix.

This issue can be closed I guess.

This issue can be closed I guess.

I believe this issue actually still exists. Did you take a look and see that it doesn't?

I was able to reproduce this issue today with Metals 0.9.7 (1.9.9, VS Code) and sbt v1.4.4

Was this page helpful?
0 / 5 - 0 ratings