diff --git a/src/clang_cursor.cc b/src/clang_cursor.cc index a4efda2b..af70888e 100644 --- a/src/clang_cursor.cc +++ b/src/clang_cursor.cc @@ -20,7 +20,7 @@ Range ResolveCXSourceRange(const CXSourceRange& range, CXFile* cx_file) { } // TODO Place this global variable into config -bool g_enable_comments = false; +int g_enable_comments; ClangType::ClangType() : cx_type() {} diff --git a/src/config.h b/src/config.h index fe0297db..84c0f61c 100644 --- a/src/config.h +++ b/src/config.h @@ -91,7 +91,9 @@ struct Config { // a function or method bool enableSnippetInsertion = true; - bool enableComments = false; + // 0: no; 1: Doxygen comment markers; 2: -fparse-all-comments, which includes + // plain // /* + int enableComments = 0; //// For debugging diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index ab865220..95c5e1e1 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -12,7 +12,7 @@ // TODO Cleanup global variables extern std::string g_init_options; -extern bool g_enable_comments; +extern int g_enable_comments; namespace { struct Ipc_InitializeRequest : public IpcMessage { @@ -176,7 +176,8 @@ struct InitializeHandler : BaseMessageHandler { Timer time; // Open up / load the project. - project->Load(config->extraClangArguments, + project->Load(config, + config->extraClangArguments, config->compilationDatabaseDirectory, project_path, config->resourceDirectory); time.ResetAndPrint("[perf] Loaded compilation entries (" + diff --git a/src/project.cc b/src/project.cc index 97b2a50a..bdada838 100644 --- a/src/project.cc +++ b/src/project.cc @@ -92,6 +92,7 @@ optional SourceFileType(const std::string& path) { } Project::Entry GetCompilationEntryFromCompileCommandEntry( + Config* initOpts, ProjectConfig* config, const CompileCommandsEntry& entry) { 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 // 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"); return result; } -std::vector LoadFromDirectoryListing(ProjectConfig* config) { +std::vector LoadFromDirectoryListing(Config* initOpts, ProjectConfig* config) { std::vector result; std::vector args; @@ -270,7 +271,7 @@ std::vector LoadFromDirectoryListing(ProjectConfig* config) { e.file = file; e.args = args; 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 LoadFromDirectoryListing(ProjectConfig* config) { } std::vector LoadCompilationEntriesFromDirectory( + Config* initOpts, ProjectConfig* config, const std::string& opt_compilation_db_dir) { // If there is a .cquery file always load using directory listing. 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. const auto& compilation_db_dir = opt_compilation_db_dir.empty() @@ -295,7 +297,7 @@ std::vector LoadCompilationEntriesFromDirectory( if (cx_db_load_error == CXCompilationDatabase_CanNotLoadDatabase) { LOG_S(INFO) << "Unable to load compile_commands.json located at \"" << compilation_db_dir << "\"; using directory listing instead."; - return LoadFromDirectoryListing(config); + return LoadFromDirectoryListing(initOpts, config); } Timer clang_time; @@ -339,7 +341,7 @@ std::vector LoadCompilationEntriesFromDirectory( absolute_filename = directory + "/" + relative_filename; entry.file = NormalizePathWithTestOptOut(absolute_filename); - result.push_back(GetCompilationEntryFromCompileCommandEntry(config, entry)); + result.push_back(GetCompilationEntryFromCompileCommandEntry(initOpts, config, entry)); our_time.Pause(); } @@ -394,7 +396,8 @@ int ComputeGuessScore(const std::string& a, const std::string& b) { } // namespace -void Project::Load(const std::vector& extra_flags, +void Project::Load(Config* initOpts, + const std::vector& extra_flags, const std::string& opt_compilation_db_dir, const std::string& root_directory, const std::string& resource_directory) { @@ -404,7 +407,7 @@ void Project::Load(const std::vector& extra_flags, config.project_dir = root_directory; config.resource_dir = resource_directory; entries = - LoadCompilationEntriesFromDirectory(&config, opt_compilation_db_dir); + LoadCompilationEntriesFromDirectory(initOpts, &config, opt_compilation_db_dir); // Cleanup / postprocess include directories. quote_include_directories.assign(config.quote_dirs.begin(), @@ -476,6 +479,7 @@ TEST_SUITE("Project") { std::vector expected) { g_disable_normalize_path_for_test = true; + Config initOpts; ProjectConfig config; config.project_dir = "/w/c/s/"; config.resource_dir = "/w/resource_dir/"; @@ -485,7 +489,7 @@ TEST_SUITE("Project") { entry.args = raw; entry.file = file; Project::Entry result = - GetCompilationEntryFromCompileCommandEntry(&config, entry); + GetCompilationEntryFromCompileCommandEntry(&initOpts, &config, entry); if (result.args != expected) { std::cout << "Raw: " << StringJoin(raw) << std::endl; @@ -514,21 +518,19 @@ TEST_SUITE("Project") { /* expected */ {"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14", "-lstdc++", "myfile.cc", "-resource-dir=/w/resource_dir/", - "-Wno-unknown-warning-option", "-fparse-all-comments"}); + "-Wno-unknown-warning-option"}); CheckFlags( /* raw */ {"goma", "clang"}, /* expected */ {"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14", - "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option", - "-fparse-all-comments"}); + "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"}); CheckFlags( /* raw */ {"goma", "clang", "--foo"}, /* expected */ {"clang", "-working-directory", "/dir/", "-xc++", "-std=c++14", "--foo", - "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option", - "-fparse-all-comments"}); + "-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option"}); } // FIXME: Fix this test. @@ -538,7 +540,7 @@ TEST_SUITE("Project") { /* expected */ {"cc", "-working-directory", "/home/user", "-xc", "-std=gnu11", "-O0", "foo/bar.c", "-resource-dir=/w/resource_dir/", - "-Wno-unknown-warning-option", "-fparse-all-comments"}); + "-Wno-unknown-warning-option"}); } TEST_CASE("Implied binary") { @@ -548,7 +550,7 @@ TEST_SUITE("Project") { /* expected */ {"clang++", "-working-directory", "/home/user", "-xc++", "-std=c++14", "-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 @@ -897,8 +899,7 @@ TEST_SUITE("Project") { "-fvisibility-inlines-hidden", "../../ash/login/ui/lock_screen_sanity_unittest.cc", "-resource-dir=/w/resource_dir/", - "-Wno-unknown-warning-option", - "-fparse-all-comments"}); + "-Wno-unknown-warning-option"}); } // Checks flag parsing for an example chromium file. @@ -1222,11 +1223,11 @@ TEST_SUITE("Project") { "-fvisibility-inlines-hidden", "../../apps/app_lifetime_monitor.cc", "-resource-dir=/w/resource_dir/", - "-Wno-unknown-warning-option", - "-fparse-all-comments"}); + "-Wno-unknown-warning-option"}); } TEST_CASE("Directory extraction") { + Config initOpts; ProjectConfig config; config.project_dir = "/w/c/s/"; @@ -1256,7 +1257,7 @@ TEST_SUITE("Project") { "foo.cc"}; entry.file = "foo.cc"; Project::Entry result = - GetCompilationEntryFromCompileCommandEntry(&config, entry); + GetCompilationEntryFromCompileCommandEntry(&initOpts, &config, entry); std::unordered_set angle_expected{ "&/a_absolute1", "&/a_absolute2", "&/base/a_relative1", diff --git a/src/project.h b/src/project.h index 3a9f6268..d8ae6a2e 100644 --- a/src/project.h +++ b/src/project.h @@ -34,7 +34,8 @@ struct Project { // 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 // .cquery file located inside of |root_directory|. - void Load(const std::vector& extra_flags, + void Load(Config* initOpts, + const std::vector& extra_flags, const std::string& opt_compilation_db_dir, const std::string& root_directory, const std::string& resource_directory);