diff options
author | David Schulz <david.schulz@qt.io> | 2024-03-05 12:47:33 +0100 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2024-03-11 12:39:06 +0000 |
commit | 325db93a7b39062d8dc7b9f5371259f143b9f51b (patch) | |
tree | 13c4f0cd55cdd88d648e75df2bf001157aee544b /src/plugins/cppeditor | |
parent | 17f40221e0d49fdb06b72f2d5c583216d7bed4ee (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 <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/cppeditor')
-rw-r--r-- | src/plugins/cppeditor/cppcompletionassist.cpp | 24 | ||||
-rw-r--r-- | src/plugins/cppeditor/cpptoolsreuse.cpp | 24 | ||||
-rw-r--r-- | src/plugins/cppeditor/cpptoolsreuse.h | 2 |
3 files changed, 29 insertions, 21 deletions
diff --git a/src/plugins/cppeditor/cppcompletionassist.cpp b/src/plugins/cppeditor/cppcompletionassist.cpp index 8168d72ba1..03c04765d4 100644 --- a/src/plugins/cppeditor/cppcompletionassist.cpp +++ b/src/plugins/cppeditor/cppcompletionassist.cpp @@ -372,27 +372,11 @@ QString CppFunctionHintModel::text(int index) const int CppFunctionHintModel::activeArgument(const QString &prefix) const { - int argnr = 0; - int parcount = 0; - SimpleLexer tokenize; - Tokens tokens = tokenize(prefix); - for (int i = 0; i < tokens.count(); ++i) { - const Token &tk = tokens.at(i); - if (tk.is(T_LPAREN)) - ++parcount; - else if (tk.is(T_RPAREN)) - --parcount; - else if (!parcount && tk.is(T_COMMA)) - ++argnr; - } - - if (parcount < 0) + const int arg = activeArgumenForPrefix(prefix); + if (arg < 0) return -1; - - if (argnr != m_currentArg) - m_currentArg = argnr; - - return argnr; + m_currentArg = arg; + return arg; } // --------------------------- diff --git a/src/plugins/cppeditor/cpptoolsreuse.cpp b/src/plugins/cppeditor/cpptoolsreuse.cpp index 48fe23244b..6555010c8f 100644 --- a/src/plugins/cppeditor/cpptoolsreuse.cpp +++ b/src/plugins/cppeditor/cpptoolsreuse.cpp @@ -219,6 +219,28 @@ bool isValidIdentifier(const QString &s) return true; } +int activeArgumenForPrefix(const QString &prefix) +{ + int argnr = 0; + int parcount = 0; + SimpleLexer tokenize; + Tokens tokens = tokenize(prefix); + for (int i = 0; i < tokens.count(); ++i) { + const Token &tk = tokens.at(i); + if (tk.is(T_LPAREN)) + ++parcount; + else if (tk.is(T_RPAREN)) + --parcount; + else if (!parcount && tk.is(T_COMMA)) + ++argnr; + } + + if (parcount < 0) + return -1; + + return argnr; +} + bool isQtKeyword(QStringView text) { switch (text.length()) { @@ -859,5 +881,5 @@ void decorateCppEditor(TextEditor::TextEditorWidget *editor) editor->setAutoCompleter(new CppAutoCompleter); } -} // namespace Internal +} // Internal } // CppEditor diff --git a/src/plugins/cppeditor/cpptoolsreuse.h b/src/plugins/cppeditor/cpptoolsreuse.h index 50078bdd79..89bf896197 100644 --- a/src/plugins/cppeditor/cpptoolsreuse.h +++ b/src/plugins/cppeditor/cpptoolsreuse.h @@ -45,6 +45,8 @@ bool CPPEDITOR_EXPORT isValidFirstIdentifierChar(const QChar &ch); bool CPPEDITOR_EXPORT isValidIdentifierChar(const QChar &ch); bool CPPEDITOR_EXPORT isValidIdentifier(const QString &s); +int CPPEDITOR_EXPORT activeArgumenForPrefix(const QString &prefix); + QStringList CPPEDITOR_EXPORT identifierWordsUnderCursor(const QTextCursor &tc); QString CPPEDITOR_EXPORT identifierUnderCursor(QTextCursor *cursor); |