Skip to content

[CodeCompletion] Annotated type name and 'IsSystem' #31738

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions include/swift/IDE/CodeCompletion.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ class CodeCompletionStringChunk {
/// This chunk should not be inserted into the editor buffer.
TypeAnnotation,

/// Structured group version of 'TypeAnnotation'.
/// This grouped chunks should not be inserted into the editor buffer.
TypeAnnotationBegin,

/// A brace statement -- left brace and right brace. The preferred
/// position to put the cursor after the completion result is inserted
/// into the editor buffer is between the braces.
Expand All @@ -195,7 +199,8 @@ class CodeCompletionStringChunk {
return Kind == ChunkKind::CallParameterBegin ||
Kind == ChunkKind::GenericParameterBegin ||
Kind == ChunkKind::OptionalBegin ||
Kind == ChunkKind::CallParameterTypeBegin;
Kind == ChunkKind::CallParameterTypeBegin ||
Kind == ChunkKind::TypeAnnotationBegin;
}

static bool chunkHasText(ChunkKind Kind) {
Expand Down Expand Up @@ -594,6 +599,7 @@ class CodeCompletionResult {
unsigned SemanticContext : 3;
unsigned NotRecommended : 1;
unsigned NotRecReason : 3;
unsigned IsSystem : 1;

/// The number of bytes to the left of the code completion point that
/// should be erased first if this completion string is inserted in the
Expand Down Expand Up @@ -634,6 +640,7 @@ class CodeCompletionResult {
assert(!isOperator() ||
getOperatorKind() != CodeCompletionOperatorKind::None);
AssociatedKind = 0;
IsSystem = 0;
}

/// Constructs a \c Keyword result.
Expand All @@ -651,6 +658,7 @@ class CodeCompletionResult {
TypeDistance(TypeDistance) {
assert(CompletionString);
AssociatedKind = static_cast<unsigned>(Kind);
IsSystem = 0;
}

/// Constructs a \c Literal result.
Expand All @@ -667,6 +675,7 @@ class CodeCompletionResult {
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
TypeDistance(TypeDistance) {
AssociatedKind = static_cast<unsigned>(LiteralKind);
IsSystem = 0;
assert(CompletionString);
}

Expand Down Expand Up @@ -694,6 +703,7 @@ class CodeCompletionResult {
TypeDistance(TypeDistance) {
assert(AssociatedDecl && "should have a decl");
AssociatedKind = unsigned(getCodeCompletionDeclKind(AssociatedDecl));
IsSystem = getDeclIsSystem(AssociatedDecl);
assert(CompletionString);
if (isOperator())
KnownOperatorKind =
Expand All @@ -706,8 +716,8 @@ class CodeCompletionResult {
CodeCompletionResult(SemanticContextKind SemanticContext,
unsigned NumBytesToErase,
CodeCompletionString *CompletionString,
CodeCompletionDeclKind DeclKind, StringRef ModuleName,
bool NotRecommended,
CodeCompletionDeclKind DeclKind, bool IsSystem,
StringRef ModuleName, bool NotRecommended,
CodeCompletionResult::NotRecommendedReason NotRecReason,
StringRef BriefDocComment,
ArrayRef<StringRef> AssociatedUSRs,
Expand All @@ -718,10 +728,10 @@ class CodeCompletionResult {
KnownOperatorKind(unsigned(KnownOperatorKind)),
SemanticContext(unsigned(SemanticContext)),
NotRecommended(NotRecommended), NotRecReason(NotRecReason),
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
ModuleName(ModuleName), BriefDocComment(BriefDocComment),
AssociatedUSRs(AssociatedUSRs), DocWords(DocWords),
TypeDistance(TypeDistance) {
IsSystem(IsSystem), NumBytesToErase(NumBytesToErase),
CompletionString(CompletionString), ModuleName(ModuleName),
BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
DocWords(DocWords), TypeDistance(TypeDistance) {
AssociatedKind = static_cast<unsigned>(DeclKind);
assert(CompletionString);
assert(!isOperator() ||
Expand Down Expand Up @@ -763,6 +773,10 @@ class CodeCompletionResult {
return static_cast<CodeCompletionOperatorKind>(KnownOperatorKind);
}

bool isSystem() const {
return static_cast<bool>(IsSystem);
}

ExpectedTypeRelation getExpectedTypeRelation() const {
return static_cast<ExpectedTypeRelation>(TypeDistance);
}
Expand Down Expand Up @@ -810,6 +824,7 @@ class CodeCompletionResult {
getCodeCompletionOperatorKind(StringRef name);
static CodeCompletionOperatorKind
getCodeCompletionOperatorKind(CodeCompletionString *str);
static bool getDeclIsSystem(const Decl *D);
};

struct CodeCompletionResultSink {
Expand Down Expand Up @@ -874,7 +889,7 @@ class CodeCompletionContext {
: Cache(Cache) {}

void setAnnotateResult(bool flag) { CurrentResults.annotateResult = flag; }
bool getAnnnoateResult() { return CurrentResults.annotateResult; }
bool getAnnotateResult() { return CurrentResults.annotateResult; }

/// Allocate a string owned by the code completion context.
StringRef copyString(StringRef Str);
Expand Down
7 changes: 7 additions & 0 deletions include/swift/IDE/CodeCompletionResultPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ void printCodeCompletionResultDescription(const CodeCompletionResult &Result,
void printCodeCompletionResultDescriptionAnnotated(
const CodeCompletionResult &Result, llvm::raw_ostream &OS,
bool leadingPunctuation);

void printCodeCompletionResultTypeName(
const CodeCompletionResult &Result, llvm::raw_ostream &OS);

void printCodeCompletionResultTypeNameAnnotated(
const CodeCompletionResult &Result, llvm::raw_ostream &OS);

} // namespace ide
} // namespace swift

Expand Down
Loading