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 <ivan.donchevskii@qt.io>
This commit is contained in:
Nikolai Kosjar
2018-10-25 14:05:31 +02:00
parent b385171eb8
commit 8bccd8a428

View File

@@ -175,10 +175,18 @@ void ClangAssistProposalItem::apply(TextDocumentManipulatorInterface &manipulato
cursorOffset = converter.placeholderPositions().at(0) - converter.text().size(); cursorOffset = converter.placeholderPositions().at(0) - converter.text().size();
} else if (ccr.completionKind == CodeCompletion::NamespaceCompletionKind) { } else if (ccr.completionKind == CodeCompletion::NamespaceCompletionKind) {
CompletionChunksToTextConverter converter; CompletionChunksToTextConverter converter;
converter.parseChunks(ccr.chunks); // Appends "::" after name space name converter.parseChunks(ccr.chunks); // Appends "::" after name space name
textToBeInserted = converter.text(); textToBeInserted = converter.text();
// Clang does not provide the "::" chunk consistently for namespaces, e.g.
//
// namespace a { namespace b { namespace c {} } }
// <CURSOR> // complete "a" ==> "a::"
// a::<CURSOR> // complete "b" ==> "b", not "b::"
//
// Remove "::" to avoid any confusion for now.
if (textToBeInserted.endsWith("::"))
textToBeInserted.chop(2);
} else if (!ccr.text.isEmpty()) { } else if (!ccr.text.isEmpty()) {
const CompletionSettings &completionSettings = const CompletionSettings &completionSettings =
TextEditorSettings::instance()->completionSettings(); TextEditorSettings::instance()->completionSettings();