Store client capability snippetSupport into config

Rename filterAndSortCompletionResponse to completion.filterAndSort
Rename index.builtin_types to index.buitinTypes
This commit is contained in:
Fangrui Song 2018-01-21 09:52:28 -08:00
parent 69d439ae8d
commit d4a4e15976
4 changed files with 31 additions and 16 deletions

View File

@ -447,8 +447,9 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
ls_completion_item.detail, ls_completion_item.insertText,
ls_completion_item.insertTextFormat,
&ls_completion_item.parameters_,
completion_manager->config_->enableSnippetInsertion);
if (ls_completion_item.insertTextFormat ==
completion_manager->config_->client.snippetSupport);
if (completion_manager->config_->client.snippetSupport &&
ls_completion_item.insertTextFormat ==
lsInsertTextFormat::Snippet) {
ls_completion_item.insertText += "$0";
}

View File

@ -87,18 +87,23 @@ struct Config {
// inform users their vscode client is too old and needs to be updated.
optional<int> clientVersion;
// If true parameter declarations are included in code completion when calling
// a function or method
bool enableSnippetInsertion = true;
// TODO Deprecated in favor of index.comments
int enableComments = 0;
// If true, filter and sort completion response.
bool filterAndSortCompletionResponse = true;
struct ClientCapability {
// TextDocumentClientCapabilities.completion.completionItem.snippetSupport
bool snippetSupport = false;
};
ClientCapability client;
struct Completion {
// If true, filter and sort completion response.
bool filterAndSort = true;
};
Completion completion;
struct Index {
bool builtin_types = false;
bool builtinTypes = false;
// 0: no; 1: Doxygen comment markers; 2: -fparse-all-comments, which includes
// plain // /*
@ -111,7 +116,9 @@ struct Config {
// Dump AST after parsing if some pattern matches the source filename.
std::vector<std::string> dumpAST;
};
MAKE_REFLECT_STRUCT(Config::Index, builtin_types, comments);
MAKE_REFLECT_STRUCT(Config::ClientCapability, snippetSupport);
MAKE_REFLECT_STRUCT(Config::Completion, filterAndSort);
MAKE_REFLECT_STRUCT(Config::Index, builtinTypes, comments);
MAKE_REFLECT_STRUCT(Config,
compilationDatabaseDirectory,
cacheDirectory,
@ -146,14 +153,13 @@ MAKE_REFLECT_STRUCT(Config,
codeLensOnLocalVariables,
clientVersion,
enableSnippetInsertion,
enableComments,
client,
completion,
index,
filterAndSortCompletionResponse,
dumpAST);
// Expected client version. We show an error if this doesn't match.

View File

@ -75,12 +75,20 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
}
}
}
g_index_builtin_types = config->index.builtin_types;
g_index_builtin_types = config->index.builtinTypes;
// TODO Remove enableComments
if (config->index.comments > 0)
config->enableComments = config->index.comments;
g_enable_comments = config->enableComments;
// Client capabilities
if (request->params.capabilities.textDocument) {
const auto& cap = *request->params.capabilities.textDocument;
if (cap.completion && cap.completion->completionItem)
config->client.snippetSupport =
cap.completion->completionItem->snippetSupport.value_or(false);
}
// Check client version.
if (config->clientVersion.has_value() &&
*config->clientVersion != kExpectedClientVersion) {

View File

@ -309,7 +309,7 @@ struct TextDocumentCompletionHandler : MessageHandler {
TrimInPlace(buffer_line);
FilterAndSortCompletionResponse(&out, buffer_line,
config->filterAndSortCompletionResponse);
config->completion.filterAndSort);
QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out);
} else {
// If existing completion is empty, dont return clang-based completion
@ -337,7 +337,7 @@ struct TextDocumentCompletionHandler : MessageHandler {
// Emit completion results.
FilterAndSortCompletionResponse(
&out, existing_completion,
config->filterAndSortCompletionResponse);
config->completion.filterAndSort);
QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out);
// Cache completion results.