@@ -22,8 +22,8 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
22
22
import org.javacs.kt.LOG
23
23
24
24
fun fetchSignatureHelpAt (file : CompiledFile , cursor : Int ): SignatureHelp ? {
25
- val (signatures, activeDeclaration , activeParameter) = getSignatureTriplet(file, cursor) ? : return nullResult(" No call around ${file.describePosition(cursor)} " )
26
- return SignatureHelp (signatures, activeDeclaration , activeParameter)
25
+ val (signatures, activeSignature , activeParameter) = getSignatureTriplet(file, cursor) ? : return nullResult(" No call around ${file.describePosition(cursor)} " )
26
+ return SignatureHelp (signatures, activeSignature , activeParameter)
27
27
}
28
28
29
29
/* *
@@ -41,14 +41,18 @@ fun getDocString(file: CompiledFile, cursor: Int): String {
41
41
}
42
42
43
43
// TODO better function name?
44
- private fun getSignatureTriplet (file : CompiledFile , cursor : Int ): Triple <List <SignatureInformation >, Int, Int>? {
44
+ @Suppress(" ReturnCount" )
45
+ private fun getSignatureTriplet (file : CompiledFile , cursor : Int ): Triple <List <SignatureInformation >, Int?, Int?>? {
45
46
val call = file.parseAtPoint(cursor)?.findParent<KtCallExpression >() ? : return null
46
47
val candidates = candidates(call, file)
47
- val activeDeclaration = activeDeclaration(call, candidates)
48
+ if (candidates.isEmpty()) {
49
+ return null
50
+ }
51
+ val activeSignature = activeSignature(call, candidates)
48
52
val activeParameter = activeParameter(call, cursor)
49
53
val signatures = candidates.map(::toSignature)
50
54
51
- return Triple (signatures, activeDeclaration , activeParameter)
55
+ return Triple (signatures, activeSignature , activeParameter)
52
56
}
53
57
54
58
private fun getSignatures (file : CompiledFile , cursor : Int ): List <SignatureInformation >? {
@@ -97,8 +101,13 @@ private fun candidates(call: KtCallExpression, file: CompiledFile): List<Callabl
97
101
return emptyList()
98
102
}
99
103
100
- private fun activeDeclaration (call : KtCallExpression , candidates : List <CallableDescriptor >): Int {
101
- return candidates.indexOfFirst { isCompatibleWith(call, it) }
104
+ private fun activeSignature (call : KtCallExpression , candidates : List <CallableDescriptor >): Int? {
105
+ val activeIndex = candidates.indexOfFirst { isCompatibleWith(call, it) }
106
+ if (activeIndex < 0 ) {
107
+ LOG .warn(" No activeSignature found, omitting from SignatureHelp response." )
108
+ return null
109
+ }
110
+ return activeIndex
102
111
}
103
112
104
113
private fun isCompatibleWith (call : KtCallExpression , candidate : CallableDescriptor ): Boolean {
@@ -118,8 +127,9 @@ private fun isCompatibleWith(call: KtCallExpression, candidate: CallableDescript
118
127
return true
119
128
}
120
129
121
- private fun activeParameter (call : KtCallExpression , cursor : Int ): Int {
122
- val args = call.valueArgumentList ? : return - 1
130
+ @Suppress(" ReturnCount" )
131
+ private fun activeParameter (call : KtCallExpression , cursor : Int ): Int? {
132
+ val args = call.valueArgumentList ? : return null
123
133
val text = args.text
124
134
if (text.length == 2 )
125
135
return 0
0 commit comments