forked from qt-creator/qt-creator
ClangCurrentDocumentFilter: make use of prepareSearch function
Since it's guaranteed, that prepareSearch() is always called from the main thread prior to the call to matchesFor() from the other thread, we copy the data inside prepareSearch() which we will operate on when matchesFor() is called later on. Change-Id: Idf6a8e683356bb524eb4b5b1ce1e05b0ba065c8b Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -97,11 +97,17 @@ static Core::LocatorFilterEntry makeEntry(Core::ILocatorFilter *filter,
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClangCurrentDocumentFilter::prepareSearch(const QString &entry)
|
||||||
|
{
|
||||||
|
Q_UNUSED(entry)
|
||||||
|
m_preparedPath = m_currentPath;
|
||||||
|
}
|
||||||
|
|
||||||
QList<Core::LocatorFilterEntry> ClangCurrentDocumentFilter::matchesFor(
|
QList<Core::LocatorFilterEntry> ClangCurrentDocumentFilter::matchesFor(
|
||||||
QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry)
|
QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry)
|
||||||
{
|
{
|
||||||
QList<Core::LocatorFilterEntry> goodEntries;
|
QList<Core::LocatorFilterEntry> goodEntries;
|
||||||
if (!m_currentEditor)
|
if (m_preparedPath.isEmpty())
|
||||||
return goodEntries;
|
return goodEntries;
|
||||||
|
|
||||||
FuzzyMatcher::CaseSensitivity caseSesitivity = caseSensitivity(entry) == Qt::CaseSensitive
|
FuzzyMatcher::CaseSensitivity caseSesitivity = caseSensitivity(entry) == Qt::CaseSensitive
|
||||||
@@ -111,7 +117,7 @@ QList<Core::LocatorFilterEntry> ClangCurrentDocumentFilter::matchesFor(
|
|||||||
if (!regexp.isValid())
|
if (!regexp.isValid())
|
||||||
return goodEntries;
|
return goodEntries;
|
||||||
|
|
||||||
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(m_currentPath);
|
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(m_preparedPath);
|
||||||
if (!processor)
|
if (!processor)
|
||||||
return goodEntries;
|
return goodEntries;
|
||||||
|
|
||||||
@@ -143,10 +149,10 @@ void ClangCurrentDocumentFilter::refresh(QFutureInterface<void> &)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangCurrentDocumentFilter::reset()
|
void ClangCurrentDocumentFilter::reset(Core::IEditor *newCurrent, const QString &path)
|
||||||
{
|
{
|
||||||
m_currentEditor = nullptr;
|
m_currentEditor = newCurrent;
|
||||||
m_currentPath.clear();
|
m_currentPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAboutToClose)
|
void ClangCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAboutToClose)
|
||||||
@@ -161,11 +167,10 @@ void ClangCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAbout
|
|||||||
void ClangCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *newCurrent)
|
void ClangCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *newCurrent)
|
||||||
{
|
{
|
||||||
if (newCurrent) {
|
if (newCurrent) {
|
||||||
m_currentEditor = newCurrent;
|
Core::IDocument *document = newCurrent->document();
|
||||||
Core::IDocument *document = m_currentEditor->document();
|
QTC_ASSERT(document, reset(); return);
|
||||||
QTC_ASSERT(document, return;);
|
|
||||||
if (auto *textDocument = qobject_cast<TextEditor::TextDocument *>(document)) {
|
if (auto *textDocument = qobject_cast<TextEditor::TextDocument *>(document)) {
|
||||||
m_currentPath = textDocument->filePath().toString();
|
reset(newCurrent, textDocument->filePath().toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,7 @@ class ClangCurrentDocumentFilter : public Core::ILocatorFilter
|
|||||||
public:
|
public:
|
||||||
explicit ClangCurrentDocumentFilter();
|
explicit ClangCurrentDocumentFilter();
|
||||||
|
|
||||||
|
void prepareSearch(const QString &entry) override;
|
||||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||||
const QString &entry) override;
|
const QString &entry) override;
|
||||||
void accept(Core::LocatorFilterEntry selection,
|
void accept(Core::LocatorFilterEntry selection,
|
||||||
@@ -48,10 +49,11 @@ private:
|
|||||||
void onEditorAboutToClose(Core::IEditor *editors);
|
void onEditorAboutToClose(Core::IEditor *editors);
|
||||||
void onCurrentEditorChanged(Core::IEditor *newCurrent);
|
void onCurrentEditorChanged(Core::IEditor *newCurrent);
|
||||||
|
|
||||||
void reset();
|
void reset(Core::IEditor *newCurrent = nullptr, const QString &path = QString());
|
||||||
|
|
||||||
Core::IEditor *m_currentEditor = nullptr;
|
Core::IEditor *m_currentEditor = nullptr;
|
||||||
QString m_currentPath;
|
QString m_currentPath;
|
||||||
|
QString m_preparedPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user