Only set insertTextFormat to Snippet when we have placeholders

This commit is contained in:
Yuxuan Shui 2017-12-05 12:21:54 -05:00 committed by Jacob Dufault
parent dbeb4eb511
commit 2bd4671ddd
2 changed files with 8 additions and 4 deletions

View File

@ -135,6 +135,7 @@ void BuildDetailString(CXCompletionString completion_string,
std::string& label,
std::string& detail,
std::string& insert,
lsInsertTextFormat& format,
std::vector<std::string>* 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));

View File

@ -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.