Skip to content

Commit

Permalink
bugfix: Infer correct build target for jars
Browse files Browse the repository at this point in the history
Previously, we would use fallback service for all jars, which would mean we would use Scala 3 there. Now, when jar filesystem is opened we correctly check which service might be using it.
  • Loading branch information
tgodzik committed May 27, 2024
1 parent a2e4569 commit b58e2a9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,14 @@ class WorkspaceLspService(

def getServiceForOpt(path: AbsolutePath): Option[ProjectMetalsLspService] =
getFolderForOpt(path, folderServices).orElse {
folderServices.find(
_.buildTargets.all
.exists(bt => bt.baseDirectoryPath.exists(path.startWith))
)
folderServices.find { service =>
if (path.isJarFileSystem) {
service.buildTargets.inferBuildTarget(path).nonEmpty
} else {
service.buildTargets.all
.exists(bt => bt.baseDirectoryPath.exists(path.startWith))
}
}
}

def getServiceFor(path: AbsolutePath): MetalsLspService =
Expand Down
3 changes: 2 additions & 1 deletion project/TestGroups.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ object TestGroups {
"tests.SkipCommentsSuite", "tests.JarSourcesProviderSuite",
"tests.inlayHints.InlayHintsHoverSuite", "tests.Java8Suite",
"tests.RequestRegistrySuite", "tests.inlayHints.InlayHintsExpectSuite",
"tests.worksheets.WorksheetInfiniteLoopSuite", "tests.TimeoutSuite"),
"tests.worksheets.WorksheetInfiniteLoopSuite", "tests.TimeoutSuite",
"tests.SingleFileSuite", "tests.SupportedScalaSuite"),
Set("tests.AmmoniteSuite", "tests.debug.BreakpointDapSuite",
"tests.OnTypeFormattingSuite", "tests.ReferenceLspSuite",
"tests.SuperMethodLspSuite", "tests.SyntaxErrorLspSuite",
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/src/test/scala/tests/HoverLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ class HoverLspSuite extends BaseLspSuite("hover-") with TestHovers {
} yield ()
}

test("dependency", withoutVirtualDocs = true) {
cleanWorkspace()
for {
_ <- initialize(
s"""
|/metals.json
|{
| "a": {
| "scalaVersion": "${V.scala213}",
| "libraryDependencies" : [ "org.scala-lang:scala-reflect:${V.scala213}"]
| }
|}
|/a/src/main/scala/Main.scala
|object Main {
| import scala.reflect.internal.Scopes
|}
|""".stripMargin
)
_ = client.messageRequests.clear()
_ <- server.didOpen("a/src/main/scala/Main.scala")
/* Scopes.scala from scala-reflect has unsupported Scala 3 syntax
* For Scala 2.13.x it should not show any diagnostics.
*
* workspaceDefinitions will open Scopes.scala and trigger diagnostics.
*/
_ = server.workspaceDefinitions
_ <- server.didOpen("scala/reflect/internal/Scopes.scala")
_ = assertNoDiagnostics()
} yield ()
}

test("basic-rambo".tag(FlakyWindows)) {
for {
_ <- initialize(
Expand Down

0 comments on commit b58e2a9

Please sign in to comment.