Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
Store client capability snippetSupport into config
Browse files Browse the repository at this point in the history
Rename filterAndSortCompletionResponse to completion.filterAndSort
Rename index.builtin_types to index.buitinTypes
  • Loading branch information
MaskRay committed Jan 21, 2018
1 parent bbee82b commit 455423f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/clang_complete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
28 changes: 17 additions & 11 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,23 @@ struct Config {
// inform users their vscode client is too old and needs to be updated.
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
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 // /*
Expand All @@ -111,7 +116,9 @@ struct Config {
// Dump AST after parsing if some pattern matches the source filename.
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,
compilationDatabaseDirectory,
cacheDirectory,
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
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) {
Expand Down
4 changes: 2 additions & 2 deletions src/messages/text_document_completion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 455423f

Please sign in to comment.