diff options
author | Sam McCall <sam.mccall@gmail.com> | 2018-11-14 09:05:19 +0000 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2018-11-14 09:05:19 +0000 |
commit | 39e86fa5e49005898c47ca6b23bc465f65fe66c7 (patch) | |
tree | bd4e2d51217cfd472fd3400daf6a7fee107d4804 /clang-tools-extra/clangd/CodeCompletionStrings.cpp | |
parent | 2634bd599567842385e11d1fd70f5486c166f935 (diff) | |
download | bcm5719-llvm-39e86fa5e49005898c47ca6b23bc465f65fe66c7.tar.gz bcm5719-llvm-39e86fa5e49005898c47ca6b23bc465f65fe66c7.zip |
[clangd] Improve code completion for ObjC methods
Summary:
Previously code completion did not work well for Objective-C methods
which contained multiple arguments as clangd did not expect to see
multiple typed-text chunks when handling code completion.
Note that even with this change, we do not consider selector fragments
from previous arguments to be part of the signature (although we
could in the future).
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, jfb, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53934
llvm-svn: 346836
Diffstat (limited to 'clang-tools-extra/clangd/CodeCompletionStrings.cpp')
-rw-r--r-- | clang-tools-extra/clangd/CodeCompletionStrings.cpp | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/clang-tools-extra/clangd/CodeCompletionStrings.cpp b/clang-tools-extra/clangd/CodeCompletionStrings.cpp index 4381b437c2f..f7e31619dfa 100644 --- a/clang-tools-extra/clangd/CodeCompletionStrings.cpp +++ b/clang-tools-extra/clangd/CodeCompletionStrings.cpp @@ -76,6 +76,7 @@ std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) { void getSignature(const CodeCompletionString &CCS, std::string *Signature, std::string *Snippet, std::string *RequiredQualifiers) { unsigned ArgCount = 0; + bool HadObjCArguments = false; for (const auto &Chunk : CCS) { // Informative qualifier chunks only clutter completion results, skip // them. @@ -85,13 +86,36 @@ void getSignature(const CodeCompletionString &CCS, std::string *Signature, switch (Chunk.Kind) { case CodeCompletionString::CK_TypedText: // The typed-text chunk is the actual name. We don't record this chunk. - // In general our string looks like <qualifiers><name><signature>. - // So once we see the name, any text we recorded so far should be - // reclassified as qualifiers. - if (RequiredQualifiers) - *RequiredQualifiers = std::move(*Signature); - Signature->clear(); - Snippet->clear(); + // C++: + // In general our string looks like <qualifiers><name><signature>. + // So once we see the name, any text we recorded so far should be + // reclassified as qualifiers. + // + // Objective-C: + // Objective-C methods may have multiple typed-text chunks, so we must + // treat them carefully. For Objective-C methods, all typed-text chunks + // will end in ':' (unless there are no arguments, in which case we + // can safely treat them as C++). + if (!StringRef(Chunk.Text).endswith(":")) { // Treat as C++. + if (RequiredQualifiers) + *RequiredQualifiers = std::move(*Signature); + Signature->clear(); + Snippet->clear(); + } else { // Objective-C method with args. + // If this is the first TypedText to the Objective-C method, discard any + // text that we've previously seen (such as previous parameter selector, + // which will be marked as Informative text). + // + // TODO: Make previous parameters part of the signature for Objective-C + // methods. + if (!HadObjCArguments) { + HadObjCArguments = true; + Signature->clear(); + } else { // Subsequent argument, considered part of snippet/signature. + *Signature += Chunk.Text; + *Snippet += Chunk.Text; + } + } break; case CodeCompletionString::CK_Text: *Signature += Chunk.Text; |