From 8bccd8a428c8bd21e77a3af93c4cdb881e2882cb Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Thu, 25 Oct 2018 14:05:31 +0200 Subject: [PATCH] Clang: Do not insert "::" after namespace completion ...as currently libclang does not provide "::" consistently and it confuses users. Ideally, once libclang provides it consistently, we probably want to insert "::", but allow to "overtype" it by the user, similar to what we do with function parentheses. That is, if the user accepts such a completion and types "::" due to muscle memory, he should not end up with "::::". Change-Id: Ibfd19c22457641956ace0ba976672eddc51ecc88 Reviewed-by: Ivan Donchevskii --- .../clangcodemodel/clangassistproposalitem.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/plugins/clangcodemodel/clangassistproposalitem.cpp b/src/plugins/clangcodemodel/clangassistproposalitem.cpp index 6fcbed054f5..d9e1c7e454a 100644 --- a/src/plugins/clangcodemodel/clangassistproposalitem.cpp +++ b/src/plugins/clangcodemodel/clangassistproposalitem.cpp @@ -175,10 +175,18 @@ void ClangAssistProposalItem::apply(TextDocumentManipulatorInterface &manipulato cursorOffset = converter.placeholderPositions().at(0) - converter.text().size(); } else if (ccr.completionKind == CodeCompletion::NamespaceCompletionKind) { CompletionChunksToTextConverter converter; - converter.parseChunks(ccr.chunks); // Appends "::" after name space name - textToBeInserted = converter.text(); + + // Clang does not provide the "::" chunk consistently for namespaces, e.g. + // + // namespace a { namespace b { namespace c {} } } + // // complete "a" ==> "a::" + // a:: // complete "b" ==> "b", not "b::" + // + // Remove "::" to avoid any confusion for now. + if (textToBeInserted.endsWith("::")) + textToBeInserted.chop(2); } else if (!ccr.text.isEmpty()) { const CompletionSettings &completionSettings = TextEditorSettings::instance()->completionSettings();