aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/clangcodemodel/test
diff options
context:
space:
mode:
authorDavid Schulz <[email protected]>2024-03-05 12:47:33 +0100
committerDavid Schulz <[email protected]>2024-03-11 12:39:06 +0000
commit325db93a7b39062d8dc7b9f5371259f143b9f51b (patch)
tree13c4f0cd55cdd88d648e75df2bf001157aee544b /src/plugins/clangcodemodel/test
parent17f40221e0d49fdb06b72f2d5c583216d7bed4ee (diff)
LanguageClient: improve clangd function hint
Add a Clangd specific function hint model that alwys highlights the current parameter based on the number of commas in front of the cursor position, like the builtin code model. It also correctly closes the proposal after typing the closing parenthesis. Fixes: QTCREATORBUG-26346 Fixes: QTCREATORBUG-30489 Change-Id: I09d3ac6856acfe5e0f206d8c3a96dbb561ea2ce7 Reviewed-by: Christian Kandeler <[email protected]>
Diffstat (limited to 'src/plugins/clangcodemodel/test')
-rw-r--r--src/plugins/clangcodemodel/test/clangdtests.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/plugins/clangcodemodel/test/clangdtests.cpp b/src/plugins/clangcodemodel/test/clangdtests.cpp
index bfe7ea95368..d4dd092b837 100644
--- a/src/plugins/clangcodemodel/test/clangdtests.cpp
+++ b/src/plugins/clangcodemodel/test/clangdtests.cpp
@@ -29,6 +29,7 @@
#include <texteditor/blockrange.h>
#include <texteditor/codeassist/assistproposaliteminterface.h>
#include <texteditor/codeassist/genericproposal.h>
+#include <texteditor/codeassist/ifunctionhintproposalmodel.h>
#include <texteditor/codeassist/textdocumentmanipulatorinterface.h>
#include <texteditor/semantichighlighter.h>
#include <texteditor/textmark.h>
@@ -1832,12 +1833,12 @@ void ClangdTestCompletion::testFunctionHints()
QVERIFY(proposal);
QVERIFY(hasItem(proposal, "f() -> void"));
- QVERIFY(hasItem(proposal, "f(int a) -> void"));
- QVERIFY(hasItem(proposal, "f(const QString &s) -> void"));
- QVERIFY(hasItem(proposal, "f(char c, int optional = 3) -> void"));
- QVERIFY(hasItem(proposal, "f(char c, int optional1 = 3, int optional2 = 3) -> void"));
- QVERIFY(hasItem(proposal, "f(const TType<QString> *t) -> void"));
- QVERIFY(hasItem(proposal, "f(bool) -> TType<QString>"));
+ QVERIFY(hasItem(proposal, "f(<b>int a</b>) -&gt; void"));
+ QVERIFY(hasItem(proposal, "f(<b>const QString &amp;s</b>) -&gt; void"));
+ QVERIFY(hasItem(proposal, "f(<b>char c</b>, int optional = 3) -&gt; void"));
+ QVERIFY(hasItem(proposal, "f(<b>char c</b>, int optional1 = 3, int optional2 = 3) -&gt; void"));
+ QVERIFY(hasItem(proposal, "f(<b>const TType&lt;QString&gt; *t</b>) -&gt; void"));
+ QVERIFY(hasItem(proposal, "f(<b>bool</b>) -&gt; TType&lt;QString&gt;"));
}
void ClangdTestCompletion::testFunctionHintsFiltered()
@@ -1855,7 +1856,6 @@ void ClangdTestCompletion::testFunctionHintsFiltered()
QVERIFY(proposal);
QCOMPARE(proposal->size(), 2);
QVERIFY(hasItem(proposal, "func(const S &amp;s, <b>int j</b>) -&gt; void"));
- QEXPECT_FAIL("", "QTCREATORBUG-26346", Abort);
QVERIFY(hasItem(proposal, "func(const S &amp;s, <b>int j</b>, int k) -&gt; void"));
}
@@ -1868,7 +1868,6 @@ void ClangdTestCompletion::testFunctionHintConstructor()
QVERIFY(!hasItem(proposal, "globalVariable"));
QVERIFY(!hasItem(proposal, " class"));
QVERIFY(hasItem(proposal, "Foo(<b>int</b>)"));
- QEXPECT_FAIL("", "QTCREATORBUG-26346", Abort);
QVERIFY(hasItem(proposal, "Foo(<b>int</b>, double)"));
}
@@ -2066,7 +2065,8 @@ void ClangdTestCompletion::getProposal(const QString &fileName,
{
const TextDocument * const doc = document(fileName);
QVERIFY(doc);
- const int pos = doc->document()->toPlainText().indexOf(" /* COMPLETE HERE */");
+ const QString docContent = doc->document()->toPlainText();
+ const int pos = docContent.indexOf(" /* COMPLETE HERE */");
QVERIFY(pos != -1);
if (cursorPos)
*cursorPos = pos;
@@ -2110,6 +2110,13 @@ void ClangdTestCompletion::getProposal(const QString &fileName,
QVERIFY(timer.isActive());
QVERIFY(proposal);
proposalModel = proposal->model();
+ if (auto functionHintModel = proposalModel.dynamicCast<IFunctionHintProposalModel>()) {
+ const int proposalBasePos = proposal->basePosition();
+ // The language client function hint model expects that activeArgument was called before the
+ // text of individual hints is accessed. This is usually done by the proposal widget. But
+ // since we don't have a proposal widget in this test, we have to call it manually.
+ functionHintModel->activeArgument(docContent.mid(proposalBasePos, pos - proposalBasePos));
+ }
delete proposal;
// The "dot" test files are only used once.