2017-05-21 19:51:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "serializer.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2018-01-30 00:14:23 +00:00
|
|
|
/*
|
2018-01-30 17:04:01 +00:00
|
|
|
The language client plugin needs to send initialization options in the
|
|
|
|
`initialize` request to the cquery language server. The only required option is
|
|
|
|
`cacheDirectory`, which is where index files will be stored.
|
2018-01-30 00:14:23 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
"initializationOptions": {
|
2018-01-30 17:04:01 +00:00
|
|
|
"cacheDirectory": "/tmp/cquery"
|
2018-01-30 00:14:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 17:04:01 +00:00
|
|
|
If necessary, the command line option --init can be used to override
|
|
|
|
initialization options specified by the client. For example, in shell syntax:
|
2018-01-30 00:14:23 +00:00
|
|
|
|
2018-01-30 17:04:01 +00:00
|
|
|
'--init={"indexWhitelist": ["."], "index": {"comments": 2}}'
|
2018-01-30 00:14:23 +00:00
|
|
|
*/
|
2017-05-21 19:51:15 +00:00
|
|
|
struct Config {
|
2018-01-30 00:14:23 +00:00
|
|
|
// Root directory of the project. **Not available for configuration**
|
2017-05-21 19:51:15 +00:00
|
|
|
std::string projectRoot;
|
2018-02-20 00:19:57 +00:00
|
|
|
// If specified, this option overrides compile_commands.json and this
|
|
|
|
// external command will be executed with an option |projectRoot|.
|
|
|
|
// The initialization options will be provided as stdin.
|
|
|
|
// The stdout of the command should be the JSON compilation database.
|
|
|
|
std::string compilationDatabaseCommand;
|
2018-01-30 00:14:23 +00:00
|
|
|
// Directory containing compile_commands.json.
|
2017-11-21 16:47:28 +00:00
|
|
|
std::string compilationDatabaseDirectory;
|
2017-07-16 00:25:52 +00:00
|
|
|
// Cache directory for indexed files.
|
2017-05-21 19:51:15 +00:00
|
|
|
std::string cacheDirectory;
|
2018-01-30 00:14:23 +00:00
|
|
|
// 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.
|
2018-01-06 23:29:53 +00:00
|
|
|
SerializeFormat cacheFormat = SerializeFormat::Json;
|
2017-10-25 01:02:15 +00:00
|
|
|
// Value to use for clang -resource-dir if not present in
|
|
|
|
// compile_commands.json.
|
2018-01-30 00:14:23 +00:00
|
|
|
//
|
|
|
|
// 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/"
|
2017-10-25 01:02:15 +00:00
|
|
|
std::string resourceDirectory;
|
2017-05-22 06:45:47 +00:00
|
|
|
|
2018-01-30 00:14:23 +00:00
|
|
|
// Additional arguments to pass to clang.
|
2017-05-21 19:51:15 +00:00
|
|
|
std::vector<std::string> extraClangArguments;
|
|
|
|
|
2018-01-30 17:04:01 +00:00
|
|
|
// If a translation unit's absolute path matches any EMCAScript regex in the
|
|
|
|
// whitelist, or does not match any regex in the blacklist, it will be indexed.
|
|
|
|
// To only index files in the whitelist, add ".*" to the blacklist.
|
|
|
|
// `std::regex_search(path, regex, std::regex_constants::match_any)`
|
2018-01-30 00:14:23 +00:00
|
|
|
//
|
2018-01-30 17:04:01 +00:00
|
|
|
// Example: `ash/.*\.cc`
|
2017-05-22 06:45:47 +00:00
|
|
|
std::vector<std::string> indexWhitelist;
|
|
|
|
std::vector<std::string> indexBlacklist;
|
|
|
|
// If true, project paths that were skipped by the whitelist/blacklist will
|
|
|
|
// be logged.
|
|
|
|
bool logSkippedPathsForIndex = false;
|
2017-09-22 01:14:57 +00:00
|
|
|
|
2017-05-21 19:51:15 +00:00
|
|
|
// Maximum workspace search results.
|
2017-12-24 06:49:45 +00:00
|
|
|
int maxWorkspaceSearchResults = 500;
|
2018-01-07 21:08:18 +00:00
|
|
|
// If true, workspace search results will be dynamically rescored/reordered
|
|
|
|
// as the search progresses. Some clients do their own ordering and assume
|
|
|
|
// that the results stay sorted in the same order as the search progresses.
|
|
|
|
bool sortWorkspaceSearchResults = true;
|
2017-05-21 19:51:15 +00:00
|
|
|
|
|
|
|
// Force a certain number of indexer threads. If less than 1 a default value
|
2018-01-30 00:14:23 +00:00
|
|
|
// is be used (80% number of CPU cores).
|
2017-05-21 19:51:15 +00:00
|
|
|
int indexerCount = 0;
|
|
|
|
// If false, the indexer will be disabled.
|
|
|
|
bool enableIndexing = true;
|
|
|
|
|
2017-11-26 22:20:43 +00:00
|
|
|
// If true, cquery will send progress reports while indexing
|
2018-01-07 21:06:18 +00:00
|
|
|
// How often should cquery send progress report messages?
|
|
|
|
// -1: never
|
|
|
|
// 0: as often as possible
|
|
|
|
// xxx: at most every xxx milliseconds
|
|
|
|
//
|
|
|
|
// Empty progress reports (ie, idle) are delivered as often as they are
|
|
|
|
// available and may exceed this value.
|
|
|
|
//
|
|
|
|
// This does not guarantee a progress report will be delivered every
|
|
|
|
// interval; it could take significantly longer if cquery is completely idle.
|
|
|
|
int progressReportFrequencyMs = 500;
|
2017-11-26 22:20:43 +00:00
|
|
|
|
2017-05-21 19:51:15 +00:00
|
|
|
// If true, document links are reported for #include directives.
|
|
|
|
bool showDocumentLinksOnIncludes = true;
|
|
|
|
|
2017-05-21 21:01:52 +00:00
|
|
|
// Maximum path length to show in completion results. Paths longer than this
|
|
|
|
// will be elided with ".." put at the front. Set to 0 or a negative number
|
|
|
|
// to disable eliding.
|
|
|
|
int includeCompletionMaximumPathLength = 30;
|
2017-05-21 19:51:15 +00:00
|
|
|
// Whitelist that file paths will be tested against. If a file path does not
|
|
|
|
// end in one of these values, it will not be considered for auto-completion.
|
|
|
|
// An example value is { ".h", ".hpp" }
|
|
|
|
//
|
|
|
|
// This is significantly faster than using a regex.
|
2018-01-29 14:26:13 +00:00
|
|
|
std::vector<std::string> includeCompletionWhitelistLiteralEnding = {
|
|
|
|
".h", ".hpp", ".hh"};
|
2017-05-21 19:51:15 +00:00
|
|
|
// Regex patterns to match include completion candidates against. They
|
|
|
|
// receive the absolute file path.
|
|
|
|
//
|
|
|
|
// For example, to hide all files in a /CACHE/ folder, use ".*/CACHE/.*"
|
|
|
|
std::vector<std::string> includeCompletionWhitelist;
|
|
|
|
std::vector<std::string> includeCompletionBlacklist;
|
|
|
|
|
2017-07-16 00:25:52 +00:00
|
|
|
// If true, diagnostics from a full document parse will be reported.
|
|
|
|
bool diagnosticsOnParse = true;
|
|
|
|
// If true, diagnostics from code completion will be reported.
|
|
|
|
bool diagnosticsOnCodeCompletion = true;
|
|
|
|
|
2017-05-21 19:51:15 +00:00
|
|
|
// Enables code lens on parameter and function variables.
|
|
|
|
bool codeLensOnLocalVariables = true;
|
|
|
|
|
2017-12-04 08:29:38 +00:00
|
|
|
// Version of the client. If undefined the version check is skipped. Used to
|
|
|
|
// inform users their vscode client is too old and needs to be updated.
|
|
|
|
optional<int> clientVersion;
|
2017-11-19 12:57:16 +00:00
|
|
|
|
2018-01-21 17:52:28 +00:00
|
|
|
struct ClientCapability {
|
|
|
|
// TextDocumentClientCapabilities.completion.completionItem.snippetSupport
|
|
|
|
bool snippetSupport = false;
|
|
|
|
};
|
|
|
|
ClientCapability client;
|
|
|
|
|
|
|
|
struct Completion {
|
2018-01-30 00:14:23 +00:00
|
|
|
// 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.
|
2018-01-21 17:52:28 +00:00
|
|
|
bool filterAndSort = true;
|
add detailedLabel completion style
Some completion UI, such as Emacs' completion-at-point and company-lsp,
display completion item label and detail side by side.
This does not look right, when you see things like:
"foo" "int foo()"
"bar" "void bar(int i = 0)"
When this option is enabled, the completion item label is very detailed,
it shows the full signature of the candidate.
The detail just contains the completion item parent context.
Also, in this mode, functions with default arguments,
generates one more item per default argument
so that the right function call can be selected.
That is, you get something like:
"int foo()" "Foo"
"void bar()" "Foo"
"void bar(int i = 0)" "Foo"
Be wary, this is quickly quite verbose,
items can end up truncated by the UIs.
2018-02-03 17:32:55 +00:00
|
|
|
|
|
|
|
// Some completion UI, such as Emacs' completion-at-point and company-lsp,
|
|
|
|
// display completion item label and detail side by side.
|
|
|
|
// This does not look right, when you see things like:
|
|
|
|
// "foo" "int foo()"
|
|
|
|
// "bar" "void bar(int i = 0)"
|
|
|
|
// When this option is enabled, the completion item label is very detailed,
|
|
|
|
// it shows the full signature of the candidate.
|
|
|
|
// The detail just contains the completion item parent context.
|
|
|
|
// Also, in this mode, functions with default arguments,
|
|
|
|
// generates one more item per default argument
|
|
|
|
// so that the right function call can be selected.
|
|
|
|
// That is, you get something like:
|
|
|
|
// "int foo()" "Foo"
|
|
|
|
// "void bar()" "Foo"
|
|
|
|
// "void bar(int i = 0)" "Foo"
|
|
|
|
// Be wary, this is quickly quite verbose,
|
|
|
|
// items can end up truncated by the UIs.
|
|
|
|
bool detailedLabel = false;
|
2018-01-21 17:52:28 +00:00
|
|
|
};
|
|
|
|
Completion completion;
|
2018-01-19 03:25:23 +00:00
|
|
|
|
2018-02-21 04:26:17 +00:00
|
|
|
struct Xref {
|
|
|
|
// If true, |Location[]| response will include lexical container.
|
|
|
|
bool container = false;
|
|
|
|
// Maximum number of definition/reference/... results.
|
|
|
|
int maxNum = 300;
|
2018-02-11 01:50:44 +00:00
|
|
|
};
|
2018-02-21 04:26:17 +00:00
|
|
|
Xref xref;
|
2018-02-11 01:50:44 +00:00
|
|
|
|
2018-01-21 06:34:41 +00:00
|
|
|
struct Index {
|
2018-01-30 00:14:23 +00:00
|
|
|
// 0: none, 1: doxygen, 2: all comments
|
|
|
|
// 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
|
2018-01-24 06:54:54 +00:00
|
|
|
int comments = 2;
|
2018-01-31 19:10:20 +00:00
|
|
|
|
2018-02-01 04:21:16 +00:00
|
|
|
// Attempt to convert calls of make* functions to constructors based on
|
|
|
|
// hueristics.
|
|
|
|
//
|
|
|
|
// For example, this will show constructor calls for std::make_unique
|
|
|
|
// invocations. Specifically, cquery will try to attribute a ctor call
|
|
|
|
// whenever the function name starts with make (ignoring case).
|
|
|
|
bool attributeMakeCallsToCtor = true;
|
2018-01-21 06:34:41 +00:00
|
|
|
};
|
|
|
|
Index index;
|
|
|
|
|
2018-01-08 07:51:36 +00:00
|
|
|
//// For debugging
|
|
|
|
|
|
|
|
// Dump AST after parsing if some pattern matches the source filename.
|
|
|
|
std::vector<std::string> dumpAST;
|
2017-05-21 19:51:15 +00:00
|
|
|
};
|
2018-01-21 17:52:28 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::ClientCapability, snippetSupport);
|
add detailedLabel completion style
Some completion UI, such as Emacs' completion-at-point and company-lsp,
display completion item label and detail side by side.
This does not look right, when you see things like:
"foo" "int foo()"
"bar" "void bar(int i = 0)"
When this option is enabled, the completion item label is very detailed,
it shows the full signature of the candidate.
The detail just contains the completion item parent context.
Also, in this mode, functions with default arguments,
generates one more item per default argument
so that the right function call can be selected.
That is, you get something like:
"int foo()" "Foo"
"void bar()" "Foo"
"void bar(int i = 0)" "Foo"
Be wary, this is quickly quite verbose,
items can end up truncated by the UIs.
2018-02-03 17:32:55 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::Completion, filterAndSort, detailedLabel);
|
2018-02-21 04:26:17 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::Xref, container, maxNum);
|
2018-02-01 04:21:16 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::Index, comments, attributeMakeCallsToCtor);
|
2017-05-21 19:51:15 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config,
|
2018-02-20 00:19:57 +00:00
|
|
|
compilationDatabaseCommand,
|
2017-11-21 16:47:28 +00:00
|
|
|
compilationDatabaseDirectory,
|
2017-09-22 01:14:57 +00:00
|
|
|
cacheDirectory,
|
2018-01-07 02:56:15 +00:00
|
|
|
cacheFormat,
|
2017-10-25 01:02:15 +00:00
|
|
|
resourceDirectory,
|
2017-05-22 06:45:47 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
extraClangArguments,
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
indexWhitelist,
|
|
|
|
indexBlacklist,
|
|
|
|
logSkippedPathsForIndex,
|
2017-05-22 06:45:47 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
maxWorkspaceSearchResults,
|
2018-01-07 21:08:18 +00:00
|
|
|
sortWorkspaceSearchResults,
|
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
indexerCount,
|
|
|
|
enableIndexing,
|
2018-01-07 21:06:18 +00:00
|
|
|
progressReportFrequencyMs,
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
includeCompletionMaximumPathLength,
|
|
|
|
includeCompletionWhitelistLiteralEnding,
|
|
|
|
includeCompletionWhitelist,
|
|
|
|
includeCompletionBlacklist,
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
showDocumentLinksOnIncludes,
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
diagnosticsOnParse,
|
|
|
|
diagnosticsOnCodeCompletion,
|
2017-07-16 00:25:52 +00:00
|
|
|
|
2017-09-22 01:14:57 +00:00
|
|
|
codeLensOnLocalVariables,
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2017-11-19 12:57:16 +00:00
|
|
|
clientVersion,
|
2018-01-08 07:51:36 +00:00
|
|
|
|
2018-01-21 17:52:28 +00:00
|
|
|
client,
|
|
|
|
completion,
|
2018-02-21 04:26:17 +00:00
|
|
|
xref,
|
2018-01-21 06:34:41 +00:00
|
|
|
index,
|
|
|
|
|
2018-01-11 02:43:01 +00:00
|
|
|
dumpAST);
|
2017-12-05 07:57:41 +00:00
|
|
|
|
|
|
|
// Expected client version. We show an error if this doesn't match.
|
2017-12-24 03:23:29 +00:00
|
|
|
constexpr const int kExpectedClientVersion = 3;
|