mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-19 23:20:58 +00:00
Use --init='{"enableComments": true}' to index comments and display them on hover
This commit is contained in:
parent
53134b679c
commit
c0a9b7189f
@ -20,6 +20,7 @@
|
|||||||
#include "queue_manager.h"
|
#include "queue_manager.h"
|
||||||
#include "semantic_highlight_symbol_cache.h"
|
#include "semantic_highlight_symbol_cache.h"
|
||||||
#include "serializer.h"
|
#include "serializer.h"
|
||||||
|
#include "serializers/json.h"
|
||||||
#include "standard_includes.h"
|
#include "standard_includes.h"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
#include "threaded_queue.h"
|
#include "threaded_queue.h"
|
||||||
@ -29,14 +30,11 @@
|
|||||||
#include "working_files.h"
|
#include "working_files.h"
|
||||||
|
|
||||||
#include <doctest/doctest.h>
|
#include <doctest/doctest.h>
|
||||||
#include <rapidjson/istreamwrapper.h>
|
|
||||||
#include <rapidjson/ostreamwrapper.h>
|
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
#include <rapidjson/error/en.h>
|
||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <fstream>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <future>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -52,6 +50,8 @@
|
|||||||
// TODO: implement ThreadPool type which monitors CPU usage / number of work
|
// TODO: implement ThreadPool type which monitors CPU usage / number of work
|
||||||
// items per second completed and scales up/down number of running threads.
|
// items per second completed and scales up/down number of running threads.
|
||||||
|
|
||||||
|
std::string g_init_options;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::vector<std::string> kEmptyArgs;
|
std::vector<std::string> kEmptyArgs;
|
||||||
@ -438,10 +438,22 @@ int main(int argc, char** argv) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HasOption(options, "--enable-comments")) {
|
if (HasOption(options, "--init")) {
|
||||||
// TODO Place this global variable into config
|
// We check syntax error here but override client-side initializationOptions
|
||||||
extern bool g_enable_comments;
|
// in messages/initialize.cc
|
||||||
g_enable_comments = true;
|
g_init_options = options["--init"];
|
||||||
|
rapidjson::Document reader;
|
||||||
|
rapidjson::ParseResult ok = reader.Parse(g_init_options.c_str());
|
||||||
|
if (!ok) {
|
||||||
|
std::cerr << "Failed to parse --init as JSON: "
|
||||||
|
<< rapidjson::GetParseError_En(ok.Code()) << " (" << ok.Offset()
|
||||||
|
<< ")\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!reader.IsObject()) {
|
||||||
|
std::cerr << "--init must be a JSON object\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HasOption(options, "--language-server")) {
|
if (HasOption(options, "--language-server")) {
|
||||||
|
@ -91,6 +91,8 @@ struct Config {
|
|||||||
// a function or method
|
// a function or method
|
||||||
bool enableSnippetInsertion = true;
|
bool enableSnippetInsertion = true;
|
||||||
|
|
||||||
|
bool enableComments = false;
|
||||||
|
|
||||||
//// For debugging
|
//// For debugging
|
||||||
|
|
||||||
// Dump AST after parsing if some pattern matches the source filename.
|
// Dump AST after parsing if some pattern matches the source filename.
|
||||||
@ -132,6 +134,8 @@ MAKE_REFLECT_STRUCT(Config,
|
|||||||
clientVersion,
|
clientVersion,
|
||||||
enableSnippetInsertion,
|
enableSnippetInsertion,
|
||||||
|
|
||||||
|
enableComments,
|
||||||
|
|
||||||
dumpAST
|
dumpAST
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
|
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
|
||||||
|
// TODO Cleanup global variables
|
||||||
|
extern std::string g_init_options;
|
||||||
|
extern bool g_enable_comments;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct Ipc_InitializeRequest : public IpcMessage<Ipc_InitializeRequest> {
|
struct Ipc_InitializeRequest : public IpcMessage<Ipc_InitializeRequest> {
|
||||||
const static IpcId kIpcId = IpcId::Initialize;
|
const static IpcId kIpcId = IpcId::Initialize;
|
||||||
@ -60,6 +64,15 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
*config = *request->params.initializationOptions;
|
*config = *request->params.initializationOptions;
|
||||||
|
{
|
||||||
|
rapidjson::Document reader;
|
||||||
|
reader.Parse(g_init_options.c_str());
|
||||||
|
if (!reader.HasParseError()) {
|
||||||
|
JsonReader json_reader{&reader};
|
||||||
|
Reflect(json_reader, *config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_enable_comments = config->enableComments;
|
||||||
|
|
||||||
// Check client version.
|
// Check client version.
|
||||||
if (config->clientVersion.has_value() &&
|
if (config->clientVersion.has_value() &&
|
||||||
|
Loading…
Reference in New Issue
Block a user