r320085 - [libclang] Record code-completion invocations to a temporary file when
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 7 12:37:50 PST 2017
Author: arphaman
Date: Thu Dec 7 12:37:50 2017
New Revision: 320085
URL: http://llvm.org/viewvc/llvm-project?rev=320085&view=rev
Log:
[libclang] Record code-completion invocations to a temporary file when
requested by client
This is a follow up to r319702 which records parsing invocations.
These files are not emitted by default, and the client has to specify the
invocation emission path first.
rdar://35322543
Added:
cfe/trunk/test/Index/record-completion-invocation.c
Modified:
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
cfe/trunk/tools/libclang/CIndexer.cpp
cfe/trunk/tools/libclang/CIndexer.h
cfe/trunk/tools/libclang/CXTranslationUnit.h
Added: cfe/trunk/test/Index/record-completion-invocation.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/record-completion-invocation.c?rev=320085&view=auto
==============================================================================
--- cfe/trunk/test/Index/record-completion-invocation.c (added)
+++ cfe/trunk/test/Index/record-completion-invocation.c Thu Dec 7 12:37:50 2017
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: env CINDEXTEST_INVOCATION_EMISSION_PATH=%t not c-index-test -code-completion-at=%s:10:1 "-remap-file=%s,%S/Inputs/record-parsing-invocation-remap.c" %s
+// RUN: cat %t/libclang-* | FileCheck %s
+
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: env LIBCLANG_DISABLE_CRASH_RECOVERY=1 CINDEXTEST_INVOCATION_EMISSION_PATH=%t not --crash c-index-test -code-completion-at=%s:10:1 "-remap-file=%s,%S/Inputs/record-parsing-invocation-remap.c" %s
+// RUN: cat %t/libclang-* | FileCheck %s
+
+// CHECK: {"toolchain":"{{.*}}","libclang.operation":"complete","libclang.opts":1,"args":["clang","-fno-spell-checking","{{.*}}record-completion-invocation.c","-Xclang","-detailed-preprocessing-record","-fallow-editor-placeholders"],"invocation-args":["-code-completion-at={{.*}}record-completion-invocation.c:10:1"],"unsaved_file_hashes":[{"name":"{{.*}}record-completion-invocation.c","md5":"aee23773de90e665992b48209351d70e"}]}
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=320085&r1=320084&r2=320085&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Dec 7 12:37:50 2017
@@ -2316,7 +2316,8 @@ int perform_code_completion(int argc, co
CXTranslationUnit TU;
unsigned I, Repeats = 1;
unsigned completionOptions = clang_defaultCodeCompleteOptions();
-
+ const char *InvocationPath;
+
if (getenv("CINDEXTEST_CODE_COMPLETE_PATTERNS"))
completionOptions |= CXCodeComplete_IncludeCodePatterns;
if (getenv("CINDEXTEST_COMPLETION_BRIEF_COMMENTS"))
@@ -2335,7 +2336,10 @@ int perform_code_completion(int argc, co
return -1;
CIdx = clang_createIndex(0, 0);
-
+ InvocationPath = getenv("CINDEXTEST_INVOCATION_EMISSION_PATH");
+ if (InvocationPath)
+ clang_CXIndex_setInvocationEmissionPathOption(CIdx, InvocationPath);
+
if (getenv("CINDEXTEST_EDITING"))
Repeats = 5;
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=320085&r1=320084&r2=320085&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Dec 7 12:37:50 2017
@@ -81,6 +81,8 @@ CXTranslationUnit cxtu::MakeCXTranslatio
D->Diagnostics = nullptr;
D->OverridenCursorsPool = createOverridenCXCursorsPool();
D->CommentToXML = nullptr;
+ D->ParsingOptions = 0;
+ D->Arguments = {};
return D;
}
@@ -3440,7 +3442,8 @@ clang_parseTranslationUnit_Impl(CXIndex
LibclangInvocationReporter InvocationReporter(
*CXXIdx, LibclangInvocationReporter::OperationKind::ParseOperation,
- options, llvm::makeArrayRef(*Args), unsaved_files);
+ options, llvm::makeArrayRef(*Args), /*InvocationArgs=*/None,
+ unsaved_files);
std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCommandLine(
Args->data(), Args->data() + Args->size(),
CXXIdx->getPCHContainerOperations(), Diags,
@@ -3467,7 +3470,14 @@ clang_parseTranslationUnit_Impl(CXIndex
return CXError_ASTReadError;
*out_TU = MakeCXTranslationUnit(CXXIdx, std::move(Unit));
- return *out_TU ? CXError_Success : CXError_Failure;
+ if (CXTranslationUnitImpl *TU = *out_TU) {
+ TU->ParsingOptions = options;
+ TU->Arguments.reserve(Args->size());
+ for (const char *Arg : *Args)
+ TU->Arguments.push_back(Arg);
+ return CXError_Success;
+ }
+ return CXError_Failure;
}
CXTranslationUnit
Modified: cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp?rev=320085&r1=320084&r2=320085&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp Thu Dec 7 12:37:50 2017
@@ -32,6 +32,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CrashRecoveryContext.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Timer.h"
@@ -691,6 +692,16 @@ clang_codeCompleteAt_Impl(CXTranslationU
CaptureCompletionResults Capture(Opts, *Results, &TU);
// Perform completion.
+ std::vector<const char *> CArgs;
+ for (const auto &Arg : TU->Arguments)
+ CArgs.push_back(Arg.c_str());
+ std::string CompletionInvocation =
+ llvm::formatv("-code-completion-at={0}:{1}:{2}", complete_filename,
+ complete_line, complete_column)
+ .str();
+ LibclangInvocationReporter InvocationReporter(
+ *CXXIdx, LibclangInvocationReporter::OperationKind::CompletionOperation,
+ TU->ParsingOptions, CArgs, CompletionInvocation, unsaved_files);
AST->CodeComplete(complete_filename, complete_line, complete_column,
RemappedFiles, (options & CXCodeComplete_IncludeMacros),
(options & CXCodeComplete_IncludeCodePatterns),
Modified: cfe/trunk/tools/libclang/CIndexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.cpp?rev=320085&r1=320084&r2=320085&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexer.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexer.cpp Thu Dec 7 12:37:50 2017
@@ -93,6 +93,7 @@ StringRef CIndexer::getClangToolchainPat
LibclangInvocationReporter::LibclangInvocationReporter(
CIndexer &Idx, OperationKind Op, unsigned ParseOptions,
llvm::ArrayRef<const char *> Args,
+ llvm::ArrayRef<std::string> InvocationArgs,
llvm::ArrayRef<CXUnsavedFile> UnsavedFiles) {
StringRef Path = Idx.getInvocationEmissionPath();
if (Path.empty())
@@ -127,6 +128,14 @@ LibclangInvocationReporter::LibclangInvo
OS << ',';
OS << '"' << I.value() << '"';
}
+ if (!InvocationArgs.empty()) {
+ OS << R"(],"invocation-args":[)";
+ for (const auto &I : llvm::enumerate(InvocationArgs)) {
+ if (I.index())
+ OS << ',';
+ OS << '"' << I.value() << '"';
+ }
+ }
if (!UnsavedFiles.empty()) {
OS << R"(],"unsaved_file_hashes":[)";
for (const auto &UF : llvm::enumerate(UnsavedFiles)) {
Modified: cfe/trunk/tools/libclang/CIndexer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.h?rev=320085&r1=320084&r2=320085&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexer.h (original)
+++ cfe/trunk/tools/libclang/CIndexer.h Thu Dec 7 12:37:50 2017
@@ -95,6 +95,7 @@ public:
LibclangInvocationReporter(CIndexer &Idx, OperationKind Op,
unsigned ParseOptions,
llvm::ArrayRef<const char *> Args,
+ llvm::ArrayRef<std::string> InvocationArgs,
llvm::ArrayRef<CXUnsavedFile> UnsavedFiles);
~LibclangInvocationReporter();
Modified: cfe/trunk/tools/libclang/CXTranslationUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXTranslationUnit.h?rev=320085&r1=320084&r2=320085&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXTranslationUnit.h (original)
+++ cfe/trunk/tools/libclang/CXTranslationUnit.h Thu Dec 7 12:37:50 2017
@@ -33,6 +33,8 @@ struct CXTranslationUnitImpl {
void *Diagnostics;
void *OverridenCursorsPool;
clang::index::CommentToXMLConverter *CommentToXML;
+ unsigned ParsingOptions;
+ std::vector<std::string> Arguments;
};
struct CXTargetInfoImpl {
More information about the cfe-commits
mailing list