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 "baseeditordocumentparser.h"
29 #include "cppcursorinfo.h"
30 #include "cppsymbolinfo.h"
31 #include "cppsemanticinfo.h"
32 #include "cpptools_global.h"
33 
34 #include <coreplugin/helpitem.h>
35 #include <texteditor/codeassist/assistinterface.h>
36 #include <texteditor/quickfix.h>
37 #include <texteditor/texteditor.h>
38 #include <texteditor/textdocument.h>
39 
40 #include <cplusplus/CppDocument.h>
41 
42 #include <QTextEdit>
43 
44 #include <QVariant>
45 
46 #include <functional>
47 
48 namespace TextEditor {
49 class TextDocument;
50 }
51 
52 namespace CppTools {
53 
54 // For clang code model only, move?
55 struct CPPTOOLS_EXPORT ToolTipInfo {
56     QString text;
57     QString briefComment;
58 
59     QStringList qDocIdCandidates;
60     QString qDocMark;
61     Core::HelpItem::Category qDocCategory;
62     QVariant value;
63 
64     QString sizeInBytes;
65 };
66 
67 class CPPTOOLS_EXPORT BaseEditorDocumentProcessor : public QObject
68 {
69     Q_OBJECT
70 
71 public:
72     BaseEditorDocumentProcessor(QTextDocument *textDocument, const QString &filePath);
73     ~BaseEditorDocumentProcessor() override;
74 
75     void run(bool projectsUpdated = false);
76     virtual void semanticRehighlight() = 0;
77     virtual void recalculateSemanticInfoDetached(bool force) = 0;
78     virtual CppTools::SemanticInfo recalculateSemanticInfo() = 0;
79     virtual CPlusPlus::Snapshot snapshot() = 0;
80     virtual BaseEditorDocumentParser::Ptr parser() = 0;
81     virtual bool isParserRunning() const = 0;
82 
83     virtual TextEditor::QuickFixOperations
84     extraRefactoringOperations(const TextEditor::AssistInterface &assistInterface);
85 
86     virtual void invalidateDiagnostics();
87 
88     virtual void editorDocumentTimerRestarted();
89 
90     virtual void setParserConfig(const BaseEditorDocumentParser::Configuration &config);
91 
92     virtual QFuture<CursorInfo> cursorInfo(const CursorInfoParams &params) = 0;
93     virtual QFuture<CursorInfo> requestLocalReferences(const QTextCursor &cursor) = 0;
94     virtual QFuture<SymbolInfo> requestFollowSymbol(int line, int column) = 0;
95     virtual QFuture<ToolTipInfo> toolTipInfo(const QByteArray &codecName, int line, int column);
96 
filePath()97     QString filePath() const { return m_filePath; }
98 
99 public:
100     using HeaderErrorDiagnosticWidgetCreator = std::function<QWidget*()>;
101 
102 signals:
103     // Signal interface to implement
104     void projectPartInfoUpdated(const CppTools::ProjectPartInfo &projectPartInfo);
105 
106     void codeWarningsUpdated(unsigned revision,
107                              const QList<QTextEdit::ExtraSelection> &selections,
108                              const HeaderErrorDiagnosticWidgetCreator &creator,
109                              const TextEditor::RefactorMarkers &refactorMarkers);
110 
111     void ifdefedOutBlocksUpdated(unsigned revision,
112                                  const QList<TextEditor::BlockRange> &ifdefedOutBlocks);
113 
114     void cppDocumentUpdated(const CPlusPlus::Document::Ptr document);    // TODO: Remove me
115     void semanticInfoUpdated(const CppTools::SemanticInfo semanticInfo); // TODO: Remove me
116 
117 protected:
118     static void runParser(QFutureInterface<void> &future,
119                           BaseEditorDocumentParser::Ptr parser,
120                           BaseEditorDocumentParser::UpdateParams updateParams);
121 
122     // Convenience
revision()123     unsigned revision() const { return static_cast<unsigned>(m_textDocument->revision()); }
textDocument()124     QTextDocument *textDocument() const { return m_textDocument; }
125 
126 private:
127     virtual void runImpl(const BaseEditorDocumentParser::UpdateParams &updateParams) = 0;
128 
129 private:
130     QString m_filePath;
131     QTextDocument *m_textDocument;
132 };
133 
134 } // namespace CppTools
135