Skip to content

Commit 9eb52e1

Browse files
author
Matthew McGarvey
committed
provide accurate completions when triggered from the middle of an instance method
1 parent 2f7d008 commit 9eb52e1

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/main/kotlin/org/javacs/kt/completion/Completions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ private fun completableElement(file: CompiledFile, cursor: Int): KtElement? {
104104
el as? KtQualifiedExpression ?: el.parent as? KtQualifiedExpression ?:
105105
// something::?
106106
el as? KtCallableReferenceExpression ?: el.parent as? KtCallableReferenceExpression ?:
107+
// something.foo() with cursor in the method
108+
el.parent?.parent as? KtQualifiedExpression ?:
107109
// ?
108110
el as? KtNameReferenceExpression
109111
}

src/test/kotlin/org/javacs/kt/CompletionsTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ class InstanceMemberTest : SingleFileTestFixture("completions", "InstanceMember.
5656
assertThat(labels, hasItem(startsWith("findFunctionReference")))
5757
assertThat(labels, not(hasItem("instanceFoo")))
5858
}
59+
60+
@Test fun `find completions on letters of method call`() {
61+
val completions = languageServer.textDocumentService.completion(completionParams(file, 26, 26)).get().right!!
62+
val labels = completions.items.map { it.label }
63+
64+
assertThat(labels, hasItems(startsWith("instanceFee"), startsWith("instanceFoo")))
65+
}
5966
}
6067

6168
class InstanceMembersJava : SingleFileTestFixture("completions", "InstanceMembersJava.kt") {

src/test/resources/completions/InstanceMember.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ private fun completeIdentifierInsideCall() {
2222
instance.instanceFoo(f)
2323
}
2424

25+
private fun findCompletionsForLettersInFullMethod() {
26+
SomeClass().instanceFoo()
27+
}
28+
2529
private class SomeClass {
2630
fun instanceFoo() = "Foo"
31+
fun instanceFee() = "Fee"
2732
private fun privateInstanceFoo() = "Foo"
2833
var fooVar = 1
2934
}
3035

31-
private fun SomeClass.extensionFoo() = "Bar"
36+
private fun SomeClass.extensionFoo() = "Bar"

0 commit comments

Comments
 (0)