mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-30 03:17:08 +00:00
Support multiple -init=
Initialization options are applied (deserialized to the same object) in the following order: * "initializationOptions" from client * first -init= * second -init= * ... Scalar options will be overridden but arrays will get concatenated, e.g. ccls -log-file=/dev/stderr -index . -init='{"clang":{"extraArgs":["-DA"]}}' -init='{"clang":{"extraArgs":["-DB"]}}' results in clang.extraArgs: ["-DA", "-DB"]
This commit is contained in:
parent
e53a1aba97
commit
1d7674bdfc
10
src/main.cc
10
src/main.cc
@ -30,7 +30,7 @@ using namespace llvm;
|
||||
using namespace llvm::cl;
|
||||
|
||||
namespace ccls {
|
||||
std::string g_init_options;
|
||||
std::vector<std::string> g_init_options;
|
||||
}
|
||||
|
||||
namespace {
|
||||
@ -44,7 +44,7 @@ opt<std::string> opt_test_index("test-index", ValueOptional, init("!"),
|
||||
opt<std::string> opt_index("index",
|
||||
desc("standalone mode: index a project and exit"),
|
||||
value_desc("root"), cat(C));
|
||||
opt<std::string> opt_init("init", desc("extra initialization options in JSON"),
|
||||
list<std::string> opt_init("init", desc("extra initialization options in JSON"),
|
||||
cat(C));
|
||||
opt<std::string> opt_log_file("log-file", desc("log"), value_desc("filename"),
|
||||
cat(C));
|
||||
@ -106,9 +106,10 @@ 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.getValue();
|
||||
g_init_options = opt_init;
|
||||
rapidjson::Document reader;
|
||||
rapidjson::ParseResult ok = reader.Parse(g_init_options.c_str());
|
||||
for (const std::string &str : g_init_options) {
|
||||
rapidjson::ParseResult ok = reader.Parse(str.c_str());
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Failed to parse --init as JSON: %s (%zd)\n",
|
||||
rapidjson::GetParseError_En(ok.Code()), ok.Offset());
|
||||
@ -125,6 +126,7 @@ int main(int argc, char **argv) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sys::ChangeStdinToBinary();
|
||||
sys::ChangeStdoutToBinary();
|
||||
|
@ -24,8 +24,7 @@
|
||||
namespace ccls {
|
||||
using namespace llvm;
|
||||
|
||||
// TODO Cleanup global variables
|
||||
extern std::string g_init_options;
|
||||
extern std::vector<std::string> g_init_options;
|
||||
|
||||
namespace {
|
||||
enum class TextDocumentSyncKind { None = 0, Full = 1, Incremental = 2 };
|
||||
@ -243,7 +242,8 @@ void Initialize(MessageHandler *m, InitializeParam ¶m, ReplyOnce &reply) {
|
||||
{
|
||||
g_config = new Config(param.initializationOptions);
|
||||
rapidjson::Document reader;
|
||||
reader.Parse(g_init_options.c_str());
|
||||
for (const std::string &str : g_init_options) {
|
||||
reader.Parse(str.c_str());
|
||||
if (!reader.HasParseError()) {
|
||||
JsonReader json_reader{&reader};
|
||||
try {
|
||||
@ -253,6 +253,7 @@ void Initialize(MessageHandler *m, InitializeParam ¶m, ReplyOnce &reply) {
|
||||
// MessageRegistry::Parse in lsp.cc
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rapidjson::StringBuffer output;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(output);
|
||||
|
Loading…
Reference in New Issue
Block a user