Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Aug 22, 2023
1 parent af19ebc commit a0f5b24
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,10 @@ class WorkspaceLspService(
focusedDocument.foreach(recentlyFocusedFiles.add)
val uri = params.getTextDocument.getUri
val path = uri.toAbsolutePath
scribe.info(s"did open file: $path")
scribe.info(s"did open uri: $uri")
focusedDocument = Some(path)
scribe.info(s"found service: ${getServiceForOpt(path).map(_.path)}")
val service = getServiceForOpt(path)
.orElse {
if (path.isScalaFilename) {
scribe.info(s"or else is Scala file")
scribe.info(s"non Scala projects ${nonScalaProjects.map(_.path)}")
getFolderForOpt(path, nonScalaProjects)
.map(workspaceFolders.convertToScalaProject)
} else None
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/src/test/scala/tests/WorkspaceFoldersSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,48 @@ class WorkspaceFoldersSuite
)
} yield ()
}

test("non-scala-project") {
cleanWorkspace()
val newScalaFile = "/a/src/main/scala/A.scala"
for {
_ <- initialize(
Map(
"testFolder" ->
s"""|/metals.json
|{"a":{"scalaVersion" : ${V.scala213}}}
|/a/src/main/scala/a/A.scala
|package a
|case class MyObjectA()
|""".stripMargin,
"notYetScalaProject" ->
s"""|/README.md
|Will be a Scala project.
|""".stripMargin,
),
expectError = false,
)
_ = assert(server.fullServer.folderServices.length == 1)
_ = assert(server.fullServer.nonScalaProjects.length == 1)
_ = writeLayout(
s"""|$newScalaFile
|package a
|object O {
| val i: Int = "aaa"
|}
|""".stripMargin,
"notYetScalaProject",
)
_ <- server.didOpen(s"notYetScalaProject$newScalaFile")
_ = assert(server.fullServer.folderServices.length == 2)
_ = assertEquals(
server.client.pathDiagnostics(s"notYetScalaProject$newScalaFile"),
s"""|notYetScalaProject$newScalaFile:3:15: error: Found: ("aaa" : String)
|Required: Int
| val i: Int = "aaa"
| ^^^^^
|""".stripMargin,
)
} yield ()
}
}

0 comments on commit a0f5b24

Please sign in to comment.