forked from qt-creator/qt-creator
LanguageClient: Support limit parameter for completion request
... and make use of it in the ClangCodeModel tests. Change-Id: Ib2186273aec1db9b354892c2e1c4ebd82e3c1c96 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -83,6 +83,9 @@ public:
|
||||
void setContext(const CompletionContext &context)
|
||||
{ insert(contextKey, context); }
|
||||
void clearContext() { remove(contextKey); }
|
||||
|
||||
// clangd extension
|
||||
void setLimit(int limit) { insert(limitKey, limit); }
|
||||
};
|
||||
|
||||
class LANGUAGESERVERPROTOCOL_EXPORT CompletionItem : public JsonObject
|
||||
|
@@ -139,6 +139,7 @@ constexpr char labelKey[] = "label";
|
||||
constexpr char languageIdKey[] = "languageId";
|
||||
constexpr char languageKey[] = "language";
|
||||
constexpr char legendKey[] = "legend";
|
||||
constexpr char limitKey[] = "limit";
|
||||
constexpr char lineKey[] = "line";
|
||||
constexpr char linesKey[] = "lines";
|
||||
constexpr char locationKey[] = "location";
|
||||
|
@@ -167,13 +167,7 @@ static BaseClientInterface *clientInterface(Project *project, const Utils::FileP
|
||||
indexingOption += "=0";
|
||||
const QString headerInsertionOption = QString("--header-insertion=")
|
||||
+ (settings.autoIncludeHeaders() ? "iwyu" : "never");
|
||||
#ifdef WITH_TESTS
|
||||
// For the #include < test, which needs to get a local header file, but the list
|
||||
// is being flooded with system include headers. 4280 on Windows!
|
||||
const QString limitResults = QString("--limit-results=0");
|
||||
#else
|
||||
const QString limitResults = QString("--limit-results=%1").arg(settings.completionResults());
|
||||
#endif
|
||||
Utils::CommandLine cmd{settings.clangdFilePath(),
|
||||
{indexingOption,
|
||||
headerInsertionOption,
|
||||
|
@@ -1550,6 +1550,9 @@ void ClangdTestCompletion::testCompletePreprocessorKeywords()
|
||||
|
||||
void ClangdTestCompletion::testCompleteIncludeDirective()
|
||||
{
|
||||
// Our local include is way down in the result list.
|
||||
client()->setCompletionResultsLimit(0);
|
||||
|
||||
ProposalModelPtr proposal;
|
||||
getProposal("includeDirectiveCompletion.cpp", proposal);
|
||||
|
||||
@@ -1558,6 +1561,7 @@ void ClangdTestCompletion::testCompleteIncludeDirective()
|
||||
QVERIFY(hasItem(proposal, " otherFile.h>"));
|
||||
QVERIFY(hasItem(proposal, " mylib/"));
|
||||
QVERIFY(!hasSnippet(proposal, "class "));
|
||||
client()->setCompletionResultsLimit(-1);
|
||||
}
|
||||
|
||||
void ClangdTestCompletion::testCompleteGlobals()
|
||||
|
@@ -328,6 +328,7 @@ public:
|
||||
QTimer m_shutdownTimer;
|
||||
LanguageServerProtocol::ClientInfo m_clientInfo;
|
||||
QJsonValue m_configuration;
|
||||
int m_completionResultsLimit = -1;
|
||||
};
|
||||
|
||||
Client::Client(BaseClientInterface *clientInterface)
|
||||
@@ -1578,6 +1579,16 @@ TextEditor::RefactoringChangesData *Client::createRefactoringChangesBackend() co
|
||||
return new TextEditor::RefactoringChangesData;
|
||||
}
|
||||
|
||||
void Client::setCompletionResultsLimit(int limit)
|
||||
{
|
||||
d->m_completionResultsLimit = limit;
|
||||
}
|
||||
|
||||
int Client::completionResultsLimit() const
|
||||
{
|
||||
return d->m_completionResultsLimit;
|
||||
}
|
||||
|
||||
const ServerCapabilities &Client::capabilities() const
|
||||
{
|
||||
return d->m_serverCapabilities;
|
||||
|
@@ -202,6 +202,9 @@ public:
|
||||
// Caller takes ownership
|
||||
virtual TextEditor::RefactoringChangesData *createRefactoringChangesBackend() const;
|
||||
|
||||
void setCompletionResultsLimit(int limit);
|
||||
int completionResultsLimit() const;
|
||||
|
||||
signals:
|
||||
void initialized(const LanguageServerProtocol::ServerCapabilities &capabilities);
|
||||
void capabilitiesChanged(const DynamicCapabilities &capabilities);
|
||||
|
@@ -379,6 +379,8 @@ IAssistProposal *LanguageClientCompletionAssistProcessor::perform(const AssistIn
|
||||
params.setPosition({line, column});
|
||||
params.setContext(context);
|
||||
params.setTextDocument(TextDocumentIdentifier(DocumentUri::fromFilePath(interface->filePath())));
|
||||
if (const int limit = m_client->completionResultsLimit(); limit >= 0)
|
||||
params.setLimit(limit);
|
||||
CompletionRequest completionRequest(params);
|
||||
completionRequest.setResponseCallback([this](auto response) {
|
||||
this->handleCompletionResponse(response);
|
||||
|
Reference in New Issue
Block a user