forked from qt-creator/qt-creator
C++: optionally let the highlighter handle ifdefed-out blocks.
Change-Id: I38cc0e55348cac0245d2ab8f3e39c68de76e3e6d Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
480f7c09fc
commit
073e5d6632
@@ -67,6 +67,7 @@ public:
|
||||
virtual bool requiresSemanticInfo() const = 0;
|
||||
|
||||
virtual bool hightlighterHandlesDiagnostics() const = 0;
|
||||
virtual bool hightlighterHandlesIfdefedOutBlocks() const = 0;
|
||||
|
||||
virtual QFuture<TextEditor::HighlightingResult> highlightingFuture(
|
||||
const CPlusPlus::Document::Ptr &doc,
|
||||
|
||||
@@ -49,6 +49,9 @@ public:
|
||||
virtual bool hightlighterHandlesDiagnostics() const
|
||||
{ return false; }
|
||||
|
||||
virtual bool hightlighterHandlesIfdefedOutBlocks() const
|
||||
{ return false; }
|
||||
|
||||
virtual QFuture<TextEditor::HighlightingResult> highlightingFuture(
|
||||
const CPlusPlus::Document::Ptr &doc,
|
||||
const CPlusPlus::Snapshot &snapshot) const;
|
||||
|
||||
@@ -969,3 +969,21 @@ void CppModelManager::setExtraDiagnostics(const QString &fileName,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CppModelManager::setIfdefedOutBlocks(const QString &fileName,
|
||||
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks)
|
||||
{
|
||||
QList<CppEditorSupport *> cppEditorSupports;
|
||||
|
||||
{
|
||||
QMutexLocker locker(&m_cppEditorSupportsMutex);
|
||||
cppEditorSupports = m_cppEditorSupports.values();
|
||||
}
|
||||
|
||||
foreach (CppEditorSupport *editorSupport, cppEditorSupports) {
|
||||
if (editorSupport->fileName() == fileName) {
|
||||
editorSupport->setIfdefedOutBlocks(ifdeffedOutBlocks);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,8 @@ public:
|
||||
|
||||
virtual void setExtraDiagnostics(const QString &fileName, const QString &key,
|
||||
const QList<Document::DiagnosticMessage> &diagnostics);
|
||||
virtual void setIfdefedOutBlocks(const QString &fileName,
|
||||
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks);
|
||||
|
||||
void finishedRefreshingSourceFiles(const QStringList &files);
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
namespace Core { class IEditor; }
|
||||
namespace CPlusPlus { class LookupContext; }
|
||||
namespace ProjectExplorer { class Project; }
|
||||
namespace TextEditor { class BaseTextEditor; }
|
||||
namespace TextEditor { class BaseTextEditor; class BlockRange; }
|
||||
namespace Utils { class FileName; }
|
||||
|
||||
namespace CppTools {
|
||||
@@ -238,6 +238,8 @@ public:
|
||||
|
||||
virtual void setExtraDiagnostics(const QString &fileName, const QString &kind,
|
||||
const QList<CPlusPlus::Document::DiagnosticMessage> &diagnostics) = 0;
|
||||
virtual void setIfdefedOutBlocks(const QString &fileName,
|
||||
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0;
|
||||
|
||||
virtual CppTools::CppCompletionSupport *completionSupport(Core::IEditor *editor) const = 0;
|
||||
virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0;
|
||||
|
||||
@@ -192,6 +192,13 @@ void CppEditorSupport::setExtraDiagnostics(const QString &key,
|
||||
emit diagnosticsChanged();
|
||||
}
|
||||
|
||||
void CppEditorSupport::setIfdefedOutBlocks(const QList<BlockRange> &ifdefedOutBlocks)
|
||||
{
|
||||
m_editorUpdates.ifdefedOutBlocks = ifdefedOutBlocks;
|
||||
|
||||
emit diagnosticsChanged();
|
||||
}
|
||||
|
||||
bool CppEditorSupport::initialized()
|
||||
{
|
||||
return m_initialized;
|
||||
@@ -262,11 +269,13 @@ void CppEditorSupport::onDocumentUpdated(Document::Ptr doc)
|
||||
return; // outdated content, wait for a new document to be parsed
|
||||
|
||||
// Update the ifdeffed-out blocks:
|
||||
QList<Document::Block> skippedBlocks = doc->skippedBlocks();
|
||||
m_editorUpdates.ifdefedOutBlocks.clear();
|
||||
m_editorUpdates.ifdefedOutBlocks.reserve(skippedBlocks.size());
|
||||
foreach (const Document::Block &block, skippedBlocks) {
|
||||
m_editorUpdates.ifdefedOutBlocks.append(BlockRange(block.begin(), block.end()));
|
||||
if (m_highlightingSupport && !m_highlightingSupport->hightlighterHandlesIfdefedOutBlocks()) {
|
||||
QList<Document::Block> skippedBlocks = doc->skippedBlocks();
|
||||
QList<BlockRange> ifdefedOutBlocks;
|
||||
ifdefedOutBlocks.reserve(skippedBlocks.size());
|
||||
foreach (const Document::Block &block, skippedBlocks)
|
||||
ifdefedOutBlocks.append(BlockRange(block.begin(), block.end()));
|
||||
setIfdefedOutBlocks(ifdefedOutBlocks);
|
||||
}
|
||||
|
||||
if (m_highlightingSupport && !m_highlightingSupport->hightlighterHandlesDiagnostics()) {
|
||||
|
||||
@@ -86,6 +86,8 @@ class CPPTOOLS_EXPORT CppEditorSupport: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
typedef TextEditor::BlockRange BlockRange;
|
||||
|
||||
public:
|
||||
CppEditorSupport(Internal::CppModelManager *modelManager, TextEditor::BaseTextEditor *textEditor);
|
||||
virtual ~CppEditorSupport();
|
||||
@@ -97,6 +99,7 @@ public:
|
||||
|
||||
void setExtraDiagnostics(const QString &key,
|
||||
const QList<CPlusPlus::Document::DiagnosticMessage> &messages);
|
||||
void setIfdefedOutBlocks(const QList<BlockRange> &ifdefedOutBlocks);
|
||||
|
||||
/// True after the document was parsed/updated for the first time
|
||||
/// and the first semantic info calculation was started.
|
||||
@@ -136,7 +139,6 @@ private slots:
|
||||
void updateEditorNow();
|
||||
|
||||
private:
|
||||
typedef TextEditor::BaseTextEditorWidget::BlockRange BlockRange;
|
||||
struct EditorUpdates {
|
||||
EditorUpdates()
|
||||
: revision(-1)
|
||||
|
||||
Reference in New Issue
Block a user