summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/ClangdServer.cpp
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2019-01-28 14:01:55 +0000
committerEric Liu <ioeric@google.com>2019-01-28 14:01:55 +0000
commitdd66277c36af442460c60dc993b41b831ee28973 (patch)
treea553ff33620d144f505a9b64f6bd0233727c6327 /clang-tools-extra/clangd/ClangdServer.cpp
parent6d5348cca557fe16675bdcafe504103c530f2aab (diff)
downloadbcm5719-llvm-dd66277c36af442460c60dc993b41b831ee28973.tar.gz
bcm5719-llvm-dd66277c36af442460c60dc993b41b831ee28973.zip
[clangd] Suggest adding missing includes for incomplete type diagnostics.
Summary: This enables clangd to intercept compiler diagnostics and attach fixes (e.g. by querying index). This patch adds missing includes for incomplete types e.g. member access into class with only forward declaration. This would allow adding missing includes for user-typed symbol names that are missing declarations (e.g. typos) in the future. Reviewers: sammccall Reviewed By: sammccall Subscribers: mgorny, ilya-biryukov, javed.absar, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D56903 llvm-svn: 352361
Diffstat (limited to 'clang-tools-extra/clangd/ClangdServer.cpp')
-rw-r--r--clang-tools-extra/clangd/ClangdServer.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 5f494210ac3..9b9eb10db0d 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -7,6 +7,7 @@
//===-------------------------------------------------------------------===//
#include "ClangdServer.h"
+#include "ClangdUnit.h"
#include "CodeComplete.h"
#include "FindSymbols.h"
#include "Headers.h"
@@ -106,6 +107,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
? new FileIndex(Opts.HeavyweightDynamicSymbolIndex)
: nullptr),
ClangTidyOptProvider(Opts.ClangTidyOptProvider),
+ SuggestMissingIncludes(Opts.SuggestMissingIncludes),
WorkspaceRoot(Opts.WorkspaceRoot),
PCHs(std::make_shared<PCHContainerOperations>()),
// Pass a callback into `WorkScheduler` to extract symbols from a newly
@@ -141,17 +143,22 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
WantDiagnostics WantDiags) {
- tidy::ClangTidyOptions Options = tidy::ClangTidyOptions::getDefaults();
+ ParseOptions Opts;
+ Opts.ClangTidyOpts = tidy::ClangTidyOptions::getDefaults();
if (ClangTidyOptProvider)
- Options = ClangTidyOptProvider->getOptions(File);
+ Opts.ClangTidyOpts = ClangTidyOptProvider->getOptions(File);
+ Opts.SuggestMissingIncludes = SuggestMissingIncludes;
// FIXME: some build systems like Bazel will take time to preparing
// environment to build the file, it would be nice if we could emit a
// "PreparingBuild" status to inform users, it is non-trivial given the
// current implementation.
- WorkScheduler.update(File, ParseInputs{getCompileCommand(File),
- FSProvider.getFileSystem(),
- Contents.str(), Options},
- WantDiags);
+ ParseInputs Inputs;
+ Inputs.CompileCommand = getCompileCommand(File);
+ Inputs.FS = FSProvider.getFileSystem();
+ Inputs.Contents = Contents;
+ Inputs.Opts = std::move(Opts);
+ Inputs.Index = Index;
+ WorkScheduler.update(File, Inputs, WantDiags);
}
void ClangdServer::removeDocument(PathRef File) { WorkScheduler.remove(File); }
OpenPOWER on IntegriCloud