From 3c332b91deb94b0b18e3986b70e05a4afba028d4 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 1 Oct 2018 00:39:44 -0700 Subject: [PATCH] Clean --- src/main.cc | 2 +- src/message_handler.h | 1 - src/project.cc | 20 +++++++++++--------- src/utils.h | 21 --------------------- 4 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/main.cc b/src/main.cc index 669968ea..66c818b7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -90,7 +90,7 @@ int main(int argc, char **argv) { if (!opt_init.empty()) { // We check syntax error here but override client-side // initializationOptions in messages/initialize.cc - g_init_options = opt_init; + g_init_options = opt_init.getValue(); rapidjson::Document reader; rapidjson::ParseResult ok = reader.Parse(g_init_options.c_str()); if (!ok) { diff --git a/src/message_handler.h b/src/message_handler.h index 7d139aa3..31c2eabe 100644 --- a/src/message_handler.h +++ b/src/message_handler.h @@ -3,7 +3,6 @@ #pragma once -#include "lru_cache.h" #include "lsp.h" #include "method.h" #include "query.h" diff --git a/src/project.cc b/src/project.cc index d9b17ccc..4faba32c 100644 --- a/src/project.cc +++ b/src/project.cc @@ -179,24 +179,26 @@ std::vector LoadFromDirectoryListing(ProjectConfig *config) { std::unordered_map> folder_args; std::vector files; + const std::string &project_dir = config->project_dir; - GetFilesInFolder(config->project_dir, true /*recursive*/, + GetFilesInFolder(project_dir, true /*recursive*/, true /*add_folder_to_path*/, [&folder_args, &files](const std::string &path) { if (SourceFileLanguage(path) != LanguageId::Unknown) { files.push_back(path); } else if (sys::path::filename(path) == ".ccls") { - LOG_S(INFO) << "Using .ccls arguments from " << path; - folder_args.emplace(sys::path::parent_path(path), - ReadCompilerArgumentsFromFile(path)); + std::vector args = ReadCompilerArgumentsFromFile(path); + folder_args.emplace(sys::path::parent_path(path), args); + std::string l; + for (size_t i = 0; i < args.size(); i++) { + if (i) + l += ' '; + l += args[i]; + } + LOG_S(INFO) << "use " << path << ": " << l; } }); - const std::string &project_dir = config->project_dir; - const auto &project_dir_args = folder_args[project_dir]; - LOG_IF_S(INFO, !project_dir_args.empty()) - << "Using .ccls arguments " << StringJoin(project_dir_args); - auto GetCompilerArgumentForFile = [&project_dir, &folder_args](std::string cur) { while (!(cur = sys::path::parent_path(cur)).empty()) { diff --git a/src/utils.h b/src/utils.h index cc90bbb4..a4e0e04f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -30,26 +29,6 @@ std::vector SplitString(const std::string &str, std::string LowerPathIfInsensitive(const std::string &path); -template -std::string StringJoinMap(const TValues &values, const TMap &map, - const std::string &sep = ", ") { - std::string result; - bool first = true; - for (auto &entry : values) { - if (!first) - result += sep; - first = false; - result += map(entry); - } - return result; -} - -template -std::string StringJoin(const TValues &values, const std::string &sep = ", ") { - return StringJoinMap(values, [](const std::string &entry) { return entry; }, - sep); -} - // Ensures that |path| ends in a slash. void EnsureEndsInSlash(std::string &path);