diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2021-06-18 16:30:03 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2021-08-23 09:06:31 +0000 |
commit | e0e8fda580c7ac5d55dbae746d5651a6ac9caf17 (patch) | |
tree | a946c99edeb6d9c04995fbaaf28340b085351e29 /src/plugins/clangcodemodel/clangutils.cpp | |
parent | 67d2a4186b0fca3d4ef7a1e31adc5cbeeeb15318 (diff) | |
download | qt-creator-e0e8fda580c7ac5d55dbae746d5651a6ac9caf17.tar.gz |
ClangCodeModel: Use clangd for completion and function hint
Change-Id: I80160f3a40da18ac178682afe6caba5e5af6e3eb
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/clangcodemodel/clangutils.cpp')
-rw-r--r-- | src/plugins/clangcodemodel/clangutils.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/plugins/clangcodemodel/clangutils.cpp b/src/plugins/clangcodemodel/clangutils.cpp index 57f3a522b8..1d3fbb7451 100644 --- a/src/plugins/clangcodemodel/clangutils.cpp +++ b/src/plugins/clangcodemodel/clangutils.cpp @@ -44,7 +44,9 @@ #include <projectexplorer/kitinformation.h> #include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/target.h> +#include <texteditor/codeassist/textdocumentmanipulatorinterface.h> +#include <cplusplus/SimpleLexer.h> #include <utils/algorithm.h> #include <utils/fileutils.h> #include <utils/qtcassert.h> @@ -608,5 +610,41 @@ const QStringList optionsForProject(ProjectExplorer::Project *project) return ClangProjectSettings::globalCommandLineOptions(); } +// 7.3.3: using typename(opt) nested-name-specifier unqualified-id ; +bool isAtUsingDeclaration(TextEditor::TextDocumentManipulatorInterface &manipulator, + int basePosition) +{ + using namespace CPlusPlus; + SimpleLexer lexer; + lexer.setLanguageFeatures(LanguageFeatures::defaultFeatures()); + const QString textToLex = textUntilPreviousStatement(manipulator, basePosition); + const Tokens tokens = lexer(textToLex); + if (tokens.empty()) + return false; + + // The nested-name-specifier always ends with "::", so check for this first. + const Token lastToken = tokens[tokens.size() - 1]; + if (lastToken.kind() != T_COLON_COLON) + return false; + + return contains(tokens, [](const Token &token) { return token.kind() == T_USING; }); +} + +QString textUntilPreviousStatement(TextEditor::TextDocumentManipulatorInterface &manipulator, + int startPosition) +{ + static const QString stopCharacters(";{}#"); + + int endPosition = 0; + for (int i = startPosition; i >= 0 ; --i) { + if (stopCharacters.contains(manipulator.characterAt(i))) { + endPosition = i + 1; + break; + } + } + + return manipulator.textAt(endPosition, startPosition - endPosition); +} + } // namespace Internal } // namespace Clang |