Add Config->dumpAST for dumping AST after parsing

Example initializationOptions: {"dumpAST": ["a.cc"]}
This commit is contained in:
Fangrui Song 2018-01-07 23:51:36 -08:00
parent a3a89af14f
commit 7b8f8e9cad
2 changed files with 16 additions and 2 deletions

View File

@ -90,6 +90,11 @@ struct Config {
// If true parameter declarations are included in code completion when calling // If true parameter declarations are included in code completion when calling
// a function or method // a function or method
bool enableSnippetInsertion = true; bool enableSnippetInsertion = true;
//// For debugging
// Dump AST after parsing if some pattern matches the source filename.
std::vector<std::string> dumpAST;
}; };
MAKE_REFLECT_STRUCT(Config, MAKE_REFLECT_STRUCT(Config,
compilationDatabaseDirectory, compilationDatabaseDirectory,
@ -125,7 +130,10 @@ MAKE_REFLECT_STRUCT(Config,
codeLensOnLocalVariables, codeLensOnLocalVariables,
clientVersion, clientVersion,
enableSnippetInsertion); enableSnippetInsertion,
dumpAST
);
// Expected client version. We show an error if this doesn't match. // Expected client version. We show an error if this doesn't match.
constexpr const int kExpectedClientVersion = 3; constexpr const int kExpectedClientVersion = 3;

View File

@ -13,8 +13,14 @@ struct ClangIndexer : IIndexer {
const std::vector<std::string>& args, const std::vector<std::string>& args,
const std::vector<FileContents>& file_contents, const std::vector<FileContents>& file_contents,
PerformanceImportFile* perf) override { PerformanceImportFile* perf) override {
bool dump_ast = false;
for (const std::string& pattern : config->dumpAST)
if (file.find(pattern) != std::string::npos) {
dump_ast = true;
break;
}
return Parse(config, file_consumer_shared, file, args, file_contents, perf, return Parse(config, file_consumer_shared, file, args, file_contents, perf,
&index); &index, dump_ast);
} }
// Note: constructing this acquires a global lock // Note: constructing this acquires a global lock