[SourceKit] Make sure we reuse ASTContext in function bodies for solver-based cursor info

The main problem that prevented us from reusing the ASTContext was that we weren’t remapping the `LocToResolve` in the temporary buffer that only contains the re-parsed function back to the original buffer. Thus `NodeFinder` couldn’t find the node that we want to get cursor info for.

Getting AST reuse to work for top-level items is harder because it currently heavily relies on the `HasCodeCompletion` state being set on the parser result. I’ll try that in a follow-up PR.

rdar://103251263
This commit is contained in:
Alex Hoppen
2023-01-30 17:06:18 +01:00
parent ac3f9f85a0
commit a5f85ee10c
12 changed files with 257 additions and 30 deletions

View File

@@ -52,9 +52,11 @@ class ContextFinder : public SourceEntityWalker {
std::function<bool(ASTNode)> IsContext;
SmallVector<ASTNode, 4> AllContexts;
bool contains(ASTNode Enclosing) {
auto Result = SM.rangeContains(Enclosing.getSourceRange(), Target);
if (Result && IsContext(Enclosing))
auto Result = SM.rangeContainsRespectingReplacedRanges(
Enclosing.getSourceRange(), Target);
if (Result && IsContext(Enclosing)) {
AllContexts.push_back(Enclosing);
}
return Result;
}
public: