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:
Christian Kandeler
2021-07-12 16:52:56 +02:00
parent d0172f80b4
commit 3c1e787215
4 changed files with 12 additions and 0 deletions

View File

@@ -188,6 +188,8 @@ public:
QString query() const { return typedValue<QString>(queryKey); }
void setQuery(const QString &query) { insert(queryKey, query); }
void setLimit(int limit) { insert("limit", limit); } // clangd extension
bool isValid() const override { return contains(queryKey); }
};

View File

@@ -43,6 +43,8 @@
namespace ClangCodeModel {
namespace Internal {
const int MaxResultCount = 10000;
class CppLocatorFilter : public CppTools::CppLocatorFilter
{
public:
@@ -67,6 +69,7 @@ public:
setDefaultShortcutString({});
setEnabled(false);
setHidden(true);
setMaxResultCount(MaxResultCount);
}
};
@@ -94,6 +97,7 @@ public:
setDefaultShortcutString({});
setEnabled(false);
setHidden(true);
setMaxResultCount(MaxResultCount);
}
};
@@ -121,6 +125,7 @@ public:
setDefaultShortcutString({});
setEnabled(false);
setHidden(true);
setMaxResultCount(MaxResultCount);
}
};

View File

@@ -230,6 +230,8 @@ void WorkspaceLocatorFilter::prepareSearch(const QString &entry,
WorkspaceSymbolParams params;
params.setQuery(entry);
if (m_maxResultCount > 0)
params.setLimit(m_maxResultCount);
QMutexLocker locker(&m_mutex);
for (auto client : qAsConst(clients)) {

View File

@@ -97,6 +97,8 @@ signals:
protected:
explicit WorkspaceLocatorFilter(const QVector<LanguageServerProtocol::SymbolKind> &filter);
void setMaxResultCount(qint64 limit) { m_maxResultCount = limit; }
private:
void prepareSearch(const QString &entry, const QVector<Client *> &clients, bool force);
void handleResponse(Client *client,
@@ -106,6 +108,7 @@ private:
QMap<Client *, LanguageServerProtocol::MessageId> m_pendingRequests;
QVector<LanguageServerProtocol::SymbolInformation> m_results;
QVector<LanguageServerProtocol::SymbolKind> m_filterKinds;
qint64 m_maxResultCount = 0;
};
class LANGUAGECLIENT_EXPORT WorkspaceClassLocatorFilter : public WorkspaceLocatorFilter