Designer: Update C++ code model on an object name change in designer

We try to locate the old symbol name in the generated ui header and
rename the symbol in the background.

Task-number: QTCREATORBUG-1179
Change-Id: Iaf68e3922cd728cbc87d0dc97125e34b8bdaa6be
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2023-01-16 17:03:26 +01:00
parent b4b2600715
commit 0d909c353c
36 changed files with 470 additions and 63 deletions

View File

@@ -292,7 +292,7 @@ public:
void findUsages(TextDocument *document, const QTextCursor &cursor,
const QString &searchTerm, const std::optional<QString> &replacement,
bool categorize);
const std::function<void()> &callback, bool categorize);
void handleDeclDefSwitchReplies();
@@ -509,7 +509,8 @@ void ClangdClient::closeExtraFile(const Utils::FilePath &filePath)
}
void ClangdClient::findUsages(TextDocument *document, const QTextCursor &cursor,
const std::optional<QString> &replacement)
const std::optional<QString> &replacement,
const std::function<void()> &renameCallback)
{
// Quick check: Are we even on anything searchable?
const QTextCursor adjustedCursor = d->adjustedCursor(cursor, document);
@@ -519,7 +520,7 @@ void ClangdClient::findUsages(TextDocument *document, const QTextCursor &cursor,
if (replacement && versionNumber() >= QVersionNumber(16)
&& Utils::qtcEnvironmentVariable("QTC_CLANGD_RENAMING") != "0") {
symbolSupport().renameSymbol(document, adjustedCursor, *replacement,
symbolSupport().renameSymbol(document, adjustedCursor, *replacement, renameCallback,
CppEditor::preferLowerCaseFileNames());
return;
}
@@ -530,19 +531,20 @@ void ClangdClient::findUsages(TextDocument *document, const QTextCursor &cursor,
if (searchTerm != "operator" && Utils::allOf(searchTerm, [](const QChar &c) {
return c.isLetterOrNumber() || c == '_';
})) {
d->findUsages(document, adjustedCursor, searchTerm, replacement, categorize);
d->findUsages(document, adjustedCursor, searchTerm, replacement, renameCallback, categorize);
return;
}
// Otherwise get the proper spelling of the search term from clang, so we can put it into the
// search widget.
const auto symbolInfoHandler = [this, doc = QPointer(document), adjustedCursor, replacement, categorize]
const auto symbolInfoHandler = [this, doc = QPointer(document), adjustedCursor, replacement,
renameCallback, categorize]
(const QString &name, const QString &, const MessageId &) {
if (!doc)
return;
if (name.isEmpty())
return;
d->findUsages(doc.data(), adjustedCursor, name, replacement, categorize);
d->findUsages(doc.data(), adjustedCursor, name, replacement, renameCallback, categorize);
};
requestSymbolInfo(document->filePath(), Range(adjustedCursor).start(), symbolInfoHandler);
}
@@ -704,10 +706,11 @@ CppEditor::ClangdSettings::Data ClangdClient::settingsData() const { return d->s
void ClangdClient::Private::findUsages(TextDocument *document,
const QTextCursor &cursor, const QString &searchTerm,
const std::optional<QString> &replacement, bool categorize)
const std::optional<QString> &replacement, const std::function<void()> &renameCallback,
bool categorize)
{
const auto findRefs = new ClangdFindReferences(q, document, cursor, searchTerm, replacement,
categorize);
renameCallback, categorize);
if (isTesting) {
connect(findRefs, &ClangdFindReferences::foundReferences,
q, &ClangdClient::foundReferences);

View File

@@ -54,7 +54,8 @@ public:
void closeExtraFile(const Utils::FilePath &filePath);
void findUsages(TextEditor::TextDocument *document, const QTextCursor &cursor,
const std::optional<QString> &replacement);
const std::optional<QString> &replacement,
const std::function<void()> &renameCallback);
void checkUnused(const Utils::Link &link, Core::SearchResult *search,
const Utils::LinkHandler &callback);
void followSymbol(TextEditor::TextDocument *document,

View File

@@ -109,7 +109,8 @@ public:
ClangdFindReferences::ClangdFindReferences(ClangdClient *client, TextDocument *document,
const QTextCursor &cursor, const QString &searchTerm,
const std::optional<QString> &replacement, bool categorize)
const std::optional<QString> &replacement, const std::function<void()> &callback,
bool categorize)
: QObject(client), d(new ClangdFindReferences::Private(this))
{
d->categorize = categorize;
@@ -130,6 +131,7 @@ ClangdFindReferences::ClangdFindReferences(ClangdClient *client, TextDocument *d
replacement ? SearchResultWindow::SearchAndReplace : SearchResultWindow::SearchOnly,
SearchResultWindow::PreserveCaseDisabled,
"CppEditor");
d->search->makeNonInteractive(callback);
if (categorize)
d->search->setFilter(new CppSearchResultFilter);
if (d->replacementData) {
@@ -150,7 +152,8 @@ ClangdFindReferences::ClangdFindReferences(ClangdClient *client, TextDocument *d
connect(d->search, &SearchResult::activated, [](const SearchResultItem& item) {
EditorManager::openEditorAtSearchResult(item);
});
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
if (d->search->isInteractive())
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
const std::optional<MessageId> requestId = client->symbolSupport().findUsages(
document, cursor, [self = QPointer(this)](const QList<Location> &locations) {

View File

@@ -27,7 +27,9 @@ class ClangdFindReferences : public QObject
public:
ClangdFindReferences(ClangdClient *client, TextEditor::TextDocument *document,
const QTextCursor &cursor, const QString &searchTerm,
const std::optional<QString> &replacement, bool categorize);
const std::optional<QString> &replacement,
const std::function<void()> &callback,
bool categorize);
ClangdFindReferences(ClangdClient *client, const Utils::Link &link, Core::SearchResult *search,
const Utils::LinkHandler &callback);
~ClangdFindReferences();

View File

@@ -313,16 +313,17 @@ void ClangModelManagerSupport::startLocalRenaming(const CppEditor::CursorInEdito
}
void ClangModelManagerSupport::globalRename(const CppEditor::CursorInEditor &cursor,
const QString &replacement)
const QString &replacement,
const std::function<void()> &callback)
{
if (ClangdClient * const client = clientForFile(cursor.filePath());
client && client->isFullyIndexed()) {
QTC_ASSERT(client->documentOpen(cursor.textDocument()),
client->openDocument(cursor.textDocument()));
client->findUsages(cursor.textDocument(), cursor.cursor(), replacement);
client->findUsages(cursor.textDocument(), cursor.cursor(), replacement, callback);
return;
}
CppModelManager::globalRename(cursor, replacement, CppModelManager::Backend::Builtin);
CppModelManager::globalRename(cursor, replacement, callback, CppModelManager::Backend::Builtin);
}
void ClangModelManagerSupport::findUsages(const CppEditor::CursorInEditor &cursor) const
@@ -331,7 +332,7 @@ void ClangModelManagerSupport::findUsages(const CppEditor::CursorInEditor &curso
client && client->isFullyIndexed()) {
QTC_ASSERT(client->documentOpen(cursor.textDocument()),
client->openDocument(cursor.textDocument()));
client->findUsages(cursor.textDocument(), cursor.cursor(), {});
client->findUsages(cursor.textDocument(), cursor.cursor(), {}, {});
return;
}

View File

@@ -60,7 +60,8 @@ private:
void startLocalRenaming(const CppEditor::CursorInEditor &data,
const CppEditor::ProjectPart *projectPart,
CppEditor::RenameCallback &&renameSymbolsCallback) override;
void globalRename(const CppEditor::CursorInEditor &cursor, const QString &replacement) override;
void globalRename(const CppEditor::CursorInEditor &cursor, const QString &replacement,
const std::function<void()> &callback) override;
void findUsages(const CppEditor::CursorInEditor &cursor) const override;
void switchHeaderSource(const Utils::FilePath &filePath, bool inNextSplit) override;
void checkUnused(const Utils::Link &link, Core::SearchResult *search,

View File

@@ -294,7 +294,7 @@ void ClangdTestFindReferences::test()
QVERIFY(doc);
QTextCursor cursor(doc->document());
cursor.setPosition(pos);
client()->findUsages(doc, cursor, {});
client()->findUsages(doc, cursor, {}, {});
QVERIFY(waitForSignalOrTimeout(client(), &ClangdClient::findUsagesDone, timeOutInMs()));
QCOMPARE(m_actualResults.size(), expectedResults.size());