| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2015-01-14 18:07:15 +01:00
										 |  |  | ** Copyright (C) 2015 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: http://www.qt.io/licensing
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							| 
									
										
										
										
											2015-01-14 18:07:15 +01:00
										 |  |  | ** a written agreement between you and The Qt Company.  For licensing terms and | 
					
						
							|  |  |  | ** conditions see http://www.qt.io/terms-conditions.  For further information
 | 
					
						
							| 
									
										
										
										
											2014-10-16 12:00:23 +02:00
										 |  |  | ** use the contact form at http://www.qt.io/contact-us.
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							| 
									
										
										
										
											2014-10-16 12:00:23 +02:00
										 |  |  | ** General Public License version 2.1 or version 3 as published by the Free | 
					
						
							|  |  |  | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | 
					
						
							|  |  |  | ** LICENSE.LGPLv3 included in the packaging of this file.  Please review the | 
					
						
							|  |  |  | ** following information to ensure the GNU Lesser General Public License | 
					
						
							|  |  |  | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
 | 
					
						
							|  |  |  | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2015-01-14 18:07:15 +01:00
										 |  |  | ** In addition, as a special exception, The Qt Company gives you certain additional | 
					
						
							|  |  |  | ** rights.  These rights are described in The Qt Company LGPL Exception | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "clangeditordocumentprocessor.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 18:26:09 +02:00
										 |  |  | #include "clangfixitoperation.h"
 | 
					
						
							|  |  |  | #include "clangfixitoperationsextractor.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-30 09:43:50 +01:00
										 |  |  | #include "clanghighlightingmarksreporter.h"
 | 
					
						
							| 
									
										
										
										
											2015-05-08 15:48:17 +02:00
										 |  |  | #include "clangmodelmanagersupport.h"
 | 
					
						
							|  |  |  | #include "clangutils.h"
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  | #include <diagnosticcontainer.h>
 | 
					
						
							|  |  |  | #include <sourcelocationcontainer.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-10 16:54:53 +01:00
										 |  |  | #include <cpptools/cppcodemodelsettings.h>
 | 
					
						
							| 
									
										
										
										
											2015-12-15 11:59:48 +01:00
										 |  |  | #include <cpptools/cppmodelmanager.h>
 | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  | #include <cpptools/cppprojects.h>
 | 
					
						
							| 
									
										
										
										
											2015-11-10 16:54:53 +01:00
										 |  |  | #include <cpptools/cpptoolsreuse.h>
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | #include <cpptools/cppworkingcopy.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 18:26:09 +02:00
										 |  |  | #include <texteditor/convenience.h>
 | 
					
						
							| 
									
										
										
										
											2015-09-10 14:18:09 +02:00
										 |  |  | #include <texteditor/fontsettings.h>
 | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  | #include <texteditor/texteditor.h>
 | 
					
						
							| 
									
										
										
										
											2015-09-10 14:18:09 +02:00
										 |  |  | #include <texteditor/texteditorconstants.h>
 | 
					
						
							|  |  |  | #include <texteditor/texteditorsettings.h>
 | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | #include <cplusplus/CppDocument.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <utils/qtcassert.h>
 | 
					
						
							|  |  |  | #include <utils/QtConcurrentTools>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  | #include <QTextBlock>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | namespace ClangCodeModel { | 
					
						
							| 
									
										
										
										
											2015-05-08 15:48:17 +02:00
										 |  |  | namespace Internal { | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 15:48:17 +02:00
										 |  |  | ClangEditorDocumentProcessor::ClangEditorDocumentProcessor( | 
					
						
							|  |  |  |         ModelManagerSupportClang *modelManagerSupport, | 
					
						
							|  |  |  |         TextEditor::TextDocument *document) | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  |     : BaseEditorDocumentProcessor(document) | 
					
						
							| 
									
										
										
										
											2015-09-04 12:15:17 +02:00
										 |  |  |     , m_diagnosticManager(document) | 
					
						
							| 
									
										
										
										
											2015-05-08 15:48:17 +02:00
										 |  |  |     , m_modelManagerSupport(modelManagerSupport) | 
					
						
							| 
									
										
										
										
											2015-09-01 17:34:07 +02:00
										 |  |  |     , m_parser(new ClangEditorDocumentParser(document->filePath().toString())) | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  |     , m_parserRevision(0) | 
					
						
							|  |  |  |     , m_semanticHighlighter(document) | 
					
						
							|  |  |  |     , m_builtinProcessor(document, /*enableSemanticHighlighter=*/ false) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // Forwarding the semantic info from the builtin processor enables us to provide all
 | 
					
						
							|  |  |  |     // editor (widget) related features that are not yet implemented by the clang plugin.
 | 
					
						
							|  |  |  |     connect(&m_builtinProcessor, &CppTools::BuiltinEditorDocumentProcessor::cppDocumentUpdated, | 
					
						
							|  |  |  |             this, &ClangEditorDocumentProcessor::cppDocumentUpdated); | 
					
						
							|  |  |  |     connect(&m_builtinProcessor, &CppTools::BuiltinEditorDocumentProcessor::semanticInfoUpdated, | 
					
						
							|  |  |  |             this, &ClangEditorDocumentProcessor::semanticInfoUpdated); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_parserWatcher.cancel(); | 
					
						
							|  |  |  |     m_parserWatcher.waitForFinished(); | 
					
						
							| 
									
										
										
										
											2015-05-08 15:48:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 19:01:32 +02:00
										 |  |  |     if (m_projectPart) { | 
					
						
							|  |  |  |         QTC_ASSERT(m_modelManagerSupport, return); | 
					
						
							| 
									
										
										
										
											2015-08-31 16:10:36 +02:00
										 |  |  |         m_modelManagerSupport->ipcCommunicator().unregisterTranslationUnitsForEditor( | 
					
						
							| 
									
										
										
										
											2015-07-14 19:01:32 +02:00
										 |  |  |             {ClangBackEnd::FileContainer(filePath(), m_projectPart->id())}); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ClangEditorDocumentProcessor::run() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  |     updateTranslationUnitIfProjectPartExists(); | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  |     // Run clang parser
 | 
					
						
							|  |  |  |     disconnect(&m_parserWatcher, &QFutureWatcher<void>::finished, | 
					
						
							|  |  |  |                this, &ClangEditorDocumentProcessor::onParserFinished); | 
					
						
							|  |  |  |     m_parserWatcher.cancel(); | 
					
						
							|  |  |  |     m_parserWatcher.setFuture(QFuture<void>()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_parserRevision = revision(); | 
					
						
							|  |  |  |     connect(&m_parserWatcher, &QFutureWatcher<void>::finished, | 
					
						
							|  |  |  |             this, &ClangEditorDocumentProcessor::onParserFinished); | 
					
						
							| 
									
										
										
										
											2015-07-10 14:57:42 +02:00
										 |  |  |     const QFuture<void> future = QtConcurrent::run(&runParser, | 
					
						
							|  |  |  |                                                    parser(), | 
					
						
							|  |  |  |                                                    ClangEditorDocumentParser::InMemoryInfo(true)); | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  |     m_parserWatcher.setFuture(future); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Run builtin processor
 | 
					
						
							|  |  |  |     m_builtinProcessor.run(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-19 14:37:26 +02:00
										 |  |  | void ClangEditorDocumentProcessor::recalculateSemanticInfoDetached(bool force) | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-06-19 14:37:26 +02:00
										 |  |  |     m_builtinProcessor.recalculateSemanticInfoDetached(force); | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-19 14:43:41 +02:00
										 |  |  | void ClangEditorDocumentProcessor::semanticRehighlight() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_semanticHighlighter.updateFormatMapFromFontSettings(); | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_projectPart) | 
					
						
							|  |  |  |         requestDocumentAnnotations(m_projectPart->id()); | 
					
						
							| 
									
										
										
										
											2015-06-19 14:43:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | CppTools::SemanticInfo ClangEditorDocumentProcessor::recalculateSemanticInfo() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_builtinProcessor.recalculateSemanticInfo(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-01 17:34:07 +02:00
										 |  |  | CppTools::BaseEditorDocumentParser::Ptr ClangEditorDocumentProcessor::parser() | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-09-01 17:34:07 +02:00
										 |  |  |     return m_parser; | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-28 12:03:58 +01:00
										 |  |  | CPlusPlus::Snapshot ClangEditorDocumentProcessor::snapshot() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |    return m_builtinProcessor.snapshot(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | bool ClangEditorDocumentProcessor::isParserRunning() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_parserWatcher.isRunning(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-28 15:15:25 +02:00
										 |  |  | bool ClangEditorDocumentProcessor::hasProjectPart() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_projectPart; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 19:01:32 +02:00
										 |  |  | CppTools::ProjectPart::Ptr ClangEditorDocumentProcessor::projectPart() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_projectPart; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-18 12:19:46 +02:00
										 |  |  | void ClangEditorDocumentProcessor::clearProjectPart() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_projectPart.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  | void ClangEditorDocumentProcessor::updateCodeWarnings(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics, | 
					
						
							|  |  |  |                                                       uint documentRevision) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (documentRevision == revision()) { | 
					
						
							| 
									
										
										
										
											2015-09-04 12:15:17 +02:00
										 |  |  |         m_diagnosticManager.processNewDiagnostics(diagnostics); | 
					
						
							|  |  |  |         const auto codeWarnings = m_diagnosticManager.takeExtraSelections(); | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  |         emit codeWarningsUpdated(revision(), codeWarnings); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-12-02 20:07:29 +01:00
										 |  |  | namespace { | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-02 20:07:29 +01:00
										 |  |  | int positionInText(QTextDocument *textDocument, | 
					
						
							|  |  |  |                    const ClangBackEnd::SourceLocationContainer &sourceLocationContainer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto textBlock = textDocument->findBlockByNumber(int(sourceLocationContainer.line()) - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return textBlock.position() + int(sourceLocationContainer.column()) - 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TextEditor::BlockRange | 
					
						
							|  |  |  | toTextEditorBlock(QTextDocument *textDocument, | 
					
						
							|  |  |  |                   const ClangBackEnd::SourceRangeContainer &sourceRangeContainer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return TextEditor::BlockRange(positionInText(textDocument, sourceRangeContainer.start()), | 
					
						
							|  |  |  |                                   positionInText(textDocument, sourceRangeContainer.end())); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QList<TextEditor::BlockRange> | 
					
						
							|  |  |  | toTextEditorBlocks(QTextDocument *textDocument, | 
					
						
							|  |  |  |                    const QVector<ClangBackEnd::SourceRangeContainer> &ifdefedOutRanges) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QList<TextEditor::BlockRange> blockRanges; | 
					
						
							|  |  |  |     blockRanges.reserve(ifdefedOutRanges.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (const auto &range : ifdefedOutRanges) | 
					
						
							| 
									
										
										
										
											2015-12-02 20:07:29 +01:00
										 |  |  |         blockRanges.append(toTextEditorBlock(textDocument, range)); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return blockRanges; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-12-02 20:07:29 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ClangEditorDocumentProcessor::updateHighlighting( | 
					
						
							|  |  |  |         const QVector<ClangBackEnd::HighlightingMarkContainer> &highlightingMarks, | 
					
						
							|  |  |  |         const QVector<ClangBackEnd::SourceRangeContainer> &skippedPreprocessorRanges, | 
					
						
							|  |  |  |         uint documentRevision) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (documentRevision == revision()) { | 
					
						
							| 
									
										
										
										
											2015-12-02 20:07:29 +01:00
										 |  |  |         const auto skippedPreprocessorBlocks = toTextEditorBlocks(textDocument(), skippedPreprocessorRanges); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |         emit ifdefedOutBlocksUpdated(documentRevision, skippedPreprocessorBlocks); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_semanticHighlighter.setHighlightingRunner( | 
					
						
							|  |  |  |             [highlightingMarks]() { | 
					
						
							|  |  |  |                 auto *reporter = new HighlightingMarksReporter(highlightingMarks); | 
					
						
							|  |  |  |                 return reporter->start(); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         m_semanticHighlighter.run(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-24 18:26:09 +02:00
										 |  |  | static int currentLine(const TextEditor::AssistInterface &assistInterface) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int line, column; | 
					
						
							|  |  |  |     TextEditor::Convenience::convertPosition(assistInterface.textDocument(), | 
					
						
							|  |  |  |                                              assistInterface.position(), | 
					
						
							|  |  |  |                                              &line, | 
					
						
							|  |  |  |                                              &column); | 
					
						
							|  |  |  |     return line; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TextEditor::QuickFixOperations ClangEditorDocumentProcessor::extraRefactoringOperations( | 
					
						
							|  |  |  |         const TextEditor::AssistInterface &assistInterface) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ClangFixItOperationsExtractor extractor(m_diagnosticManager.diagnosticsWithFixIts()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return extractor.extract(assistInterface.fileName(), currentLine(assistInterface)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  | ClangBackEnd::FileContainer ClangEditorDocumentProcessor::fileContainerWithArguments() const | 
					
						
							| 
									
										
										
										
											2015-10-05 11:17:03 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  |     return fileContainerWithArguments(m_projectPart.data()); | 
					
						
							| 
									
										
										
										
											2015-10-05 11:17:03 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 15:11:23 +01:00
										 |  |  | void ClangEditorDocumentProcessor::clearDiagnosticsWithFixIts() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_diagnosticManager.clearDiagnosticsWithFixIts(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 19:01:32 +02:00
										 |  |  | ClangEditorDocumentProcessor *ClangEditorDocumentProcessor::get(const QString &filePath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return qobject_cast<ClangEditorDocumentProcessor *>(BaseEditorDocumentProcessor::get(filePath)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-24 12:17:43 +02:00
										 |  |  | static bool isProjectPartLoadedOrIsFallback(CppTools::ProjectPart::Ptr projectPart) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return projectPart | 
					
						
							| 
									
										
										
										
											2015-09-24 14:25:53 +02:00
										 |  |  |         && (projectPart->id().isEmpty() || ClangCodeModel::Utils::isProjectPartLoaded(projectPart)); | 
					
						
							| 
									
										
										
										
											2015-09-24 12:17:43 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor() | 
					
						
							| 
									
										
										
										
											2015-07-14 19:01:32 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     const CppTools::ProjectPart::Ptr projectPart = m_parser->projectPart(); | 
					
						
							| 
									
										
										
										
											2015-07-14 19:01:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-24 12:17:43 +02:00
										 |  |  |     if (isProjectPartLoadedOrIsFallback(projectPart)) { | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  |         registerTranslationUnitForEditor(projectPart.data()); | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-24 12:17:43 +02:00
										 |  |  |         m_projectPart = projectPart; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-14 19:01:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | void ClangEditorDocumentProcessor::onParserFinished() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (revision() != m_parserRevision) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  |     updateProjectPartAndTranslationUnitForEditor(); | 
					
						
							| 
									
										
										
										
											2015-07-14 19:01:32 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  | void ClangEditorDocumentProcessor::registerTranslationUnitForEditor(CppTools::ProjectPart *projectPart) | 
					
						
							| 
									
										
										
										
											2015-07-14 19:01:32 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QTC_ASSERT(m_modelManagerSupport, return); | 
					
						
							|  |  |  |     IpcCommunicator &ipcCommunicator = m_modelManagerSupport->ipcCommunicator(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (m_projectPart) { | 
					
						
							| 
									
										
										
										
											2015-10-05 11:17:03 +02:00
										 |  |  |         if (projectPart->id() != m_projectPart->id()) { | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  |             ipcCommunicator.unregisterTranslationUnitsForEditor({fileContainerWithArguments()}); | 
					
						
							|  |  |  |             ipcCommunicator.registerTranslationUnitsForEditor({fileContainerWithArguments(projectPart)}); | 
					
						
							| 
									
										
										
										
											2015-07-14 19:01:32 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  |         ipcCommunicator.registerTranslationUnitsForEditor({{fileContainerWithArguments(projectPart)}}); | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  | void ClangEditorDocumentProcessor::updateTranslationUnitIfProjectPartExists() | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  |     if (m_projectPart) { | 
					
						
							|  |  |  |         const ClangBackEnd::FileContainer fileContainer = fileContainerWithDocumentContent(m_projectPart->id()); | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  |         m_modelManagerSupport->ipcCommunicator().updateTranslationUnitWithRevisionCheck(fileContainer); | 
					
						
							| 
									
										
										
										
											2015-08-31 16:28:26 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  | void ClangEditorDocumentProcessor::requestDocumentAnnotations(const QString &projectpartId) | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  |     const auto fileContainer = fileContainerWithDocumentContent(projectpartId); | 
					
						
							| 
									
										
										
										
											2015-11-18 17:07:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  |     auto &ipcCommunicator = m_modelManagerSupport->ipcCommunicator(); | 
					
						
							|  |  |  |     ipcCommunicator.requestDiagnostics(fileContainer); | 
					
						
							|  |  |  |     ipcCommunicator.requestHighlighting(fileContainer); | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  | static CppTools::ProjectPart projectPartForLanguageOption(CppTools::ProjectPart *projectPart) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (projectPart) | 
					
						
							|  |  |  |         return *projectPart; | 
					
						
							|  |  |  |     return *CppTools::CppModelManager::instance()->fallbackProjectPart().data(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static QStringList languageOptions(const QString &filePath, CppTools::ProjectPart *projectPart) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 11:47:01 +01:00
										 |  |  |     const auto theProjectPart = projectPartForLanguageOption(projectPart); | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     CppTools::CompilerOptionsBuilder builder(theProjectPart); | 
					
						
							|  |  |  |     builder.addLanguageOption(CppTools::ProjectFile::classify(filePath)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return builder.options(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-10 16:54:53 +01:00
										 |  |  | static QStringList fileArguments(const QString &filePath, CppTools::ProjectPart *projectPart) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QStringList(languageOptions(filePath, projectPart)) | 
					
						
							|  |  |  |          + CppTools::codeModelSettings()->extraClangOptions(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-05 11:17:03 +02:00
										 |  |  | ClangBackEnd::FileContainer | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  | ClangEditorDocumentProcessor::fileContainerWithArguments(CppTools::ProjectPart *projectPart) const | 
					
						
							| 
									
										
										
										
											2015-10-05 11:17:03 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-05 13:57:57 +01:00
										 |  |  |     const auto projectPartId = projectPart | 
					
						
							|  |  |  |             ? Utf8String::fromString(projectPart->id()) | 
					
						
							|  |  |  |             : Utf8String(); | 
					
						
							| 
									
										
										
										
											2015-11-10 16:54:53 +01:00
										 |  |  |     const QStringList theFileArguments = fileArguments(filePath(), projectPart); | 
					
						
							| 
									
										
										
										
											2015-10-05 11:17:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-10 16:54:53 +01:00
										 |  |  |     return {filePath(), projectPartId, Utf8StringVector(theFileArguments), revision()}; | 
					
						
							| 
									
										
										
										
											2015-10-05 11:17:03 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-30 10:55:25 +01:00
										 |  |  | ClangBackEnd::FileContainer | 
					
						
							|  |  |  | ClangEditorDocumentProcessor::fileContainerWithDocumentContent(const QString &projectpartId) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return ClangBackEnd::FileContainer(filePath(), | 
					
						
							|  |  |  |                                        projectpartId, | 
					
						
							|  |  |  |                                        baseTextDocument()->plainText(), | 
					
						
							|  |  |  |                                        true, | 
					
						
							|  |  |  |                                        revision()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-08 15:48:17 +02:00
										 |  |  | } // namespace Internal
 | 
					
						
							| 
									
										
										
										
											2014-08-19 15:59:29 +02:00
										 |  |  | } // namespace ClangCodeModel
 |