Change Config->enableComments from to int

"enableComments": 0  // don't index comments
"enableComments": 1  // index Doxygen comment markers
"enableComments": 2  // -fparse-all-comments
This commit is contained in:
Fangrui Song 2018-01-09 00:46:37 -08:00
parent 37152da0fc
commit 71ca687252
5 changed files with 31 additions and 26 deletions

View File

@ -20,7 +20,7 @@ Range ResolveCXSourceRange(const CXSourceRange& range, CXFile* cx_file) {
} }
// TODO Place this global variable into config // TODO Place this global variable into config
bool g_enable_comments = false; int g_enable_comments;
ClangType::ClangType() : cx_type() {} ClangType::ClangType() : cx_type() {}

View File

@ -91,7 +91,9 @@ struct Config {
// a function or method // a function or method
bool enableSnippetInsertion = true; bool enableSnippetInsertion = true;
bool enableComments = false; // 0: no; 1: Doxygen comment markers; 2: -fparse-all-comments, which includes
// plain // /*
int enableComments = 0;
//// For debugging //// For debugging

View File

@ -12,7 +12,7 @@
// TODO Cleanup global variables // TODO Cleanup global variables
extern std::string g_init_options; extern std::string g_init_options;
extern bool g_enable_comments; extern int g_enable_comments;
namespace { namespace {
struct Ipc_InitializeRequest : public IpcMessage<Ipc_InitializeRequest> { struct Ipc_InitializeRequest : public IpcMessage<Ipc_InitializeRequest> {
@ -176,7 +176,8 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
Timer time; Timer time;
// Open up / load the project. // Open up / load the project.
project->Load(config->extraClangArguments, project->Load(config,
config->extraClangArguments,
config->compilationDatabaseDirectory, project_path, config->compilationDatabaseDirectory, project_path,
config->resourceDirectory); config->resourceDirectory);
time.ResetAndPrint("[perf] Loaded compilation entries (" + time.ResetAndPrint("[perf] Loaded compilation entries (" +

View File

@ -92,6 +92,7 @@ optional<std::string> SourceFileType(const std::string& path) {
} }
Project::Entry GetCompilationEntryFromCompileCommandEntry( Project::Entry GetCompilationEntryFromCompileCommandEntry(
Config* initOpts,
ProjectConfig* config, ProjectConfig* config,
const CompileCommandsEntry& entry) { const CompileCommandsEntry& entry) {
auto cleanup_maybe_relative_path = [&](const std::string& path) { auto cleanup_maybe_relative_path = [&](const std::string& path) {
@ -236,13 +237,13 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
// Using -fparse-all-comments enables documententation in the indexer and in // Using -fparse-all-comments enables documententation in the indexer and in
// code completion. // code completion.
if (!AnyStartsWith(result.args, "-fparse-all-comments")) if (initOpts->enableComments > 1 && !AnyStartsWith(result.args, "-fparse-all-comments"))
result.args.push_back("-fparse-all-comments"); result.args.push_back("-fparse-all-comments");
return result; return result;
} }
std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) { std::vector<Project::Entry> LoadFromDirectoryListing(Config* initOpts, ProjectConfig* config) {
std::vector<Project::Entry> result; std::vector<Project::Entry> result;
std::vector<std::string> args; std::vector<std::string> args;
@ -270,7 +271,7 @@ std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) {
e.file = file; e.file = file;
e.args = args; e.args = args;
e.args.push_back(e.file); e.args.push_back(e.file);
result.push_back(GetCompilationEntryFromCompileCommandEntry(config, e)); result.push_back(GetCompilationEntryFromCompileCommandEntry(initOpts, config, e));
} }
} }
@ -278,11 +279,12 @@ std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig* config) {
} }
std::vector<Project::Entry> LoadCompilationEntriesFromDirectory( std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
Config* initOpts,
ProjectConfig* config, ProjectConfig* config,
const std::string& opt_compilation_db_dir) { const std::string& opt_compilation_db_dir) {
// If there is a .cquery file always load using directory listing. // If there is a .cquery file always load using directory listing.
if (FileExists(config->project_dir + "/.cquery")) if (FileExists(config->project_dir + "/.cquery"))
return LoadFromDirectoryListing(config); return LoadFromDirectoryListing(initOpts, config);
// Try to load compile_commands.json, but fallback to a project listing. // Try to load compile_commands.json, but fallback to a project listing.
const auto& compilation_db_dir = opt_compilation_db_dir.empty() const auto& compilation_db_dir = opt_compilation_db_dir.empty()
@ -295,7 +297,7 @@ std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
if (cx_db_load_error == CXCompilationDatabase_CanNotLoadDatabase) { if (cx_db_load_error == CXCompilationDatabase_CanNotLoadDatabase) {
LOG_S(INFO) << "Unable to load compile_commands.json located at \"" LOG_S(INFO) << "Unable to load compile_commands.json located at \""
<< compilation_db_dir << "\"; using directory listing instead."; << compilation_db_dir << "\"; using directory listing instead.";
return LoadFromDirectoryListing(config); return LoadFromDirectoryListing(initOpts, config);
} }
Timer clang_time; Timer clang_time;
@ -339,7 +341,7 @@ std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(
absolute_filename = directory + "/" + relative_filename; absolute_filename = directory + "/" + relative_filename;
entry.file = NormalizePathWithTestOptOut(absolute_filename); entry.file = NormalizePathWithTestOptOut(absolute_filename);
result.push_back(GetCompilationEntryFromCompileCommandEntry(config, entry)); result.push_back(GetCompilationEntryFromCompileCommandEntry(initOpts, config, entry));
our_time.Pause(); our_time.Pause();
} }
@ -394,7 +396,8 @@ int ComputeGuessScore(const std::string& a, const std::string& b) {
} // namespace } // namespace
void Project::Load(const std::vector<std::string>& extra_flags, void Project::Load(Config* initOpts,
const std::vector<std::string>& extra_flags,
const std::string& opt_compilation_db_dir, const std::string& opt_compilation_db_dir,
const std::string& root_directory, const std::string& root_directory,
const std::string& resource_directory) { const std::string& resource_directory) {
@ -404,7 +407,7 @@ void Project::Load(const std::vector<std::string>& extra_flags,
config.project_dir = root_directory; config.project_dir = root_directory;
config.resource_dir = resource_directory; config.resource_dir = resource_directory;
entries = entries =
LoadCompilationEntriesFromDirectory(&config, opt_compilation_db_dir); LoadCompilationEntriesFromDirectory(initOpts, &config, opt_compilation_db_dir);
// Cleanup / postprocess include directories. // Cleanup / postprocess include directories.
quote_include_directories.assign(config.quote_dirs.begin(), quote_include_directories.assign(config.quote_dirs.begin(),
@ -476,6 +479,7 @@ TEST_SUITE("Project") {
std::vector<std::string> expected) { std::vector<std::string> expected) {
g_disable_normalize_path_for_test = true; g_disable_normalize_path_for_test = true;
Config initOpts;
ProjectConfig config; ProjectConfig config;
config.project_dir = "/w/c/s/"; config.project_dir = "/w/c/s/";
config.resource_dir = "/w/resource_dir/"; config.resource_dir = "/w/resource_dir/";
@ -485,7 +489,7 @@ TEST_SUITE("Project") {
entry.args = raw; entry.args = raw;
entry.file = file; entry.file = file;
Project::Entry result = Project::Entry result =
GetCompilationEntryFromCompileCommandEntry(&config, entry); GetCompilationEntryFromCompileCommandEntry(&initOpts, &config, entry);
if (result.args != expected) { if (result.args != expected) {
std::cout << "Raw: " << StringJoin(raw) << std::endl; std::cout << "Raw: " << StringJoin(raw) << std::endl;
@ -514,21 +518,19 @@ TEST_SUITE("Project") {
/* expected */ /* expected */
{"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14", {"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14",
"-lstdc++", "myfile.cc", "-resource-dir=/w/resource_dir/", "-lstdc++", "myfile.cc", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option", "-fparse-all-comments"}); "-Wno-unknown-warning-option"});
CheckFlags( CheckFlags(
/* raw */ {"goma", "clang"}, /* raw */ {"goma", "clang"},
/* expected */ /* expected */
{"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14", {"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14",
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option", "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"});
"-fparse-all-comments"});
CheckFlags( CheckFlags(
/* raw */ {"goma", "clang", "--foo"}, /* raw */ {"goma", "clang", "--foo"},
/* expected */ /* expected */
{"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14", "--foo", {"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14", "--foo",
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option", "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"});
"-fparse-all-comments"});
} }
// FIXME: Fix this test. // FIXME: Fix this test.
@ -538,7 +540,7 @@ TEST_SUITE("Project") {
/* expected */ /* expected */
{"cc", "-working-directory", "/home/user", "-xc", "-std=gnu11", {"cc", "-working-directory", "/home/user", "-xc", "-std=gnu11",
"-O0", "foo/bar.c", "-resource-dir=/w/resource_dir/", "-O0", "foo/bar.c", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option", "-fparse-all-comments"}); "-Wno-unknown-warning-option"});
} }
TEST_CASE("Implied binary") { TEST_CASE("Implied binary") {
@ -548,7 +550,7 @@ TEST_SUITE("Project") {
/* expected */ /* expected */
{"clang++", "-working-directory", "/home/user", "-xc++", "-std=c++14", {"clang++", "-working-directory", "/home/user", "-xc++", "-std=c++14",
"-DDONT_IGNORE_ME", "-resource-dir=/w/resource_dir/", "-DDONT_IGNORE_ME", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option", "-fparse-all-comments"}); "-Wno-unknown-warning-option"});
} }
// Checks flag parsing for a random chromium file in comparison to what // Checks flag parsing for a random chromium file in comparison to what
@ -897,8 +899,7 @@ TEST_SUITE("Project") {
"-fvisibility-inlines-hidden", "-fvisibility-inlines-hidden",
"../../ash/login/ui/lock_screen_sanity_unittest.cc", "../../ash/login/ui/lock_screen_sanity_unittest.cc",
"-resource-dir=/w/resource_dir/", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option", "-Wno-unknown-warning-option"});
"-fparse-all-comments"});
} }
// Checks flag parsing for an example chromium file. // Checks flag parsing for an example chromium file.
@ -1222,11 +1223,11 @@ TEST_SUITE("Project") {
"-fvisibility-inlines-hidden", "-fvisibility-inlines-hidden",
"../../apps/app_lifetime_monitor.cc", "../../apps/app_lifetime_monitor.cc",
"-resource-dir=/w/resource_dir/", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option", "-Wno-unknown-warning-option"});
"-fparse-all-comments"});
} }
TEST_CASE("Directory extraction") { TEST_CASE("Directory extraction") {
Config initOpts;
ProjectConfig config; ProjectConfig config;
config.project_dir = "/w/c/s/"; config.project_dir = "/w/c/s/";
@ -1256,7 +1257,7 @@ TEST_SUITE("Project") {
"foo.cc"}; "foo.cc"};
entry.file = "foo.cc"; entry.file = "foo.cc";
Project::Entry result = Project::Entry result =
GetCompilationEntryFromCompileCommandEntry(&config, entry); GetCompilationEntryFromCompileCommandEntry(&initOpts, &config, entry);
std::unordered_set<std::string> angle_expected{ std::unordered_set<std::string> angle_expected{
"&/a_absolute1", "&/a_absolute2", "&/base/a_relative1", "&/a_absolute1", "&/a_absolute2", "&/base/a_relative1",

View File

@ -34,7 +34,8 @@ struct Project {
// used instead. Otherwise, a recursive directory listing of all *.cpp, *.cc, // used instead. Otherwise, a recursive directory listing of all *.cpp, *.cc,
// *.h, and *.hpp files will be used. clang arguments can be specified in a // *.h, and *.hpp files will be used. clang arguments can be specified in a
// .cquery file located inside of |root_directory|. // .cquery file located inside of |root_directory|.
void Load(const std::vector<std::string>& extra_flags, void Load(Config* initOpts,
const std::vector<std::string>& extra_flags,
const std::string& opt_compilation_db_dir, const std::string& opt_compilation_db_dir,
const std::string& root_directory, const std::string& root_directory,
const std::string& resource_directory); const std::string& resource_directory);