aboutsummaryrefslogtreecommitdiff
path: root/tools/CIndex/CIndexCodeCompletion.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-01-28 00:56:43 +0000
committerDouglas Gregor <dgregor@apple.com>2010-01-28 00:56:43 +0000
commit936ea3b590117d2cd73b1b92621d06c4a7edbe60 (patch)
treeee4ea2dfb9f2f52cf7a9ae8733db59ba557d2f63 /tools/CIndex/CIndexCodeCompletion.cpp
parentc7cbb9bf8e0bf8c3191ef0b782ec198c433d2a4e (diff)
Switch the remaining diagnostic printing in CIndex over to the
diagnostic callback mechanism, so all diagnostics now go through that callback. Also, eliminate the displayDiagnostics flag to clang_createIndex(), since it is no longer necessary: the client determines whether to display diagnostics or not. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94714 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/CIndex/CIndexCodeCompletion.cpp')
-rw-r--r--tools/CIndex/CIndexCodeCompletion.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/tools/CIndex/CIndexCodeCompletion.cpp b/tools/CIndex/CIndexCodeCompletion.cpp
index f3b60dc8b0..25b1417c97 100644
--- a/tools/CIndex/CIndexCodeCompletion.cpp
+++ b/tools/CIndex/CIndexCodeCompletion.cpp
@@ -13,6 +13,8 @@
//===----------------------------------------------------------------------===//
#include "CIndexer.h"
+#include "CIndexDiagnostic.h"
+#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -186,10 +188,19 @@ CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
struct CXUnsavedFile *unsaved_files,
const char *complete_filename,
unsigned complete_line,
- unsigned complete_column) {
+ unsigned complete_column,
+ CXDiagnosticCallback diag_callback,
+ CXClientData diag_client_data) {
// The indexer, which is mainly used to determine where diagnostics go.
CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
+ // Configure the diagnostics.
+ DiagnosticOptions DiagOpts;
+ llvm::OwningPtr<Diagnostic> Diags;
+ Diags.reset(CompilerInstance::createDiagnostics(DiagOpts, 0, 0));
+ CIndexDiagnosticClient DiagClient(diag_callback, diag_client_data);
+ Diags->setClient(&DiagClient);
+
// The set of temporary files that we've built.
std::vector<llvm::sys::Path> TemporaryFiles;
@@ -272,15 +283,16 @@ CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
/* secondsToWait */ 0,
/* memoryLimits */ 0, &ErrMsg);
- if (CXXIdx->getDisplayDiagnostics() && !ErrMsg.empty()) {
- llvm::errs() << "clang_codeComplete: " << ErrMsg
- << '\n' << "Arguments: \n";
+ if (!ErrMsg.empty()) {
+ std::string AllArgs;
for (std::vector<const char*>::iterator I = argv.begin(), E = argv.end();
- I!=E; ++I) {
+ I != E; ++I) {
+ AllArgs += ' ';
if (*I)
- llvm::errs() << ' ' << *I << '\n';
+ AllArgs += *I;
}
- llvm::errs() << '\n';
+
+ Diags->Report(diag::err_fe_clang) << AllArgs << ErrMsg;
}
// Parse the resulting source file to find code-completion results.
@@ -319,6 +331,8 @@ CXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
Results->Buffer = F;
}
+ // FIXME: Parse the (redirected) standard error to emit diagnostics.
+
for (unsigned i = 0, e = TemporaryFiles.size(); i != e; ++i)
TemporaryFiles[i].eraseFromDisk();