Add docs to config.h, remove enableCacheRead/enableCacheWrite.

This commit is contained in:
Jacob Dufault 2018-01-29 16:14:23 -08:00
parent 412af53e1d
commit 233a108814
3 changed files with 57 additions and 24 deletions

View File

@ -18,9 +18,6 @@ struct RealCacheManager : ICacheManager {
~RealCacheManager() override = default; ~RealCacheManager() override = default;
void WriteToCache(IndexFile& file) override { void WriteToCache(IndexFile& file) override {
if (!config_->enableCacheWrite)
return;
std::string cache_path = GetCachePath(file.path); std::string cache_path = GetCachePath(file.path);
if (!file.file_contents_.has_value()) { if (!file.file_contents_.has_value()) {
@ -37,16 +34,10 @@ struct RealCacheManager : ICacheManager {
optional<std::string> LoadCachedFileContents( optional<std::string> LoadCachedFileContents(
const std::string& path) override { const std::string& path) override {
if (!config_->enableCacheRead)
return nullopt;
return ReadContent(GetCachePath(path)); return ReadContent(GetCachePath(path));
} }
std::unique_ptr<IndexFile> RawCacheLoad(const std::string& path) override { std::unique_ptr<IndexFile> RawCacheLoad(const std::string& path) override {
if (!config_->enableCacheRead)
return nullptr;
std::string cache_path = GetCachePath(path); std::string cache_path = GetCachePath(path);
optional<std::string> file_content = optional<std::string> file_content =
ReadContent(AppendSerializationFormat(cache_path)); ReadContent(AppendSerializationFormat(cache_path));

View File

@ -4,21 +4,62 @@
#include <string> #include <string>
/*
The language client plugin needs to send some initialization options to the
cquery language server. The only required option is cacheDirectory, which is
where index files will be stored.
{
"initializationOptions": {
"cacheDirectory": "/tmp/cquery",
}
}
If necessary, these options can also be passed via the command line option
--init, for example,
--init='{"enableComments": 2}'
*/
struct Config { struct Config {
// Root directory of the project. **Not serialized** // Root directory of the project. **Not available for configuration**
std::string projectRoot; std::string projectRoot;
// Location of compile_commands.json. // Directory containing compile_commands.json.
std::string compilationDatabaseDirectory; std::string compilationDatabaseDirectory;
// Cache directory for indexed files. // Cache directory for indexed files.
std::string cacheDirectory; std::string cacheDirectory;
// Cache serialization format // Cache serialization format.
//
// "json" generates `cacheDirectory/.../xxx.json` files which can be pretty
// printed with jq.
//
// "msgpack" uses a compact binary serialization format (the underlying wire
// format is [MessagePack](https://msgpack.org/index.html)) which typically
// takes only 60% of the corresponding JSON size, but is difficult to inspect.
// msgpack does not store map keys and you need to re-index whenever a struct
// member has changed.
SerializeFormat cacheFormat = SerializeFormat::Json; SerializeFormat cacheFormat = SerializeFormat::Json;
// Value to use for clang -resource-dir if not present in // Value to use for clang -resource-dir if not present in
// compile_commands.json. // compile_commands.json.
//
// cquery includes a resource directory, this should not need to be configured
// unless you're using an esoteric configuration. Consider reporting a bug and
// fixing upstream instead of configuring this.
//
// Example value: "/path/to/lib/clang/5.0.1/"
std::string resourceDirectory; std::string resourceDirectory;
// Additional arguments to pass to clang.
std::vector<std::string> extraClangArguments; std::vector<std::string> extraClangArguments;
// If a translation unit's absolute path matches any EMCAScript regex in this
// list, it will be indexed. The whitelist takes priority over the blacklist.
// To only index files in the whitelist, make indexBlacklist match
// everything, ie, set it to ".*".
//
// You probably want to begin the regex using .* because the passed paths are
// absolute.
//
// Example: .*/ash/*
std::vector<std::string> indexWhitelist; std::vector<std::string> indexWhitelist;
std::vector<std::string> indexBlacklist; std::vector<std::string> indexBlacklist;
// If true, project paths that were skipped by the whitelist/blacklist will // If true, project paths that were skipped by the whitelist/blacklist will
@ -33,14 +74,10 @@ struct Config {
bool sortWorkspaceSearchResults = true; bool sortWorkspaceSearchResults = true;
// Force a certain number of indexer threads. If less than 1 a default value // Force a certain number of indexer threads. If less than 1 a default value
// should be used. // is be used (80% number of CPU cores).
int indexerCount = 0; int indexerCount = 0;
// If false, the indexer will be disabled. // If false, the indexer will be disabled.
bool enableIndexing = true; bool enableIndexing = true;
// If false, indexed files will not be written to disk.
bool enableCacheWrite = true;
// If false, the index will not be loaded from a previous run.
bool enableCacheRead = true;
// If true, cquery will send progress reports while indexing // If true, cquery will send progress reports while indexing
// How often should cquery send progress report messages? // How often should cquery send progress report messages?
@ -94,7 +131,11 @@ struct Config {
ClientCapability client; ClientCapability client;
struct Completion { struct Completion {
// If true, filter and sort completion response. // If true, filter and sort completion response. cquery filters and sorts
// completions to try to be nicer to clients that can't handle big numbers
// of completion candidates. This behaviour can be disabled by specifying
// false for the option. This option is the most useful for LSP clients
// that implement their own filtering and sorting logic.
bool filterAndSort = true; bool filterAndSort = true;
}; };
Completion completion; Completion completion;
@ -102,8 +143,11 @@ struct Config {
struct Index { struct Index {
bool builtinTypes = false; bool builtinTypes = false;
// 0: no; 1: Doxygen comment markers; 2: -fparse-all-comments, which includes // 0: none, 1: doxygen, 2: all comments
// plain // /* // Plugin support for clients:
// - https://github.com/emacs-lsp/lsp-ui
// - https://github.com/emacs-lsp/lsp-mode/pull/224
// - https://github.com/autozimu/LanguageClient-neovim/issues/224
int comments = 2; int comments = 2;
}; };
Index index; Index index;
@ -133,8 +177,6 @@ MAKE_REFLECT_STRUCT(Config,
indexerCount, indexerCount,
enableIndexing, enableIndexing,
enableCacheWrite,
enableCacheRead,
progressReportFrequencyMs, progressReportFrequencyMs,
includeCompletionMaximumPathLength, includeCompletionMaximumPathLength,

View File

@ -503,8 +503,8 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
g_enable_comments = config->index.comments; g_enable_comments = config->index.comments;
if (config->cacheDirectory.empty()) { if (config->cacheDirectory.empty()) {
config->enableCacheRead = config->enableCacheWrite = false; LOG_S(ERROR) << "cacheDirectory cannot be empty.";
LOG_S(INFO) << "Disable cache files because cacheDirectory is empty"; exit(1);
} else { } else {
config->cacheDirectory = NormalizePath(config->cacheDirectory); config->cacheDirectory = NormalizePath(config->cacheDirectory);
EnsureEndsInSlash(config->cacheDirectory); EnsureEndsInSlash(config->cacheDirectory);