2018-08-21 05:27:52 +00:00
|
|
|
/* Copyright 2017-2018 ccls Authors
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==============================================================================*/
|
|
|
|
|
2017-05-21 19:51:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
#include "serializer.hh"
|
2017-05-21 19:51:15 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2018-10-28 17:49:31 +00:00
|
|
|
namespace ccls {
|
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-09-08 17:37:48 +00:00
|
|
|
`initialize` request to the ccls language server.
|
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-10-08 05:02:28 +00:00
|
|
|
// **Not available for configuration**
|
|
|
|
std::string fallbackFolder;
|
|
|
|
std::vector<std::string> workspaceFolders;
|
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;
|
2018-08-23 00:40:50 +00:00
|
|
|
// Cache directory for indexed files, either absolute or relative to the
|
|
|
|
// project root.
|
2018-09-08 17:37:48 +00:00
|
|
|
// If empty, cache will be stored in memory.
|
2018-08-23 00:40:50 +00:00
|
|
|
std::string cacheDirectory = ".ccls-cache";
|
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.
|
2018-09-08 17:37:48 +00:00
|
|
|
// It is not schema-aware and you need to re-index whenever an internal 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
|
|
|
|
2019-02-10 10:17:07 +00:00
|
|
|
struct ServerCap {
|
|
|
|
struct DocumentOnTypeFormattingOptions {
|
|
|
|
std::string firstTriggerCharacter = "}";
|
|
|
|
std::vector<const char *> moreTriggerCharacter;
|
|
|
|
} documentOnTypeFormattingProvider;
|
|
|
|
|
|
|
|
// Set to false if you don't want folding ranges.
|
|
|
|
bool foldingRangeProvider = true;
|
|
|
|
|
|
|
|
struct Workspace {
|
|
|
|
struct WorkspaceFolders {
|
|
|
|
// Set to false if you don't want workspace folders.
|
|
|
|
bool supported = true;
|
|
|
|
|
|
|
|
bool changeNotifications = true;
|
|
|
|
} workspaceFolders;
|
|
|
|
} workspace;
|
|
|
|
} capabilities;
|
|
|
|
|
2018-05-05 22:29:17 +00:00
|
|
|
struct Clang {
|
2018-09-04 20:02:48 +00:00
|
|
|
// Arguments that should be excluded, e.g. ["-fopenmp", "-Wall"]
|
2018-09-08 17:37:48 +00:00
|
|
|
//
|
|
|
|
// e.g. If your project is built by GCC and has an option thag clang does not understand.
|
2018-09-04 20:02:48 +00:00
|
|
|
std::vector<std::string> excludeArgs;
|
|
|
|
|
2018-05-05 22:29:17 +00:00
|
|
|
// Additional arguments to pass to clang.
|
|
|
|
std::vector<std::string> extraArgs;
|
2017-05-21 19:51:15 +00:00
|
|
|
|
2018-09-16 18:07:15 +00:00
|
|
|
// Translate absolute paths in compile_commands.json entries, .ccls options
|
|
|
|
// and cache files. This allows to reuse cache files built otherwhere if the
|
|
|
|
// source paths are different.
|
|
|
|
//
|
|
|
|
// This is a list of colon-separated strings, e.g. ["/container:/host"]
|
|
|
|
//
|
|
|
|
// An entry of "clang -I /container/include /container/a.cc" will be
|
|
|
|
// translated to "clang -I /host/include /host/a.cc". This is simple string
|
|
|
|
// replacement, so "clang /prefix/container/a.cc" will become "clang
|
|
|
|
// /prefix/host/a.cc".
|
|
|
|
std::vector<std::string> pathMappings;
|
|
|
|
|
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 {
|
2018-09-16 23:32:06 +00:00
|
|
|
// TextDocumentClientCapabilities.documentSymbol.hierarchicalDocumentSymbolSupport
|
2018-09-13 21:01:37 +00:00
|
|
|
bool hierarchicalDocumentSymbolSupport = true;
|
2018-12-17 03:53:00 +00:00
|
|
|
// TextDocumentClientCapabilities.definition.linkSupport
|
|
|
|
bool linkSupport = true;
|
2018-01-21 17:52:28 +00:00
|
|
|
// TextDocumentClientCapabilities.completion.completionItem.snippetSupport
|
2018-09-13 21:01:37 +00:00
|
|
|
bool snippetSupport = true;
|
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.
|
2018-09-11 05:37:01 +00:00
|
|
|
bool detailedLabel = true;
|
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-09-11 05:37:01 +00:00
|
|
|
// Functions with default arguments, generate one more item per default
|
|
|
|
// argument. 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 duplicateOptional = 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-10-03 16:15:09 +00:00
|
|
|
// Maxmum number of results.
|
|
|
|
int maxNum = 100;
|
|
|
|
|
2018-09-30 03:26:55 +00:00
|
|
|
struct Include {
|
|
|
|
// 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> blacklist;
|
|
|
|
|
|
|
|
// 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 maxPathSize = 30;
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
std::vector<std::string> suffixWhitelist = {".h", ".hpp", ".hh", ".inc"};
|
|
|
|
|
|
|
|
std::vector<std::string> whitelist;
|
|
|
|
} include;
|
2018-02-22 05:50:36 +00:00
|
|
|
} 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-09-22 08:37:00 +00:00
|
|
|
// Time to wait before computing diagnostics for textDocument/didChange.
|
|
|
|
// -1: disable diagnostics on change
|
|
|
|
// 0: immediately
|
|
|
|
// positive (e.g. 500): wait for 500 milliseconds. didChange requests in
|
|
|
|
// this period of time will only cause one computation.
|
|
|
|
int onChange = 1000;
|
2018-03-06 01:18:33 +00:00
|
|
|
|
2018-09-22 08:37:00 +00:00
|
|
|
// Time to wait before computing diagnostics for textDocument/didOpen.
|
|
|
|
int onOpen = 0;
|
2018-03-06 01:18:33 +00:00
|
|
|
|
2018-09-22 08:37:00 +00:00
|
|
|
// Time to wait before computing diagnostics for textDocument/didSave.
|
|
|
|
int onSave = 0;
|
2018-09-08 23:00:14 +00:00
|
|
|
|
2018-09-08 19:07:43 +00:00
|
|
|
bool spellChecking = 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 {
|
2018-09-30 03:26:55 +00:00
|
|
|
// Disable semantic highlighting for files larger than the size.
|
|
|
|
int64_t largeFileSize = 2 * 1024 * 1024;
|
|
|
|
|
2018-07-14 20:56:00 +00:00
|
|
|
// true: LSP line/character; false: position
|
|
|
|
bool lsRanges = false;
|
|
|
|
|
2018-03-09 08:23:32 +00:00
|
|
|
// 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 {
|
|
|
|
// 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;
|
|
|
|
|
2018-09-24 01:45:41 +00:00
|
|
|
// By default, all project entries will be indexed on initialization. Use
|
|
|
|
// these two options to exclude some. They can still be indexed after you
|
|
|
|
// open them.
|
|
|
|
std::vector<std::string> initialBlacklist;
|
|
|
|
std::vector<std::string> initialWhitelist;
|
|
|
|
|
2019-02-10 10:17:07 +00:00
|
|
|
// If a variable initializer/macro replacement-list has fewer than this many
|
|
|
|
// lines, include the initializer in detailed_name.
|
|
|
|
int maxInitializerLines = 5;
|
|
|
|
|
2018-09-02 21:51:25 +00:00
|
|
|
// If not 0, a file will be indexed in each tranlation unit that includes it.
|
|
|
|
int multiVersion = 0;
|
|
|
|
|
2018-09-03 19:21:32 +00:00
|
|
|
// If multiVersion != 0, files that match blacklist but not whitelist will
|
|
|
|
// still only be indexed for one version.
|
|
|
|
std::vector<std::string> multiVersionBlacklist;
|
|
|
|
std::vector<std::string> multiVersionWhitelist;
|
|
|
|
|
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.
|
2018-09-08 06:40:22 +00:00
|
|
|
bool onChange = false;
|
2018-04-04 06:05:41 +00:00
|
|
|
|
2018-09-24 06:02:19 +00:00
|
|
|
// Number of indexer threads. If 0, 80% of cores are used.
|
|
|
|
int threads = 0;
|
|
|
|
|
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.
|
2018-09-30 03:26:55 +00:00
|
|
|
// 0: no, 1: only during initial load of project, 2: yes
|
2018-09-24 06:02:19 +00:00
|
|
|
int trackDependency = 2;
|
2018-02-22 05:50:36 +00:00
|
|
|
|
|
|
|
std::vector<std::string> whitelist;
|
|
|
|
} index;
|
|
|
|
|
2018-12-25 06:20:00 +00:00
|
|
|
struct Request {
|
|
|
|
// If the document of a request has not been indexed, wait up to this many
|
|
|
|
// milleseconds before reporting error.
|
|
|
|
int64_t timeout = 5000;
|
|
|
|
} request;
|
|
|
|
|
2018-12-01 06:44:52 +00:00
|
|
|
struct Session {
|
|
|
|
int maxNum = 10;
|
|
|
|
} session;
|
|
|
|
|
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 {
|
|
|
|
// Maximum number of definition/reference/... results.
|
|
|
|
int maxNum = 2000;
|
|
|
|
} xref;
|
2017-05-21 19:51:15 +00:00
|
|
|
};
|
2019-02-10 10:17:07 +00:00
|
|
|
REFLECT_STRUCT(Config::ServerCap::DocumentOnTypeFormattingOptions,
|
|
|
|
firstTriggerCharacter, moreTriggerCharacter);
|
|
|
|
REFLECT_STRUCT(Config::ServerCap::Workspace::WorkspaceFolders, supported,
|
|
|
|
changeNotifications);
|
|
|
|
REFLECT_STRUCT(Config::ServerCap::Workspace, workspaceFolders);
|
|
|
|
REFLECT_STRUCT(Config::ServerCap, documentOnTypeFormattingProvider,
|
|
|
|
foldingRangeProvider, workspace);
|
2018-12-02 23:53:33 +00:00
|
|
|
REFLECT_STRUCT(Config::Clang, excludeArgs, extraArgs, pathMappings,
|
2018-12-17 03:53:00 +00:00
|
|
|
resourceDir);
|
2018-12-02 23:53:33 +00:00
|
|
|
REFLECT_STRUCT(Config::ClientCapability, hierarchicalDocumentSymbolSupport,
|
2018-12-17 03:53:00 +00:00
|
|
|
linkSupport, snippetSupport);
|
2018-12-02 23:53:33 +00:00
|
|
|
REFLECT_STRUCT(Config::CodeLens, localVariables);
|
|
|
|
REFLECT_STRUCT(Config::Completion::Include, blacklist, maxPathSize,
|
2018-12-17 03:53:00 +00:00
|
|
|
suffixWhitelist, whitelist);
|
2018-12-02 23:53:33 +00:00
|
|
|
REFLECT_STRUCT(Config::Completion, caseSensitivity, detailedLabel,
|
2018-12-17 03:53:00 +00:00
|
|
|
dropOldRequests, duplicateOptional, filterAndSort, include,
|
|
|
|
maxNum);
|
2018-12-02 23:53:33 +00:00
|
|
|
REFLECT_STRUCT(Config::Diagnostics, blacklist, onChange, onOpen, onSave,
|
2018-12-17 03:53:00 +00:00
|
|
|
spellChecking, whitelist)
|
|
|
|
REFLECT_STRUCT(Config::Highlight, largeFileSize, lsRanges, blacklist, whitelist)
|
2018-12-02 23:53:33 +00:00
|
|
|
REFLECT_STRUCT(Config::Index, blacklist, comments, initialBlacklist,
|
2019-02-10 10:17:07 +00:00
|
|
|
initialWhitelist, maxInitializerLines, multiVersion,
|
|
|
|
multiVersionBlacklist, multiVersionWhitelist, onChange, threads,
|
|
|
|
trackDependency, whitelist);
|
2018-12-25 06:20:00 +00:00
|
|
|
REFLECT_STRUCT(Config::Request, timeout);
|
2018-12-02 23:53:33 +00:00
|
|
|
REFLECT_STRUCT(Config::Session, maxNum);
|
|
|
|
REFLECT_STRUCT(Config::WorkspaceSymbol, caseSensitivity, maxNum, sort);
|
|
|
|
REFLECT_STRUCT(Config::Xref, maxNum);
|
2018-12-17 03:53:00 +00:00
|
|
|
REFLECT_STRUCT(Config, compilationDatabaseCommand, compilationDatabaseDirectory,
|
2019-02-10 10:17:07 +00:00
|
|
|
cacheDirectory, cacheFormat, capabilities, clang, client,
|
|
|
|
codeLens, completion, diagnostics, highlight, index, request,
|
|
|
|
session, workspaceSymbol, xref);
|
2018-08-09 17:08:14 +00:00
|
|
|
|
|
|
|
extern Config *g_config;
|
2018-09-16 18:07:15 +00:00
|
|
|
|
|
|
|
void DoPathMapping(std::string &arg);
|
|
|
|
}
|