[REPL] Fix completion for function arguments

This commit is contained in:
Ilya Muradyan
2021-06-06 09:00:52 +03:00
parent 0bc34f0ff9
commit 8be5f009f1
2 changed files with 279 additions and 179 deletions
@@ -113,10 +113,13 @@ class ReplCompletionAndErrorsAnalysisTest : TestCase() {
fun testFunctionArgumentNames() = test {
run {
doCompile
code = """fun _sf(_someInt: Int = 42, _someString: String = "s") = 1"""
code = """
fun _sf(_someInt: Int = 42, _someString: String = "s") = 1
fun String.f(_bar: Int) = _bar
class C(val _xyz: Int)
""".trimIndent()
}
run {
doComplete
code = """_sf(_s"""
cursor = code.length
expect {
@@ -125,6 +128,38 @@ class ReplCompletionAndErrorsAnalysisTest : TestCase() {
addCompletion("_someString = ", "_someString", "String", "parameter")
}
}
run {
code = """ "my string".f(_b"""
cursor = code.length
expect {
addCompletion("_bar = ", "_bar", "Int", "parameter")
}
}
run {
code = "C(_x"
cursor = code.length
expect {
addCompletion("_xyz = ", "_xyz", "Int", "parameter")
}
}
}
@Test
fun testCompletionInsideFunctions() = test {
run {
val statement = "val a = _f"
code = """
fun dontCompleteMe(_foo: Int, bar: String) {
val _foo2 = ""
$statement
}
""".trimIndent()
cursor = code.indexOf(statement) + statement.length
expect {
addCompletion("_foo2", "_foo2", "String", "property")
addCompletion("_foo", "_foo", "Int", "parameter")
}
}
}
@Test