[CodeCompletion] Do not erase dot for code completion key path optiona root unwrapped members

This commit is contained in:
Luciano Almeida
2020-08-31 21:52:20 -03:00
parent b1db77adff
commit ecc5b90aa5
2 changed files with 61 additions and 2 deletions

View File

@@ -3725,8 +3725,12 @@ public:
llvm::SaveAndRestore<bool> ChangeNeedOptionalUnwrap(NeedOptionalUnwrap,
true);
if (DotLoc.isValid()) {
// Let's not erase the dot if the completion is after a swift key path
// root because \A?.?.member is the correct way to access wrapped type
// member from an optional key path root.
auto loc = IsAfterSwiftKeyPathRoot ? DotLoc.getAdvancedLoc(1) : DotLoc;
NumBytesToEraseForOptionalUnwrap = Ctx.SourceMgr.getByteDistance(
DotLoc, Ctx.SourceMgr.getCodeCompletionLoc());
loc, Ctx.SourceMgr.getCodeCompletionLoc());
} else {
NumBytesToEraseForOptionalUnwrap = 0;
}
@@ -5930,7 +5934,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
if (!OnRoot && KPE->getComponents().back().getKind() ==
KeyPathExpr::Component::Kind::OptionalWrap) {
// KeyPath expr with '?' (e.g. '\Ty.[0].prop?.another').
// Althogh expected type is optional, we should unwrap it because it's
// Although expected type is optional, we should unwrap it because it's
// unwrapped.
baseType = baseType->getOptionalObjectType();
}