-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[IDE] Report ambiguous cursor info results #63613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IDE] Report ambiguous cursor info results #63613
Conversation
a5101fa
to
471a0e2
Compare
471a0e2
to
a9f0458
Compare
@swift-ci Please smoke test |
@swift-ci Please SourceKit stress test |
All stress tester failures are one of the following:
func foo(hex: String) {
// RUN: %sourcekitd-test -req=cursor -req-opts=retrieve_symbol_graph=1 -pos=%(line + 1):7 %s -- %s
hex.index
} |
addCursorInfoForDecl(Data, Result, AddRefactorings, AddSymbolGraph, | ||
Lang, Invoc, Diagnostic, /*PreviousSnaps=*/{}); | ||
} | ||
Data.DidReuseAST = Results->DidReuseAST; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be out of the loop.
Invoc, Diagnostic, /*PreviousSnaps=*/{}, | ||
Results->DidReuseAST, Receiver); | ||
CursorInfoData Data; | ||
for (auto ResolvedCursorInfo : Results.getResult().ResolvedCursorInfos) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we be consistent whether to use .getResults()
or operator->
?
(i.e. .getResult().ResolvedCursorInfos
vs ->DidReuseAST
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I completely forgot that I added operator->
lib/IDE/CursorInfo.cpp
Outdated
/// and thus the constraint system solution doesn't know about the | ||
/// \c UnresolvedDeclRefExpr. Instead, we find the expression to resolve in | ||
/// the source file again after expression pre-check has run. | ||
SourceFile &SrcFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be the decl context instead? That should be faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
a9f0458
to
ad932bd
Compare
@swift-ci Please smoke test |
lib/Sema/TypeCheckConstraints.cpp
Outdated
@@ -416,7 +416,11 @@ TypeChecker::typeCheckTarget(SolutionApplicationTarget &target, | |||
// Construct a constraint system from this expression. | |||
ConstraintSystemOptions csOptions = ConstraintSystemFlags::AllowFixes; | |||
|
|||
if (DiagnosticSuppression::isEnabled(Context.Diags)) | |||
/// If we have a SolutionCallback, we are inspecting constraint system | |||
/// solutions directly and thus also want to receive ambiguous solutions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually interesting because there could be a number of valid solutions produced by the solver and I'm guessing we don't really want to run salvage
in that case, right? It feels like this check needs to be embedded into the solver itself somehow...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean that we should just allow fixes straight away like we do for code completion?
I deliberately wanted to keep this as close to the normal type checking as possible (without all the code-completion specific rules of weaker filtering etc.) because if normal type checking reaches a single, definite result, we also want to report that as the single result for cursor info (for now). Also, in contrast to code completion, there is a reasonable chance that the code is in a valid state and thus it makes sense to run normal type-checking first and only salvage if we didn’t find a solution or the solutions were ambiguous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this check to ConstraintSystem::solve
now. Could you take another look at it?
ad932bd
to
13f47b6
Compare
@swift-ci Please smoke test |
@swift-ci Please SourceKit stress test |
13f47b6
to
36aa733
Compare
@swift-ci Please smoke test |
36aa733
to
cf26226
Compare
Data.AvailableActions.insert(Data.AvailableActions.end(), | ||
KnownRefactoringInfo.begin(), | ||
KnownRefactoringInfo.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be append(KnownRefactoringInfo.begin(), KnownRefactoringInfo.end())
, but I see the existing code used insert
.
This hooks up the cursor info infrastructure to be able to pass through multiple, ambiguous results. There are still minor issues that cause solver-based cursor info to not actually report the ambiguous results but those will be fixed in a follow-up PR.
cf26226
to
e5c521c
Compare
@swift-ci Please smoke test |
While we switched cursor info to solver-based I actually missed to return results in ambiguous cases. This PR fixes that oversight.