| 116 | } |
| 117 | |
| 118 | void RenameAssistant::textChanged(KTextEditor::Document* doc, const KTextEditor::Range& invocationRange, |
| 119 | const QString& removedText) |
| 120 | { |
| 121 | Q_D(RenameAssistant); |
| 122 | |
| 123 | clearActions(); |
| 124 | d->m_lastChangedLocation = invocationRange.end(); |
| 125 | d->m_lastChangedDocument = doc; |
| 126 | |
| 127 | if (!supportedLanguage()->refactoring()) { |
| 128 | qCWarning(LANGUAGE) << "Refactoring not supported. Aborting."; |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | if (!doc) |
| 133 | return; |
| 134 | |
| 135 | //If the inserted text isn't valid for a variable name, consider the editing ended |
| 136 | QRegExp validDeclName(QStringLiteral("^[0-9a-zA-Z_]*$")); |
| 137 | if (removedText.isEmpty() && !validDeclName.exactMatch(doc->text(invocationRange))) { |
| 138 | d->reset(); |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | const QUrl url = doc->url(); |
| 143 | const IndexedString indexedUrl(url); |
| 144 | DUChainReadLocker lock; |
| 145 | |
| 146 | //If we've stopped editing m_newDeclarationRange or switched the view, |
| 147 | // reset and see if there's another declaration being edited |
| 148 | if (!d->m_newDeclarationRange.data() || !rangesConnect(d->m_newDeclarationRange->range(), invocationRange) |
| 149 | || d->m_newDeclarationRange->document() != indexedUrl) { |
| 150 | d->reset(); |
| 151 | |
| 152 | Declaration* declAtCursor = declarationForChangedRange(doc, invocationRange); |
| 153 | if (!declAtCursor) { |
| 154 | // not editing a declaration |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | if (supportedLanguage()->refactoring()->shouldRenameUses(declAtCursor)) { |
| 159 | const auto declUses = declAtCursor->uses(); |
| 160 | if (declUses.isEmpty()) { |
| 161 | // new declaration has no uses |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | for (auto& ranges : declUses) { |
| 166 | for (const RangeInRevision range : ranges) { |
| 167 | KTextEditor::Range currentRange = declAtCursor->transformFromLocalRevision(range); |
| 168 | if (currentRange.isEmpty() || |
| 169 | doc->text(currentRange) != declAtCursor->identifier().identifier().str()) { |
| 170 | return; // One of the uses is invalid. Maybe the replacement has already been performed. |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | d->m_oldDeclarationUses = RevisionedFileRanges::convert(declUses); |
no test coverage detected