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
|
2018-03-31 03:16:33 +00:00
|
|
|
`initialize` request to the ccls language server. The only required option is
|
2018-01-30 17:04:01 +00:00
|
|
|
`cacheDirectory`, which is where index files will be stored.
|
2018-01-30 00:14:23 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
"initializationOptions": {
|
2018-03-31 03:16:33 +00:00
|
|
|
"cacheDirectory": "/tmp/ccls"
|
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-02-22 05:50:36 +00:00
|
|
|
'--init={"index": {"comments": 2, "whitelist": ["."]}}'
|
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.
|
|
|
|
//
|
2018-04-14 23:48:56 +00:00
|
|
|
// "binary" uses a compact binary serialization format.
|
|
|
|
// It is not schema-aware and you need to re-index whenever a struct
|
2018-01-30 00:14:23 +00:00
|
|
|
// member has changed.
|
2018-04-14 23:48:56 +00:00
|
|
|
SerializeFormat cacheFormat = SerializeFormat::Binary;
|
2017-11-26 22:20:43 +00:00
|
|
|
|
2018-05-05 22:29:17 +00:00
|
|
|
struct Clang {
|
|
|
|
// Additional arguments to pass to clang.
|
|
|
|
std::vector<std::string> extraArgs;
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2018-05-05 22:29:17 +00:00
|
|
|
// Value to use for clang -resource-dir if not specified.
|
|
|
|
//
|
|
|
|
// This option defaults to clang -print-resource-dir and should not be
|
|
|
|
// specified unless you are using an esoteric configuration.
|
|
|
|
std::string resourceDir;
|
|
|
|
} clang;
|
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;
|
2018-05-05 22:29:17 +00:00
|
|
|
} client;
|
2018-01-21 17:52:28 +00:00
|
|
|
|
2018-02-22 05:50:36 +00:00
|
|
|
struct CodeLens {
|
|
|
|
// Enables code lens on parameter and function variables.
|
|
|
|
bool localVariables = true;
|
|
|
|
} codeLens;
|
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
|
|
|
|
2018-02-22 05:50:36 +00:00
|
|
|
struct Completion {
|
2018-04-14 18:57:23 +00:00
|
|
|
// 0: case-insensitive
|
|
|
|
// 1: case-folded, i.e. insensitive if no input character is uppercase.
|
|
|
|
// 2: case-sensitive
|
|
|
|
int caseSensitivity = 2;
|
|
|
|
|
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-19 03:25:23 +00:00
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
// On large projects, completion can take a long time. By default if ccls
|
2018-02-22 07:13:42 +00:00
|
|
|
// receives multiple completion requests while completion is still running
|
|
|
|
// it will only service the newest request. If this is set to false then all
|
|
|
|
// completion requests will be serviced.
|
|
|
|
bool dropOldRequests = true;
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
// If true, filter and sort completion response. ccls filters and sorts
|
2018-02-22 05:50:36 +00:00
|
|
|
// 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;
|
2018-02-11 01:50:44 +00:00
|
|
|
|
2018-02-22 05:50:36 +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> includeBlacklist;
|
|
|
|
|
|
|
|
// 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 includeMaxPathSize = 30;
|
|
|
|
|
|
|
|
// Whitelist that file paths will be tested against. If a file path does not
|
2018-02-22 07:34:32 +00:00
|
|
|
// end in one of these values, it will not be considered for
|
|
|
|
// auto-completion. An example value is { ".h", ".hpp" }
|
2018-02-22 05:50:36 +00:00
|
|
|
//
|
|
|
|
// This is significantly faster than using a regex.
|
|
|
|
std::vector<std::string> includeSuffixWhitelist = {".h", ".hpp", ".hh"};
|
2018-01-31 19:10:20 +00:00
|
|
|
|
2018-02-22 05:50:36 +00:00
|
|
|
std::vector<std::string> includeWhitelist;
|
|
|
|
} completion;
|
|
|
|
|
2018-03-06 01:18:33 +00:00
|
|
|
struct Diagnostics {
|
|
|
|
// Like index.{whitelist,blacklist}, don't publish diagnostics to
|
|
|
|
// blacklisted files.
|
|
|
|
std::vector<std::string> blacklist;
|
|
|
|
|
2018-03-31 03:16:33 +00:00
|
|
|
// How often should ccls publish diagnostics in completion?
|
2018-03-06 01:18:33 +00:00
|
|
|
// -1: never
|
|
|
|
// 0: as often as possible
|
|
|
|
// xxx: at most every xxx milliseconds
|
|
|
|
int frequencyMs = 0;
|
|
|
|
|
|
|
|
// If true, diagnostics from a full document parse will be reported.
|
|
|
|
bool onParse = true;
|
|
|
|
|
2018-05-09 05:01:58 +00:00
|
|
|
// If true, diagnostics from typing will be reported.
|
|
|
|
bool onType = true;
|
|
|
|
|
2018-03-06 01:18:33 +00:00
|
|
|
std::vector<std::string> whitelist;
|
|
|
|
} diagnostics;
|
|
|
|
|
2018-03-09 08:23:32 +00:00
|
|
|
// Semantic highlighting
|
|
|
|
struct Highlight {
|
|
|
|
// Like index.{whitelist,blacklist}, don't publish semantic highlighting to
|
|
|
|
// blacklisted files.
|
|
|
|
std::vector<std::string> blacklist;
|
|
|
|
|
|
|
|
std::vector<std::string> whitelist;
|
|
|
|
} highlight;
|
|
|
|
|
2018-02-22 05:50:36 +00:00
|
|
|
struct Index {
|
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
|
2018-03-31 03:16:33 +00:00
|
|
|
// invocations. Specifically, ccls will try to attribute a ctor call
|
2018-02-01 04:21:16 +00:00
|
|
|
// whenever the function name starts with make (ignoring case).
|
|
|
|
bool attributeMakeCallsToCtor = true;
|
2018-02-22 05:50:36 +00:00
|
|
|
|
|
|
|
// If a translation unit's absolute path matches any EMCAScript regex in the
|
2018-02-22 07:34:32 +00:00
|
|
|
// 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.
|
2018-02-22 05:50:36 +00:00
|
|
|
// `std::regex_search(path, regex, std::regex_constants::match_any)`
|
|
|
|
//
|
|
|
|
// Example: `ash/.*\.cc`
|
|
|
|
std::vector<std::string> blacklist;
|
|
|
|
|
|
|
|
// 0: none, 1: Doxygen, 2: all comments
|
|
|
|
// Plugin support for clients:
|
|
|
|
// - https://github.com/emacs-lsp/lsp-ui
|
|
|
|
// - https://github.com/autozimu/LanguageClient-neovim/issues/224
|
|
|
|
int comments = 2;
|
|
|
|
|
|
|
|
// If false, the indexer will be disabled.
|
|
|
|
bool enabled = true;
|
|
|
|
|
2018-04-04 06:05:41 +00:00
|
|
|
// Allow indexing on textDocument/didChange.
|
|
|
|
// May be too slow for big projects, so it is off by default.
|
|
|
|
bool onDidChange = false;
|
|
|
|
|
2018-06-02 07:33:12 +00:00
|
|
|
// Whether to reparse a file if write times of its dependencies have
|
|
|
|
// changed. The file will always be reparsed if its own write time changes.
|
|
|
|
// 0: no, 1: only after initial load of project, 2: yes
|
|
|
|
int reparseForDependency = 2;
|
|
|
|
|
2018-02-22 05:50:36 +00:00
|
|
|
// Number of indexer threads. If 0, 80% of cores are used.
|
|
|
|
int threads = 0;
|
|
|
|
|
|
|
|
std::vector<std::string> whitelist;
|
|
|
|
} index;
|
|
|
|
|
2018-06-01 21:22:55 +00:00
|
|
|
// Disable semantic highlighting for files larger than the size.
|
|
|
|
int64_t largeFileSize = 2 * 1024 * 1024;
|
|
|
|
|
2018-02-22 05:50:36 +00:00
|
|
|
struct WorkspaceSymbol {
|
2018-04-14 18:57:23 +00:00
|
|
|
int caseSensitivity = 1;
|
2018-02-22 05:50:36 +00:00
|
|
|
// Maximum workspace search results.
|
|
|
|
int maxNum = 1000;
|
|
|
|
// 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 sort = true;
|
|
|
|
} workspaceSymbol;
|
|
|
|
|
|
|
|
struct Xref {
|
|
|
|
// If true, |Location[]| response will include lexical container.
|
|
|
|
bool container = false;
|
|
|
|
// Maximum number of definition/reference/... results.
|
|
|
|
int maxNum = 2000;
|
|
|
|
} xref;
|
2017-05-21 19:51:15 +00:00
|
|
|
};
|
2018-05-05 22:29:17 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::Clang, extraArgs, resourceDir);
|
2018-01-21 17:52:28 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::ClientCapability, snippetSupport);
|
2018-02-22 05:50:36 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::CodeLens, localVariables);
|
|
|
|
MAKE_REFLECT_STRUCT(Config::Completion,
|
2018-04-14 18:57:23 +00:00
|
|
|
caseSensitivity,
|
2018-05-09 05:01:58 +00:00
|
|
|
dropOldRequests,
|
2018-02-22 05:50:36 +00:00
|
|
|
detailedLabel,
|
|
|
|
filterAndSort,
|
|
|
|
includeBlacklist,
|
|
|
|
includeMaxPathSize,
|
|
|
|
includeSuffixWhitelist,
|
|
|
|
includeWhitelist);
|
2018-03-06 01:18:33 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::Diagnostics,
|
|
|
|
blacklist,
|
|
|
|
frequencyMs,
|
|
|
|
onParse,
|
2018-05-09 05:01:58 +00:00
|
|
|
onType,
|
2018-03-06 01:18:33 +00:00
|
|
|
whitelist)
|
2018-03-20 02:51:42 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::Highlight, blacklist, whitelist)
|
2018-02-22 05:50:36 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::Index,
|
|
|
|
attributeMakeCallsToCtor,
|
|
|
|
blacklist,
|
|
|
|
comments,
|
|
|
|
enabled,
|
2018-04-04 06:05:41 +00:00
|
|
|
onDidChange,
|
2018-06-02 07:33:12 +00:00
|
|
|
reparseForDependency,
|
2018-02-22 05:50:36 +00:00
|
|
|
threads,
|
|
|
|
whitelist);
|
2018-04-14 18:57:23 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::WorkspaceSymbol, caseSensitivity, maxNum, sort);
|
2018-02-21 04:26:17 +00:00
|
|
|
MAKE_REFLECT_STRUCT(Config::Xref, container, maxNum);
|
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,
|
2018-01-08 07:51:36 +00:00
|
|
|
|
2018-05-05 22:29:17 +00:00
|
|
|
clang,
|
2018-01-21 17:52:28 +00:00
|
|
|
client,
|
2018-02-22 05:50:36 +00:00
|
|
|
codeLens,
|
2018-01-21 17:52:28 +00:00
|
|
|
completion,
|
2018-03-06 01:18:33 +00:00
|
|
|
diagnostics,
|
2018-03-09 08:23:32 +00:00
|
|
|
highlight,
|
2018-01-21 06:34:41 +00:00
|
|
|
index,
|
2018-06-01 21:22:55 +00:00
|
|
|
largeFileSize,
|
2018-02-22 05:50:36 +00:00
|
|
|
workspaceSymbol,
|
2018-04-09 07:52:04 +00:00
|
|
|
xref);
|
2017-12-05 07:57:41 +00:00
|
|
|
|
2018-06-01 21:22:55 +00:00
|
|
|
extern Config* g_config;
|
2018-05-05 22:29:17 +00:00
|
|
|
thread_local extern int g_thread_id;
|