Skip to content

Commit 94b6285

Browse files
committed
Omit parentheses in method reference completions
Fix #146
1 parent efb8cd1 commit 94b6285

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ private val callPattern = Regex("(.*)\\((\\$\\d+)?\\)")
8383
private val methodSignature = Regex("""(?:fun|constructor) (?:<(?:[a-zA-Z\?\!\: ]+)(?:, [A-Z])*> )?([a-zA-Z]+\(.*\))""")
8484

8585
private fun completionItem(d: DeclarationDescriptor, surroundingElement: KtElement, file: CompiledFile, config: CompletionConfiguration): CompletionItem {
86-
val result = d.accept(RenderCompletionItem(config.snippets.enabled), null)
86+
val isMethodReference = surroundingElement is KtCallableReferenceExpression
87+
val renderWithSnippets = config.snippets.enabled && !isMethodReference
88+
val result = d.accept(RenderCompletionItem(renderWithSnippets), null)
8789

8890
result.label = methodSignature.find(result.detail)?.groupValues?.get(1) ?: result.label
8991

@@ -96,10 +98,6 @@ private fun completionItem(d: DeclarationDescriptor, surroundingElement: KtEleme
9698
result.filterText = name
9799
}
98100

99-
if (surroundingElement is KtCallableReferenceExpression && result.insertText.endsWith("()")) {
100-
result.insertText = result.insertText.removeSuffix("()")
101-
}
102-
103101
val matchCall = callPattern.matchEntire(result.insertText)
104102
if (file.lineAfter(surroundingElement.endOffset).startsWith("(") && matchCall != null) {
105103
result.insertText = matchCall.groups[1]!!.value

0 commit comments

Comments
 (0)