forked from qt-creator/qt-creator
Clang: fix completion for incomplete includes
Complete includes when one choice exists. Fix complete in the middle. Task-number: QTCREATORBUG-15710 Change-Id: Iec794c17aabc8de47f981382f4b4286b9325827d Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -63,7 +63,7 @@ bool ClangAssistProposalItem::prematurelyApplies(const QChar &typedCharacter) co
|
|||||||
|
|
||||||
bool ClangAssistProposalItem::implicitlyApplies() const
|
bool ClangAssistProposalItem::implicitlyApplies() const
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||||
@@ -174,20 +174,13 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Avoid inserting characters that are already there
|
// Avoid inserting characters that are already there
|
||||||
const int endsPosition = manipulator.positionAt(TextEditor::EndOfLinePosition);
|
QTextCursor cursor = manipulator.textCursorAt(basePosition);
|
||||||
const QString existingText = manipulator.textAt(manipulator.currentPosition(), endsPosition - manipulator.currentPosition());
|
cursor.movePosition(QTextCursor::EndOfWord);
|
||||||
int existLength = 0;
|
const int currentPosition = cursor.position();
|
||||||
if (!existingText.isEmpty() && ccr.completionKind() != CodeCompletion::KeywordCompletionKind) {
|
|
||||||
// Calculate the exist length in front of the extra chars
|
|
||||||
existLength = textToBeInserted.length() - (manipulator.currentPosition() - basePosition);
|
|
||||||
while (!existingText.startsWith(textToBeInserted.right(existLength))) {
|
|
||||||
if (--existLength == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int i = 0; i < extraCharacters.length(); ++i) {
|
for (int i = 0; i < extraCharacters.length(); ++i) {
|
||||||
const QChar a = extraCharacters.at(i);
|
const QChar a = extraCharacters.at(i);
|
||||||
const QChar b = manipulator.characterAt(manipulator.currentPosition() + i + existLength);
|
const QChar b = manipulator.characterAt(currentPosition + i);
|
||||||
if (a == b)
|
if (a == b)
|
||||||
++extraLength;
|
++extraLength;
|
||||||
else
|
else
|
||||||
@@ -196,9 +189,10 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
|
|||||||
|
|
||||||
textToBeInserted += extraCharacters;
|
textToBeInserted += extraCharacters;
|
||||||
|
|
||||||
const int length = manipulator.currentPosition() - basePosition + existLength + extraLength;
|
const int length = currentPosition - basePosition + extraLength;
|
||||||
|
|
||||||
const bool isReplaced = manipulator.replace(basePosition, length, textToBeInserted);
|
const bool isReplaced = manipulator.replace(basePosition, length, textToBeInserted);
|
||||||
|
manipulator.setCursorPosition(basePosition + textToBeInserted.length());
|
||||||
if (isReplaced) {
|
if (isReplaced) {
|
||||||
if (cursorOffset)
|
if (cursorOffset)
|
||||||
manipulator.setCursorPosition(manipulator.currentPosition() + cursorOffset);
|
manipulator.setCursorPosition(manipulator.currentPosition() + cursorOffset);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ bool ClangPreprocessorAssistProposalItem::prematurelyApplies(const QChar &typedC
|
|||||||
|
|
||||||
bool ClangPreprocessorAssistProposalItem::implicitlyApplies() const
|
bool ClangPreprocessorAssistProposalItem::implicitlyApplies() const
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangPreprocessorAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
void ClangPreprocessorAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface &manipulator,
|
||||||
|
|||||||
@@ -354,9 +354,13 @@ void CodeAssistantPrivate::processProposalItem(AssistProposalItemInterface *prop
|
|||||||
void CodeAssistantPrivate::handlePrefixExpansion(const QString &newPrefix)
|
void CodeAssistantPrivate::handlePrefixExpansion(const QString &newPrefix)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_proposal, return);
|
QTC_ASSERT(m_proposal, return);
|
||||||
const int currentPosition = m_editorWidget->position();
|
|
||||||
|
QTextCursor cursor(m_editorWidget->document());
|
||||||
|
cursor.setPosition(m_proposal->basePosition());
|
||||||
|
cursor.movePosition(QTextCursor::EndOfWord);
|
||||||
|
|
||||||
m_editorWidget->setCursorPosition(m_proposal->basePosition());
|
m_editorWidget->setCursorPosition(m_proposal->basePosition());
|
||||||
m_editorWidget->replace(currentPosition - m_proposal->basePosition(), newPrefix);
|
m_editorWidget->replace(cursor.position() - m_proposal->basePosition(), newPrefix);
|
||||||
notifyChange();
|
notifyChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user