diff options
| author | Eric Liu <ioeric@google.com> | 2018-09-03 10:18:21 +0000 |
|---|---|---|
| committer | Eric Liu <ioeric@google.com> | 2018-09-03 10:18:21 +0000 |
| commit | 83f63e42b2e15e4bc120253b9deae00a232a787d (patch) | |
| tree | a3dac7148c425a7d3c1172bd55faada327818b5c /clang-tools-extra/clangd/CodeComplete.h | |
| parent | 2e35c1e3992a8c49d9049d30edd22f5937e0408a (diff) | |
| download | bcm5719-llvm-83f63e42b2e15e4bc120253b9deae00a232a787d.tar.gz bcm5719-llvm-83f63e42b2e15e4bc120253b9deae00a232a787d.zip | |
[clangd] Support multiple #include headers in one symbol.
Summary:
Currently, a symbol can have only one #include header attached, which
might not work well if the symbol can be imported via different #includes depending
on where it's used. This patch stores multiple #include headers (with # references)
for each symbol, so that CodeCompletion can decide which include to insert.
In this patch, code completion simply picks the most popular include as the default inserted header. We also return all possible includes and their edits in the `CodeCompletion` results.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: mgrang, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51291
llvm-svn: 341304
Diffstat (limited to 'clang-tools-extra/clangd/CodeComplete.h')
| -rw-r--r-- | clang-tools-extra/clangd/CodeComplete.h | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/clang-tools-extra/clangd/CodeComplete.h b/clang-tools-extra/clangd/CodeComplete.h index 1785fb6a68e..3213acc7a31 100644 --- a/clang-tools-extra/clangd/CodeComplete.h +++ b/clang-tools-extra/clangd/CodeComplete.h @@ -26,6 +26,7 @@ #include "clang/Sema/CodeCompleteOptions.h" #include "clang/Tooling/CompilationDatabase.h" #include "llvm/ADT/Optional.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include <future> @@ -131,12 +132,20 @@ struct CodeCompletion { // Other fields should apply equally to all bundled completions. unsigned BundleSize = 1; SymbolOrigin Origin = SymbolOrigin::Unknown; - // The header through which this symbol could be included. - // Quoted string as expected by an #include directive, e.g. "<memory>". - // Empty for non-symbol completions, or when not known. - std::string Header; - // Present if Header is set and should be inserted to use this item. - llvm::Optional<TextEdit> HeaderInsertion; + + struct IncludeCandidate { + // The header through which this symbol could be included. + // Quoted string as expected by an #include directive, e.g. "<memory>". + // Empty for non-symbol completions, or when not known. + std::string Header; + // Present if Header should be inserted to use this item. + llvm::Optional<TextEdit> Insertion; + }; + // All possible include headers ranked by preference. By default, the first + // include is used. + // If we've bundled together overloads that have different sets of includes, + // thse includes may not be accurate for all of them. + llvm::SmallVector<IncludeCandidate, 1> Includes; /// Holds information about small corrections that needs to be done. Like /// converting '->' to '.' on member access. |

