Commit 073e5d66 authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Nikolai Kosjar

C++: optionally let the highlighter handle ifdefed-out blocks.

Change-Id: I38cc0e55348cac0245d2ab8f3e39c68de76e3e6d
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 480f7c09
......@@ -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)
......
......@@ -5416,7 +5416,7 @@ QString BaseTextEditorWidget::extraSelectionTooltip(int pos) const
}
// the blocks list must be sorted
void BaseTextEditorWidget::setIfdefedOutBlocks(const QList<BaseTextEditorWidget::BlockRange> &blocks)
void BaseTextEditorWidget::setIfdefedOutBlocks(const QList<BlockRange> &blocks)
{
QTextDocument *doc = document();
BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(doc->documentLayout());
......@@ -5433,11 +5433,12 @@ void BaseTextEditorWidget::setIfdefedOutBlocks(const QList<BaseTextEditorWidget:
bool set = false;
if (rangeNumber < blocks.size()) {
const BlockRange &range = blocks.at(rangeNumber);
if (block.position() >= range.first && ((block.position() + block.length() - 1) <= range.last || !range.last))
if (block.position() >= range.first()
&& ((block.position() + block.length() - 1) <= range.last() || !range.last()))
set = BaseTextDocumentLayout::setIfdefedOut(block);
else
cleared = BaseTextDocumentLayout::clearIfdefedOut(block);
if (block.contains(range.last))
if (block.contains(range.last()))
++rangeNumber;
} else {
cleared = BaseTextDocumentLayout::clearIfdefedOut(block);
......
......@@ -428,18 +428,6 @@ signals:
void refactorMarkerClicked(const TextEditor::RefactorMarker &marker);
public:
struct BlockRange
{
BlockRange() : first(0), last(-1) {}
BlockRange(int first_position, int last_position)
: first(first_position), last(last_position)
{}
int first;
int last;
inline bool isNull() const { return last < first; }
};
// the blocks list must be sorted
void setIfdefedOutBlocks(const QList<BlockRange> &blocks);
......
......@@ -56,6 +56,25 @@ namespace Utils {
namespace TextEditor {
class TEXTEDITOR_EXPORT BlockRange
{
public:
BlockRange() : _first(0), _last(-1) {}
BlockRange(int firstPosition, int lastPosition)
: _first(firstPosition), _last(lastPosition)
{}
inline bool isNull() const { return _last < _first; }
int first() const { return _first; }
int last() const { return _last; }
private:
int _first;
int _last;
};
class TEXTEDITOR_EXPORT ITextEditorDocument : public Core::TextDocument
{
Q_OBJECT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment