Use --init='{"enableComments": true}' to index comments and display them on hover

This commit is contained in:
Fangrui Song 2018-01-08 19:09:15 -08:00
parent 53134b679c
commit c0a9b7189f
3 changed files with 37 additions and 8 deletions

View File

@ -20,6 +20,7 @@
#include "queue_manager.h"
#include "semantic_highlight_symbol_cache.h"
#include "serializer.h"
#include "serializers/json.h"
#include "standard_includes.h"
#include "test.h"
#include "threaded_queue.h"
@ -29,14 +30,11 @@
#include "working_files.h"
#include <doctest/doctest.h>
#include <rapidjson/istreamwrapper.h>
#include <rapidjson/ostreamwrapper.h>
#include <loguru.hpp>
#include <rapidjson/error/en.h>
#include <climits>
#include <fstream>
#include <functional>
#include <future>
#include <iostream>
#include <iterator>
#include <sstream>
@ -52,6 +50,8 @@
// TODO: implement ThreadPool type which monitors CPU usage / number of work
// items per second completed and scales up/down number of running threads.
std::string g_init_options;
namespace {
std::vector<std::string> kEmptyArgs;
@ -438,10 +438,22 @@ int main(int argc, char** argv) {
return -1;
}
if (HasOption(options, "--enable-comments")) {
// TODO Place this global variable into config
extern bool g_enable_comments;
g_enable_comments = true;
if (HasOption(options, "--init")) {
// We check syntax error here but override client-side initializationOptions
// in messages/initialize.cc
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")) {

View File

@ -91,6 +91,8 @@ struct Config {
// a function or method
bool enableSnippetInsertion = true;
bool enableComments = false;
//// For debugging
// Dump AST after parsing if some pattern matches the source filename.
@ -132,6 +134,8 @@ MAKE_REFLECT_STRUCT(Config,
clientVersion,
enableSnippetInsertion,
enableComments,
dumpAST
);

View File

@ -10,6 +10,10 @@
#include <loguru.hpp>
// TODO Cleanup global variables
extern std::string g_init_options;
extern bool g_enable_comments;
namespace {
struct Ipc_InitializeRequest : public IpcMessage<Ipc_InitializeRequest> {
const static IpcId kIpcId = IpcId::Initialize;
@ -60,6 +64,15 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
}
*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.
if (config->clientVersion.has_value() &&