LanguageClient: redo completion replacement logic

Instead of trying some magic when applying completion items just replace
the text from the current position back to the start of the word.

Change-Id: I03ac0f8c9bced88d21bd51f9e5cfa0a3ea25025a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2019-05-03 15:04:40 +02:00
parent a7f1fc2d6b
commit 5eca6c031f

View File

@@ -99,16 +99,11 @@ void LanguageClientCompletionItem::apply(TextDocumentManipulatorInterface &manip
if (auto edit = m_item.textEdit()) { if (auto edit = m_item.textEdit()) {
applyTextEdit(manipulator, *edit); applyTextEdit(manipulator, *edit);
} else { } else {
const QString textToInsert(m_item.insertText().value_or(text())); QTextCursor cursor = manipulator.textCursorAt(pos);
int length = 0; cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
for (auto it = textToInsert.crbegin(); it != textToInsert.crend(); ++it) { manipulator.replace(cursor.position(),
auto ch = *it; cursor.selectionEnd() - cursor.selectionStart(),
if (ch == manipulator.characterAt(pos - length - 1)) m_item.insertText().value_or(m_item.label()));
++length;
else if (length != 0)
length = 0;
}
manipulator.replace(pos - length, length, textToInsert);
} }
if (auto additionalEdits = m_item.additionalTextEdits()) { if (auto additionalEdits = m_item.additionalTextEdits()) {