diff --git a/src/clang_complete.cc b/src/clang_complete.cc index d199be8f..566e03d4 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -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"; } diff --git a/src/config.h b/src/config.h index 5f65f49b..09db234a 100644 --- a/src/config.h +++ b/src/config.h @@ -87,18 +87,23 @@ struct Config { // inform users their vscode client is too old and needs to be updated. optional 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 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. diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 0d0ecca9..c0629fb5 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -75,12 +75,20 @@ struct InitializeHandler : BaseMessageHandler { } } } - 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) { diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index 030959ec..6f061ee7 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -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.