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.detail, ls_completion_item.insertText,
ls_completion_item.insertTextFormat, ls_completion_item.insertTextFormat,
&ls_completion_item.parameters_, &ls_completion_item.parameters_,
completion_manager->config_->enableSnippetInsertion); completion_manager->config_->client.snippetSupport);
if (ls_completion_item.insertTextFormat == if (completion_manager->config_->client.snippetSupport &&
ls_completion_item.insertTextFormat ==
lsInsertTextFormat::Snippet) { lsInsertTextFormat::Snippet) {
ls_completion_item.insertText += "$0"; 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. // inform users their vscode client is too old and needs to be updated.
optional<int> clientVersion; 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 // TODO Deprecated in favor of index.comments
int enableComments = 0; int enableComments = 0;
// If true, filter and sort completion response. struct ClientCapability {
bool filterAndSortCompletionResponse = true; // 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 { struct Index {
bool builtin_types = false; bool builtinTypes = false;
// 0: no; 1: Doxygen comment markers; 2: -fparse-all-comments, which includes // 0: no; 1: Doxygen comment markers; 2: -fparse-all-comments, which includes
// plain // /* // plain // /*
@ -111,7 +116,9 @@ struct Config {
// Dump AST after parsing if some pattern matches the source filename. // Dump AST after parsing if some pattern matches the source filename.
std::vector<std::string> dumpAST; 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, MAKE_REFLECT_STRUCT(Config,
compilationDatabaseDirectory, compilationDatabaseDirectory,
cacheDirectory, cacheDirectory,
@ -146,14 +153,13 @@ MAKE_REFLECT_STRUCT(Config,
codeLensOnLocalVariables, codeLensOnLocalVariables,
clientVersion, clientVersion,
enableSnippetInsertion,
enableComments, enableComments,
client,
completion,
index, index,
filterAndSortCompletionResponse,
dumpAST); dumpAST);
// Expected client version. We show an error if this doesn't match. // 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 // TODO Remove enableComments
if (config->index.comments > 0) if (config->index.comments > 0)
config->enableComments = config->index.comments; config->enableComments = config->index.comments;
g_enable_comments = config->enableComments; 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. // Check client version.
if (config->clientVersion.has_value() && if (config->clientVersion.has_value() &&
*config->clientVersion != kExpectedClientVersion) { *config->clientVersion != kExpectedClientVersion) {

View File

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