forked from qt-creator/qt-creator
ClangCodeModel: Limit result count in clangd-based locator searches
clangd memory usage explodes when the workspace/symbol result count hits the six-digit mark, so prevent that. Change-Id: Iefc2eeb3da7fe541e2b1d3105818126980fc3323 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -188,6 +188,8 @@ public:
|
|||||||
QString query() const { return typedValue<QString>(queryKey); }
|
QString query() const { return typedValue<QString>(queryKey); }
|
||||||
void setQuery(const QString &query) { insert(queryKey, query); }
|
void setQuery(const QString &query) { insert(queryKey, query); }
|
||||||
|
|
||||||
|
void setLimit(int limit) { insert("limit", limit); } // clangd extension
|
||||||
|
|
||||||
bool isValid() const override { return contains(queryKey); }
|
bool isValid() const override { return contains(queryKey); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -43,6 +43,8 @@
|
|||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
const int MaxResultCount = 10000;
|
||||||
|
|
||||||
class CppLocatorFilter : public CppTools::CppLocatorFilter
|
class CppLocatorFilter : public CppTools::CppLocatorFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -67,6 +69,7 @@ public:
|
|||||||
setDefaultShortcutString({});
|
setDefaultShortcutString({});
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
setHidden(true);
|
setHidden(true);
|
||||||
|
setMaxResultCount(MaxResultCount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -94,6 +97,7 @@ public:
|
|||||||
setDefaultShortcutString({});
|
setDefaultShortcutString({});
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
setHidden(true);
|
setHidden(true);
|
||||||
|
setMaxResultCount(MaxResultCount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -121,6 +125,7 @@ public:
|
|||||||
setDefaultShortcutString({});
|
setDefaultShortcutString({});
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
setHidden(true);
|
setHidden(true);
|
||||||
|
setMaxResultCount(MaxResultCount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -230,6 +230,8 @@ void WorkspaceLocatorFilter::prepareSearch(const QString &entry,
|
|||||||
|
|
||||||
WorkspaceSymbolParams params;
|
WorkspaceSymbolParams params;
|
||||||
params.setQuery(entry);
|
params.setQuery(entry);
|
||||||
|
if (m_maxResultCount > 0)
|
||||||
|
params.setLimit(m_maxResultCount);
|
||||||
|
|
||||||
QMutexLocker locker(&m_mutex);
|
QMutexLocker locker(&m_mutex);
|
||||||
for (auto client : qAsConst(clients)) {
|
for (auto client : qAsConst(clients)) {
|
||||||
|
@@ -97,6 +97,8 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
explicit WorkspaceLocatorFilter(const QVector<LanguageServerProtocol::SymbolKind> &filter);
|
explicit WorkspaceLocatorFilter(const QVector<LanguageServerProtocol::SymbolKind> &filter);
|
||||||
|
|
||||||
|
void setMaxResultCount(qint64 limit) { m_maxResultCount = limit; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void prepareSearch(const QString &entry, const QVector<Client *> &clients, bool force);
|
void prepareSearch(const QString &entry, const QVector<Client *> &clients, bool force);
|
||||||
void handleResponse(Client *client,
|
void handleResponse(Client *client,
|
||||||
@@ -106,6 +108,7 @@ private:
|
|||||||
QMap<Client *, LanguageServerProtocol::MessageId> m_pendingRequests;
|
QMap<Client *, LanguageServerProtocol::MessageId> m_pendingRequests;
|
||||||
QVector<LanguageServerProtocol::SymbolInformation> m_results;
|
QVector<LanguageServerProtocol::SymbolInformation> m_results;
|
||||||
QVector<LanguageServerProtocol::SymbolKind> m_filterKinds;
|
QVector<LanguageServerProtocol::SymbolKind> m_filterKinds;
|
||||||
|
qint64 m_maxResultCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LANGUAGECLIENT_EXPORT WorkspaceClassLocatorFilter : public WorkspaceLocatorFilter
|
class LANGUAGECLIENT_EXPORT WorkspaceClassLocatorFilter : public WorkspaceLocatorFilter
|
||||||
|
Reference in New Issue
Block a user