diff --git a/src/clang_complete.cc b/src/clang_complete.cc index b5c2a745..7dfe3b51 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -135,6 +135,7 @@ void BuildDetailString(CXCompletionString completion_string, std::string& label, std::string& detail, std::string& insert, + lsInsertTextFormat& format, std::vector* parameters, bool include_snippets) { int num_chunks = clang_getNumCompletionChunks(completion_string); @@ -146,7 +147,7 @@ void BuildDetailString(CXCompletionString completion_string, case CXCompletionChunk_Optional: { CXCompletionString nested = clang_getCompletionChunkCompletionString(completion_string, i); - BuildDetailString(nested, label, detail, insert, parameters, + BuildDetailString(nested, label, detail, insert, format, parameters, include_snippets); break; } @@ -160,6 +161,7 @@ void BuildDetailString(CXCompletionString completion_string, if (include_snippets) { insert += "${" + std::to_string(parameters->size()) + ":" + text + "}"; + format = lsInsertTextFormat::Snippet; } break; } @@ -204,6 +206,7 @@ void BuildDetailString(CXCompletionString completion_string, // Put cursor between parentheses if snippets are not enabled if (!include_snippets) { insert += "$1"; + format = lsInsertTextFormat::Snippet; } break; case CXCompletionChunk_RightParen: @@ -260,8 +263,6 @@ void BuildDetailString(CXCompletionString completion_string, break; } } - - insert += "$0"; } void TryEnsureDocumentParsed(ClangCompleteManager* manager, @@ -420,8 +421,11 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { BuildDetailString( result.CompletionString, ls_completion_item.label, 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 == lsInsertTextFormat::Snippet) + ls_completion_item.insertText += "$0"; ls_completion_item.documentation = ToString( clang_getCompletionBriefComment(result.CompletionString)); diff --git a/src/language_server_api.h b/src/language_server_api.h index e0d306c7..21d5ce68 100644 --- a/src/language_server_api.h +++ b/src/language_server_api.h @@ -360,7 +360,7 @@ struct lsCompletionItem { // The format of the insert text. The format applies to both the `insertText` // property and the `newText` property of a provided `textEdit`. - lsInsertTextFormat insertTextFormat = lsInsertTextFormat::Snippet; + lsInsertTextFormat insertTextFormat = lsInsertTextFormat::PlainText; // An edit which is applied to a document when selecting this completion. When // an edit is provided the value of `insertText` is ignored.