1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include <cplusplus/Token.h> 29 30 #include <QString> 31 32 namespace TextEditor { class AssistInterface; } 33 34 namespace ClangCodeModel { 35 namespace Internal { 36 37 class ClangCompletionAssistInterface; 38 39 class ClangCompletionContextAnalyzer 40 { 41 public: 42 ClangCompletionContextAnalyzer() = delete; 43 ClangCompletionContextAnalyzer(const ClangCompletionAssistInterface *assistInterface, 44 CPlusPlus::LanguageFeatures languageFeatures); 45 void analyze(); 46 47 enum CompletionAction { 48 PassThroughToLibClang, 49 PassThroughToLibClangAfterLeftParen, 50 CompleteDoxygenKeyword, 51 CompleteIncludePath, 52 CompletePreprocessorDirective, 53 CompleteSignal, 54 CompleteSlot, 55 CompleteNone 56 }; completionAction()57 CompletionAction completionAction() const { return m_completionAction; } completionOperator()58 unsigned completionOperator() const { return m_completionOperator; } positionForProposal()59 int positionForProposal() const { return m_positionForProposal; } positionForClang()60 int positionForClang() const { return m_positionForClang; } functionNameStart()61 int functionNameStart() const { return m_functionNameStart; } positionEndOfExpression()62 int positionEndOfExpression() const { return m_positionEndOfExpression; } addSnippets()63 bool addSnippets() const { return m_addSnippets; } 64 65 private: 66 int startOfFunctionCall(int endOfExpression) const; 67 68 void setActionAndClangPosition(CompletionAction action, 69 int position, 70 int functionNameStart = -1); 71 void setAction(CompletionAction action); 72 73 bool handleNonFunctionCall(int position); 74 void handleCommaInFunctionCall(); 75 void handleFunctionCall(int endOfOperator); 76 77 private: 78 const ClangCompletionAssistInterface *m_interface; // Not owned 79 const CPlusPlus::LanguageFeatures m_languageFeatures; // TODO: Get from assistInterface?! 80 81 // Results 82 CompletionAction m_completionAction = PassThroughToLibClang; 83 CPlusPlus::Kind m_completionOperator = CPlusPlus::T_EOF_SYMBOL; 84 int m_positionForProposal = -1; 85 int m_positionForClang = -1; 86 int m_functionNameStart = -1; 87 int m_positionEndOfExpression = -1; 88 bool m_addSnippets = false; 89 }; 90 91 } // namespace Internal 92 } // namespace ClangCodeModel 93