[NI] Provide diagnostics for candidates in "allCandidates" mode

This helps for completion as it use diagnostics to clip extra
 candidates
This commit is contained in:
Mikhail Zarechenskiy
2019-04-26 10:19:20 +03:00
parent 450bfed375
commit 5b33e54f77
3 changed files with 15 additions and 7 deletions
@@ -189,9 +189,12 @@ class PSICallResolver(
tracingStrategy: TracingStrategy tracingStrategy: TracingStrategy
): OverloadResolutionResults<D> { ): OverloadResolutionResults<D> {
if (result is AllCandidatesResolutionResult) { if (result is AllCandidatesResolutionResult) {
val resolvedCalls = result.allCandidates.map { val resolvedCalls = result.allCandidates.map { (candidate, diagnostics) ->
val resultingSubstitutor = it.getSystem().asReadOnlyStorage().buildResultingSubstitutor() val resultingSubstitutor = candidate.getSystem().asReadOnlyStorage().buildResultingSubstitutor()
kotlinToResolvedCallTransformer.transformToResolvedCall<D>(it.resolvedCall, null, resultingSubstitutor, result.diagnostics)
kotlinToResolvedCallTransformer.transformToResolvedCall<D>(
candidate.resolvedCall, null, resultingSubstitutor, diagnostics
)
} }
return AllCandidates(resolvedCalls) return AllCandidates(resolvedCalls)
@@ -58,8 +58,9 @@ class KotlinCallCompleter(
expectedType: UnwrappedType?, expectedType: UnwrappedType?,
resolutionCallbacks: KotlinResolutionCallbacks resolutionCallbacks: KotlinResolutionCallbacks
): CallResolutionResult { ): CallResolutionResult {
val diagnosticsHolder = KotlinDiagnosticsHolder.SimpleHolder() val completedCandidates = candidates.map { candidate ->
for (candidate in candidates) { val diagnosticsHolder = KotlinDiagnosticsHolder.SimpleHolder()
candidate.addExpectedTypeConstraint( candidate.addExpectedTypeConstraint(
candidate.returnTypeWithSmartCastInfo(resolutionCallbacks), expectedType, resolutionCallbacks candidate.returnTypeWithSmartCastInfo(resolutionCallbacks), expectedType, resolutionCallbacks
) )
@@ -72,8 +73,10 @@ class KotlinCallCompleter(
resolutionCallbacks, resolutionCallbacks,
collectAllCandidatesMode = true collectAllCandidatesMode = true
) )
CandidateWithDiagnostics(candidate, diagnosticsHolder.getDiagnostics() + candidate.diagnosticsFromResolutionParts)
} }
return AllCandidatesResolutionResult(candidates) return AllCandidatesResolutionResult(completedCandidates)
} }
private fun KotlinResolutionCandidate.runCompletion( private fun KotlinResolutionCandidate.runCompletion(
@@ -203,9 +203,11 @@ class ErrorCallResolutionResult(
) : SingleCallResolutionResult(resultCallAtom, diagnostics, constraintSystem) ) : SingleCallResolutionResult(resultCallAtom, diagnostics, constraintSystem)
class AllCandidatesResolutionResult( class AllCandidatesResolutionResult(
val allCandidates: Collection<KotlinResolutionCandidate> val allCandidates: Collection<CandidateWithDiagnostics>
) : CallResolutionResult(null, emptyList(), ConstraintStorage.Empty) ) : CallResolutionResult(null, emptyList(), ConstraintStorage.Empty)
data class CandidateWithDiagnostics(val candidate: KotlinResolutionCandidate, val diagnostics: List<KotlinCallDiagnostic>)
fun CallResolutionResult.resultCallAtom(): ResolvedCallAtom? = fun CallResolutionResult.resultCallAtom(): ResolvedCallAtom? =
if (this is SingleCallResolutionResult) resultCallAtom else null if (this is SingleCallResolutionResult) resultCallAtom else null