mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 00:55:08 +00:00
Add option to disable insertion of snippets when completing a method/function call.
This commit is contained in:
parent
0a3064fe34
commit
5842dd5d60
@ -135,7 +135,8 @@ void BuildDetailString(CXCompletionString completion_string,
|
|||||||
std::string& label,
|
std::string& label,
|
||||||
std::string& detail,
|
std::string& detail,
|
||||||
std::string& insert,
|
std::string& insert,
|
||||||
std::vector<std::string>* parameters) {
|
std::vector<std::string>* parameters,
|
||||||
|
bool include_snippets) {
|
||||||
int num_chunks = clang_getNumCompletionChunks(completion_string);
|
int num_chunks = clang_getNumCompletionChunks(completion_string);
|
||||||
for (int i = 0; i < num_chunks; ++i) {
|
for (int i = 0; i < num_chunks; ++i) {
|
||||||
CXCompletionChunkKind kind =
|
CXCompletionChunkKind kind =
|
||||||
@ -145,7 +146,7 @@ void BuildDetailString(CXCompletionString completion_string,
|
|||||||
case CXCompletionChunk_Optional: {
|
case CXCompletionChunk_Optional: {
|
||||||
CXCompletionString nested =
|
CXCompletionString nested =
|
||||||
clang_getCompletionChunkCompletionString(completion_string, i);
|
clang_getCompletionChunkCompletionString(completion_string, i);
|
||||||
BuildDetailString(nested, label, detail, insert, parameters);
|
BuildDetailString(nested, label, detail, insert, parameters, include_snippets);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +155,8 @@ void BuildDetailString(CXCompletionString completion_string,
|
|||||||
ToString(clang_getCompletionChunkText(completion_string, i));
|
ToString(clang_getCompletionChunkText(completion_string, i));
|
||||||
parameters->push_back(text);
|
parameters->push_back(text);
|
||||||
detail += text;
|
detail += text;
|
||||||
insert += "${" + std::to_string(parameters->size()) + ":" + text + "}";
|
// Add parameter declarations as snippets if enabled
|
||||||
|
if (include_snippets) { insert += "${" + std::to_string(parameters->size()) + ":" + text + "}"; }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +197,8 @@ void BuildDetailString(CXCompletionString completion_string,
|
|||||||
case CXCompletionChunk_LeftParen:
|
case CXCompletionChunk_LeftParen:
|
||||||
detail += "(";
|
detail += "(";
|
||||||
insert += "(";
|
insert += "(";
|
||||||
|
// Put cursor between parentheses if snippets are not enabled
|
||||||
|
if (!include_snippets) { insert += "$1"; }
|
||||||
break;
|
break;
|
||||||
case CXCompletionChunk_RightParen:
|
case CXCompletionChunk_RightParen:
|
||||||
detail += ")";
|
detail += ")";
|
||||||
@ -226,7 +230,8 @@ void BuildDetailString(CXCompletionString completion_string,
|
|||||||
break;
|
break;
|
||||||
case CXCompletionChunk_Comma:
|
case CXCompletionChunk_Comma:
|
||||||
detail += ", ";
|
detail += ", ";
|
||||||
insert += ", ";
|
// Only put comma's between parentheses if snippets are enabled
|
||||||
|
if (include_snippets) { insert += ", "; }
|
||||||
break;
|
break;
|
||||||
case CXCompletionChunk_Colon:
|
case CXCompletionChunk_Colon:
|
||||||
detail += ":";
|
detail += ":";
|
||||||
@ -247,6 +252,8 @@ void BuildDetailString(CXCompletionString completion_string,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
insert += "$0";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TryEnsureDocumentParsed(ClangCompleteManager* manager,
|
void TryEnsureDocumentParsed(ClangCompleteManager* manager,
|
||||||
@ -405,8 +412,9 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
|
|||||||
BuildDetailString(result.CompletionString, ls_completion_item.label,
|
BuildDetailString(result.CompletionString, ls_completion_item.label,
|
||||||
ls_completion_item.detail,
|
ls_completion_item.detail,
|
||||||
ls_completion_item.insertText,
|
ls_completion_item.insertText,
|
||||||
&ls_completion_item.parameters_);
|
&ls_completion_item.parameters_,
|
||||||
ls_completion_item.insertText += "$0";
|
completion_manager->config_->enableSnippetInsertion);
|
||||||
|
|
||||||
ls_completion_item.documentation = ToString(
|
ls_completion_item.documentation = ToString(
|
||||||
clang_getCompletionBriefComment(result.CompletionString));
|
clang_getCompletionBriefComment(result.CompletionString));
|
||||||
ls_completion_item.sortText =
|
ls_completion_item.sortText =
|
||||||
|
@ -64,6 +64,9 @@ struct Config {
|
|||||||
|
|
||||||
// Version of the client.
|
// Version of the client.
|
||||||
int clientVersion = 0;
|
int clientVersion = 0;
|
||||||
|
|
||||||
|
// If true parameter declarations are included in code completion when calling a function or method
|
||||||
|
bool enableSnippetInsertion = true;
|
||||||
};
|
};
|
||||||
MAKE_REFLECT_STRUCT(Config,
|
MAKE_REFLECT_STRUCT(Config,
|
||||||
cacheDirectory,
|
cacheDirectory,
|
||||||
@ -93,4 +96,5 @@ MAKE_REFLECT_STRUCT(Config,
|
|||||||
|
|
||||||
codeLensOnLocalVariables,
|
codeLensOnLocalVariables,
|
||||||
|
|
||||||
clientVersion);
|
clientVersion,
|
||||||
|
enableSnippetInsertion);
|
Loading…
Reference in New Issue
Block a user