Skip to content

Commit

Permalink
RD-10698 runner crash report scala match error (#372)
Browse files Browse the repository at this point in the history
Fixed
  • Loading branch information
alexzerntev authored Mar 6, 2024
1 parent 61b6173 commit 3361c2d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,13 @@ trait LspDefinitionTest extends CompilerTestContext {
assert(goToDefinitionResponse.position.isEmpty)
}

test("RD-10698 crash fix") { _ =>
val code = """main(`1 + 2`: int) = let
| a = 1,
| a = 2
|in a""".stripMargin
val goToDefinitionResponse = goToDefinition(code, Pos(4, 4))
assert(goToDefinitionResponse.position.isEmpty)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ trait LspDotAutoCompleteTest extends CompilerTestContext {
assert(entries.length == 0)
}

test("RD-10698 crash fix") { _ =>
val code = """main(`1 + 2`: int) = let
| a = 1,
| a = 2
|in a""".stripMargin
val AutoCompleteResponse(entries) = dotAutoComplete(code, Pos(4, 5))
assert(entries.length == 0)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,21 @@ trait LspHoverTest extends CompilerTestContext {
assertResult("string")(tipe)
}

knownBug("RD-8323", "hover variable in the end of the code (RD-8323)") { _ =>
test("RD-8323 hover variable in the end of the code (RD-8323)") { _ =>
val code = """let c = 2
|in c""".stripMargin
val HoverResponse(Some(TypeCompletion(name, tipe))) = hover(code, Pos(2, 5))
val HoverResponse(Some(TypeCompletion(name, tipe))) = hover(code, Pos(2, 4))
name shouldBe "c"
tipe shouldBe "int"
}

test("RD-10698 crash fix") { _ =>
val code = """main(`1 + 2`: int) = let
| a = 1,
| a = 2
|in a""".stripMargin

val HoverResponse(Some(TypeCompletion(name, tipe))) = hover(code, Pos(4, 4))
assert(tipe == "error")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,13 @@ trait LspRenameTest extends CompilerTestContext {
assert(positions.length == 0)
}

test("RD-10698 crash fix") { _ =>
val code = """main(`1 + 2`: int) = let
| a = 1,
| a = 2
|in a""".stripMargin
val RenameResponse(positions) = rename(code, Pos(4, 4))
assert(positions.length == 2)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,16 @@ trait LspWordAutoCompleteTest extends CompilerTestContext {
assert(entries.length > 17)
}

test("RD-10698 crash fix") { _ =>
val AutoCompleteResponse(entries) = wordAutoComplete(
"""main(`1 + 2`: int) = let
| a = 1,
| a = 2
|in a""".stripMargin,
"",
Pos(4, 5)
)
assert(entries.length > 0)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,31 +150,42 @@ class CompilerLspService(
case _ => true
}
}
.map {
.flatMap {
case (idn, e) => e match {
case l: LetBindEntity => LetBindCompletion(
SourcePrettyPrinter.ident(idn),
SourcePrettyPrinter.format(analyzer.idnType(l.b.i))
case l: LetBindEntity => Some(
LetBindCompletion(
SourcePrettyPrinter.ident(idn),
SourcePrettyPrinter.format(analyzer.idnType(l.b.i))
)
)
case f: LetFunEntity => LetFunCompletion(
SourcePrettyPrinter.ident(idn),
SourcePrettyPrinter.format(analyzer.idnType(f.f.i))
case f: LetFunEntity => Some(
LetFunCompletion(
SourcePrettyPrinter.ident(idn),
SourcePrettyPrinter.format(analyzer.idnType(f.f.i))
)
)
case m: MethodEntity => LetFunCompletion(
SourcePrettyPrinter.ident(idn),
SourcePrettyPrinter.format(analyzer.idnType(m.d.i))
case m: MethodEntity => Some(
LetFunCompletion(
SourcePrettyPrinter.ident(idn),
SourcePrettyPrinter.format(analyzer.idnType(m.d.i))
)
)
case f: LetFunRecEntity => LetFunRecCompletion(
SourcePrettyPrinter.ident(idn),
SourcePrettyPrinter.format(analyzer.idnType(f.f.i))
case f: LetFunRecEntity => Some(
LetFunRecCompletion(
SourcePrettyPrinter.ident(idn),
SourcePrettyPrinter.format(analyzer.idnType(f.f.i))
)
)
case p: FunParamEntity => FunParamCompletion(
SourcePrettyPrinter.ident(idn),
SourcePrettyPrinter.format(analyzer.idnType(p.f.i))
case p: FunParamEntity => Some(
FunParamCompletion(
SourcePrettyPrinter.ident(idn),
SourcePrettyPrinter.format(analyzer.idnType(p.f.i))
)
)
case p: PackageEntity =>
val docs = p.p.docs
PackageCompletion(SourcePrettyPrinter.ident(idn), docs)
Some(PackageCompletion(SourcePrettyPrinter.ident(idn), docs))
case _ => None
}
}
}
Expand Down

0 comments on commit 3361c2d

Please sign in to comment.