This commit is contained in:
Fangrui Song 2018-10-01 00:39:44 -07:00
parent fa2234c894
commit 3c332b91de
4 changed files with 12 additions and 32 deletions

View File

@ -90,7 +90,7 @@ int main(int argc, char **argv) {
if (!opt_init.empty()) { if (!opt_init.empty()) {
// We check syntax error here but override client-side // We check syntax error here but override client-side
// initializationOptions in messages/initialize.cc // initializationOptions in messages/initialize.cc
g_init_options = opt_init; g_init_options = opt_init.getValue();
rapidjson::Document reader; rapidjson::Document reader;
rapidjson::ParseResult ok = reader.Parse(g_init_options.c_str()); rapidjson::ParseResult ok = reader.Parse(g_init_options.c_str());
if (!ok) { if (!ok) {

View File

@ -3,7 +3,6 @@
#pragma once #pragma once
#include "lru_cache.h"
#include "lsp.h" #include "lsp.h"
#include "method.h" #include "method.h"
#include "query.h" #include "query.h"

View File

@ -179,24 +179,26 @@ std::vector<Project::Entry> LoadFromDirectoryListing(ProjectConfig *config) {
std::unordered_map<std::string, std::vector<const char *>> folder_args; std::unordered_map<std::string, std::vector<const char *>> folder_args;
std::vector<std::string> files; std::vector<std::string> 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*/, true /*add_folder_to_path*/,
[&folder_args, &files](const std::string &path) { [&folder_args, &files](const std::string &path) {
if (SourceFileLanguage(path) != LanguageId::Unknown) { if (SourceFileLanguage(path) != LanguageId::Unknown) {
files.push_back(path); files.push_back(path);
} else if (sys::path::filename(path) == ".ccls") { } else if (sys::path::filename(path) == ".ccls") {
LOG_S(INFO) << "Using .ccls arguments from " << path; std::vector<const char *> args = ReadCompilerArgumentsFromFile(path);
folder_args.emplace(sys::path::parent_path(path), folder_args.emplace(sys::path::parent_path(path), args);
ReadCompilerArgumentsFromFile(path)); 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, auto GetCompilerArgumentForFile = [&project_dir,
&folder_args](std::string cur) { &folder_args](std::string cur) {
while (!(cur = sys::path::parent_path(cur)).empty()) { while (!(cur = sys::path::parent_path(cur)).empty()) {

View File

@ -7,7 +7,6 @@
#include <string_view> #include <string_view>
#include <iterator> #include <iterator>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -30,26 +29,6 @@ std::vector<std::string> SplitString(const std::string &str,
std::string LowerPathIfInsensitive(const std::string &path); std::string LowerPathIfInsensitive(const std::string &path);
template <typename TValues, typename TMap>
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 <typename TValues>
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. // Ensures that |path| ends in a slash.
void EnsureEndsInSlash(std::string &path); void EnsureEndsInSlash(std::string &path);