[CodeCompletion] Always print argument ':' in filterName

In annotated results.

rdar://124667867
This commit is contained in:
Rintaro Ishizaki
2024-04-05 17:07:48 -07:00
parent cbf9cb2734
commit 46cc32e9a4
5 changed files with 63 additions and 54 deletions

View File

@@ -234,60 +234,58 @@ void CodeCompletionResultBuilder::setAssociatedDecl(const Decl *D) {
void CodeCompletionResultBuilder::addCallArgument(
Identifier Name, Identifier LocalName, Type Ty, Type ContextTy,
bool IsVarArg, bool IsInOut, bool IsIUO, bool IsAutoClosure,
bool UseUnderscoreLabel, bool IsLabeledTrailingClosure, bool HasDefault) {
bool IsLabeledTrailingClosure, bool IsForOperator, bool HasDefault) {
++CurrentNestingLevel;
using ChunkKind = CodeCompletionString::Chunk::ChunkKind;
addSimpleChunk(ChunkKind::CallArgumentBegin);
if (shouldAnnotateResults()) {
if (!Name.empty() || !LocalName.empty()) {
llvm::SmallString<16> EscapedKeyword;
if (!Name.empty()) {
addChunkWithText(
CodeCompletionString::Chunk::ChunkKind::CallArgumentName,
escapeKeyword(Name.str(), false, EscapedKeyword));
if (!LocalName.empty() && Name != LocalName) {
addChunkWithTextNoCopy(ChunkKind::Text, " ");
getLastChunk().setIsAnnotation();
addChunkWithText(
ChunkKind::CallArgumentInternalName,
escapeKeyword(LocalName.str(), false, EscapedKeyword));
getLastChunk().setIsAnnotation();
}
} else {
assert(!LocalName.empty());
addChunkWithTextNoCopy(ChunkKind::CallArgumentName, "_");
getLastChunk().setIsAnnotation();
llvm::SmallString<16> EscapedKeyword;
if (!Name.empty()) {
addChunkWithText(ChunkKind::CallArgumentName,
escapeKeyword(Name.str(), false, EscapedKeyword));
if (!LocalName.empty() && Name != LocalName) {
addChunkWithTextNoCopy(ChunkKind::Text, " ");
getLastChunk().setIsAnnotation();
addChunkWithText(ChunkKind::CallArgumentInternalName,
escapeKeyword(LocalName.str(), false, EscapedKeyword));
getLastChunk().setIsAnnotation();
}
addChunkWithTextNoCopy(ChunkKind::CallArgumentColon, ": ");
} else if (!LocalName.empty()) {
addChunkWithTextNoCopy(ChunkKind::CallArgumentName, "_");
getLastChunk().setIsAnnotation();
addChunkWithTextNoCopy(ChunkKind::Text, " ");
getLastChunk().setIsAnnotation();
addChunkWithText(ChunkKind::CallArgumentInternalName,
escapeKeyword(LocalName.str(), false, EscapedKeyword));
addChunkWithTextNoCopy(ChunkKind::CallArgumentColon, ": ");
} else if (!IsForOperator) {
addChunkWithTextNoCopy(ChunkKind::CallArgumentName, "_");
if (!IsLabeledTrailingClosure)
getLastChunk().setIsAnnotation();
addChunkWithTextNoCopy(ChunkKind::CallArgumentColon, ": ");
if (!IsLabeledTrailingClosure)
getLastChunk().setIsAnnotation();
}
} else {
llvm::SmallString<16> stash;
ChunkKind nameKind;
StringRef nameStr;
if (!Name.empty()) {
llvm::SmallString<16> EscapedKeyword;
addChunkWithText(CodeCompletionString::Chunk::ChunkKind::CallArgumentName,
escapeKeyword(Name.str(), false, EscapedKeyword));
addChunkWithTextNoCopy(
CodeCompletionString::Chunk::ChunkKind::CallArgumentColon, ": ");
} else if (UseUnderscoreLabel) {
addChunkWithTextNoCopy(
CodeCompletionString::Chunk::ChunkKind::CallArgumentName, "_");
addChunkWithTextNoCopy(
CodeCompletionString::Chunk::ChunkKind::CallArgumentColon, ": ");
nameKind = ChunkKind::CallArgumentName;
nameStr = escapeKeyword(Name.str(), false, stash);
} else if (IsLabeledTrailingClosure) {
nameKind = ChunkKind::CallArgumentName;
nameStr = "_";
} else if (!LocalName.empty()) {
// Use local (non-API) parameter name if we have nothing else.
llvm::SmallString<16> EscapedKeyword;
addChunkWithText(
CodeCompletionString::Chunk::ChunkKind::CallArgumentInternalName,
escapeKeyword(LocalName.str(), false, EscapedKeyword));
addChunkWithTextNoCopy(
CodeCompletionString::Chunk::ChunkKind::CallArgumentColon, ": ");
nameKind = ChunkKind::CallArgumentInternalName;
nameStr = escapeKeyword(LocalName.str(), false, stash);
}
if (!nameStr.empty()) {
addChunkWithText(nameKind, nameStr);
addChunkWithTextNoCopy(ChunkKind::CallArgumentColon, ": ");
}
}