Skip to content

Commit fd0b611

Browse files
Add back hack for DeclPrinter (#1086)
In a previous PR, we decided to remove this workaround because we thought it was likely no longer necessary. It turns out it is necessary, because `DeclPrinter` contains a partial pattern match, leading to a `MatchError` when an unexpected symbol is encountered. Pending a proper fix, this adds back the hack.
1 parent ecba906 commit fd0b611

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

effekt/jvm/src/test/scala/effekt/LSPTests.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,24 @@ class LSPTests extends FunSuite {
19381938
}
19391939
}
19401940

1941+
test("Server does not crash on file with type variables") {
1942+
withClientAndServer { (client, server) =>
1943+
val source =
1944+
raw"""def foo[T]() = <>
1945+
|""".textDocument
1946+
1947+
val initializeParams = new InitializeParams()
1948+
val initializationOptions = """{"effekt": {"showHoles": true}}"""
1949+
initializeParams.setInitializationOptions(JsonParser.parseString(initializationOptions))
1950+
server.initialize(initializeParams).get()
1951+
val didOpenParams = new DidOpenTextDocumentParams()
1952+
didOpenParams.setTextDocument(source)
1953+
server.getTextDocumentService().didOpen(didOpenParams)
1954+
val receivedHoles = client.receivedHoles()
1955+
assertEquals(receivedHoles.length, 1)
1956+
}
1957+
}
1958+
19411959
// Text document DSL
19421960
//
19431961
//

effekt/shared/src/main/scala/effekt/Intelligence.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ trait Intelligence {
197197
})
198198
}
199199

200-
sorted.map((name, path, sym) => sym match {
201-
case sym: TypeSymbol => TypeBinding(path, name, origin, DeclPrinter(sym))
202-
case sym: ValueSymbol => TermBinding(path, name, origin, C.valueTypeOption(sym).map(t => pp"${t}"))
203-
case sym: BlockSymbol => TermBinding(path, name, origin, C.blockTypeOption(sym).map(t => pp"${t}"))
200+
sorted.flatMap((name, path, sym) => sym match {
201+
// TODO this is extremely hacky, printing is not defined for all types at the moment
202+
case sym: TypeSymbol => try { Some(TypeBinding(path, name, origin, DeclPrinter(sym))) } catch { case e => None }
203+
case sym: ValueSymbol => Some(TermBinding(path, name, origin, C.valueTypeOption(sym).map(t => pp"${t}")))
204+
case sym: BlockSymbol => Some(TermBinding(path, name, origin, C.blockTypeOption(sym).map(t => pp"${t}")))
204205
}).toList
205206

206207
def allSymbols(origin: String, bindings: Bindings, path: List[String] = Nil)(using C: Context): Array[(String, List[String], TypeSymbol | TermSymbol)] = {

0 commit comments

Comments
 (0)