Commit a6e04c36 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: CppHighlightingSupport takes a BaseTextDocument

...instead an ITextEditor.

The ITextEditor was only used to access the file path and QTextDocument
via the BaseTextEditorWidget.

Change-Id: Idef2b8162b992fe3718e16e2a046e2ff214846f2
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent fc7f5ba3
......@@ -29,21 +29,19 @@
#include "clanghighlightingsupport.h"
#include <coreplugin/idocument.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/itexteditor.h>
#include <texteditor/basetextdocument.h>
#include <QTextBlock>
#include <QTextEdit>
#include "pchmanager.h"
using namespace ClangCodeModel;
using namespace ClangCodeModel::Internal;
using namespace CppTools;
ClangHighlightingSupport::ClangHighlightingSupport(TextEditor::ITextEditor *textEditor, FastIndexer *fastIndexer)
: CppHighlightingSupport(textEditor)
ClangHighlightingSupport::ClangHighlightingSupport(TextEditor::BaseTextDocument *baseTextDocument,
FastIndexer *fastIndexer)
: CppHighlightingSupport(baseTextDocument)
, m_fastIndexer(fastIndexer)
, m_semanticMarker(new ClangCodeModel::SemanticMarker)
{
......@@ -69,11 +67,10 @@ QFuture<TextEditor::HighlightingResult> ClangHighlightingSupport::highlightingFu
Q_UNUSED(doc);
Q_UNUSED(snapshot);
TextEditor::BaseTextEditorWidget *ed = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor()->widget());
int firstLine = 1;
int lastLine = ed->document()->blockCount();
int lastLine = baseTextDocument()->document()->blockCount();
const QString fileName = editor()->document()->filePath();
const QString fileName = baseTextDocument()->filePath();
CppModelManagerInterface *modelManager = CppModelManagerInterface::instance();
QList<ProjectPart::Ptr> parts = modelManager->projectPart(fileName);
if (parts.isEmpty())
......
......@@ -44,7 +44,7 @@ namespace ClangCodeModel {
class ClangHighlightingSupport: public CppTools::CppHighlightingSupport
{
public:
ClangHighlightingSupport(TextEditor::ITextEditor *textEditor,
ClangHighlightingSupport(TextEditor::BaseTextDocument *baseTextDocument,
Internal::FastIndexer *fastIndexer);
~ClangHighlightingSupport();
......
......@@ -64,7 +64,7 @@ CppTools::CppCompletionAssistProvider *ModelManagerSupport::completionAssistProv
}
CppTools::CppHighlightingSupport *ModelManagerSupport::highlightingSupport(
TextEditor::ITextEditor *editor)
TextEditor::BaseTextDocument *baseTextDocument)
{
return new ClangHighlightingSupport(editor, m_fastIndexer);
return new ClangHighlightingSupport(baseTextDocument, m_fastIndexer);
}
......@@ -51,7 +51,8 @@ public:
virtual QString displayName() const;
virtual CppTools::CppCompletionAssistProvider *completionAssistProvider();
virtual CppTools::CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor);
virtual CppTools::CppHighlightingSupport *highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument);
private:
QScopedPointer<CppTools::CppCompletionAssistProvider> m_completionAssistProvider;
......
......@@ -31,10 +31,10 @@
using namespace CppTools;
CppHighlightingSupport::CppHighlightingSupport(TextEditor::ITextEditor *editor)
: m_editor(editor)
CppHighlightingSupport::CppHighlightingSupport(TextEditor::BaseTextDocument *baseTextDocument)
: m_baseTextDocument(baseTextDocument)
{
Q_ASSERT(editor);
Q_ASSERT(baseTextDocument);
}
CppHighlightingSupport::~CppHighlightingSupport()
......
......@@ -38,7 +38,7 @@
#include <QFuture>
namespace TextEditor { class ITextEditor; }
namespace TextEditor { class BaseTextDocument; }
namespace CppTools {
......@@ -60,7 +60,7 @@ public:
};
public:
CppHighlightingSupport(TextEditor::ITextEditor *editor);
CppHighlightingSupport(TextEditor::BaseTextDocument *baseTextDocument);
virtual ~CppHighlightingSupport() = 0;
virtual bool requiresSemanticInfo() const = 0;
......@@ -73,11 +73,11 @@ public:
const CPlusPlus::Snapshot &snapshot) const = 0;
protected:
TextEditor::ITextEditor *editor() const
{ return m_editor; }
TextEditor::BaseTextDocument *baseTextDocument() const
{ return m_baseTextDocument; }
private:
TextEditor::ITextEditor *m_editor;
TextEditor::BaseTextDocument *m_baseTextDocument;
};
} // namespace CppTools
......
......@@ -32,7 +32,8 @@
#include "cppchecksymbols.h"
#include "cpptoolsreuse.h"
#include <texteditor/itexteditor.h>
#include <texteditor/basetextdocument.h>
#include <texteditor/convenience.h>
#include <cplusplus/SimpleLexer.h>
......@@ -40,8 +41,9 @@ using namespace CPlusPlus;
using namespace CppTools;
using namespace CppTools::Internal;
CppHighlightingSupportInternal::CppHighlightingSupportInternal(TextEditor::ITextEditor *editor)
: CppHighlightingSupport(editor)
CppHighlightingSupportInternal::CppHighlightingSupportInternal(
TextEditor::BaseTextDocument *baseTextDocument)
: CppHighlightingSupport(baseTextDocument)
{
}
......@@ -56,10 +58,14 @@ QFuture<TextEditor::HighlightingResult> CppHighlightingSupportInternal::highligh
typedef TextEditor::HighlightingResult Result;
QList<Result> macroUses;
QTextDocument *textDocument = baseTextDocument()->document();
using TextEditor::Convenience::convertPosition;
// Get macro definitions
foreach (const CPlusPlus::Macro& macro, doc->definedMacros()) {
int line, column;
editor()->convertPosition(macro.utf16CharOffset(), &line, &column);
convertPosition(textDocument, macro.utf16CharOffset(), &line, &column);
++column; //Highlighting starts at (column-1) --> compensate here
Result use(line, column, macro.nameToQString().size(), MacroUse);
macroUses.append(use);
......@@ -86,7 +92,7 @@ QFuture<TextEditor::HighlightingResult> CppHighlightingSupportInternal::highligh
continue;
int line, column;
editor()->convertPosition(macro.utf16charsBegin(), &line, &column);
convertPosition(textDocument, macro.utf16charsBegin(), &line, &column);
++column; //Highlighting starts at (column-1) --> compensate here
Result use(line, column, name.size(), MacroUse);
macroUses.append(use);
......
......@@ -40,7 +40,7 @@ namespace Internal {
class CppHighlightingSupportInternal: public CppHighlightingSupport
{
public:
CppHighlightingSupportInternal(TextEditor::ITextEditor *editor);
CppHighlightingSupportInternal(TextEditor::BaseTextDocument *baseTextDocument);
virtual ~CppHighlightingSupportInternal();
virtual bool requiresSemanticInfo() const
......
......@@ -895,15 +895,13 @@ CppCompletionAssistProvider *CppModelManager::completionAssistProvider(const QSt
return cms->completionAssistProvider();
}
CppHighlightingSupport *CppModelManager::highlightingSupport(Core::IEditor *editor) const
CppHighlightingSupport *CppModelManager::highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument) const
{
TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor);
if (!textEditor)
return 0;
ModelManagerSupport *cms = modelManagerSupportForMimeType(editor->document()->mimeType());
return cms->highlightingSupport(textEditor);
QTC_ASSERT(baseTextDocument, return 0);
ModelManagerSupport *cms = modelManagerSupportForMimeType(baseTextDocument->mimeType());
QTC_ASSERT(cms, return 0);
return cms->highlightingSupport(baseTextDocument);
}
void CppModelManager::setIndexingSupport(CppIndexingSupport *indexingSupport)
......
......@@ -115,7 +115,8 @@ public:
virtual void addModelManagerSupport(ModelManagerSupport *modelManagerSupport);
virtual ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const;
virtual CppCompletionAssistProvider *completionAssistProvider(const QString &mimeType) const;
virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const;
virtual CppHighlightingSupport *highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument) const;
virtual void setIndexingSupport(CppIndexingSupport *indexingSupport);
virtual CppIndexingSupport *indexingSupport();
......
......@@ -47,7 +47,7 @@
namespace Core { class IEditor; }
namespace CPlusPlus { class LookupContext; }
namespace ProjectExplorer { class Project; }
namespace TextEditor { class BaseTextEditor; class BlockRange; }
namespace TextEditor { class BaseTextEditor; class BaseTextDocument; class BlockRange; }
namespace Utils { class FileName; }
namespace CppTools {
......@@ -260,7 +260,8 @@ public:
virtual void addModelManagerSupport(ModelManagerSupport *modelManagerSupport) = 0;
virtual ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const = 0;
virtual CppCompletionAssistProvider *completionAssistProvider(const QString &mimeType) const = 0;
virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0;
virtual CppHighlightingSupport *highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument) const = 0;
virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0;
virtual CppIndexingSupport *indexingSupport() = 0;
......
......@@ -34,7 +34,7 @@
#include <QString>
namespace TextEditor { class ITextEditor; }
namespace TextEditor { class BaseTextDocument; }
namespace CppTools {
......@@ -50,7 +50,8 @@ public:
virtual QString displayName() const = 0;
virtual CppCompletionAssistProvider *completionAssistProvider() = 0;
virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor) = 0;
virtual CppHighlightingSupport *highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument) = 0;
};
} // CppTools namespace
......
......@@ -61,7 +61,8 @@ CppCompletionAssistProvider *ModelManagerSupportInternal::completionAssistProvid
return m_completionAssistProvider.data();
}
CppHighlightingSupport *ModelManagerSupportInternal::highlightingSupport(TextEditor::ITextEditor *editor)
CppHighlightingSupport *ModelManagerSupportInternal::highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument)
{
return new CppHighlightingSupportInternal(editor);
return new CppHighlightingSupportInternal(baseTextDocument);
}
......@@ -49,7 +49,8 @@ public:
virtual QString displayName() const;
virtual CppCompletionAssistProvider *completionAssistProvider();
virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor);
virtual CppHighlightingSupport *highlightingSupport(
TextEditor::BaseTextDocument *baseTextDocument);
private:
QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider;
......
......@@ -121,7 +121,7 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor
, m_initialized(false)
, m_lastHighlightRevision(0)
, m_lastHighlightOnCompleteSemanticInfo(true)
, m_highlightingSupport(modelManager->highlightingSupport(textEditor))
, m_highlightingSupport(modelManager->highlightingSupport(textEditor->baseTextDocument()))
, m_completionAssistProvider(
modelManager->completionAssistProvider(textEditor->document()->mimeType()))
{
......@@ -595,7 +595,8 @@ void CppEditorSupport::onMimeTypeChanged()
m_highlighter.cancel();
m_highlighter.waitForFinished();
m_highlightingSupport.reset(m_modelManager->highlightingSupport(m_textEditor));
m_highlightingSupport.reset(
m_modelManager->highlightingSupport(m_textEditor->baseTextDocument()));
disconnect(this, SIGNAL(semanticInfoUpdated(CppTools::SemanticInfo)),
this, SLOT(startHighlighting()));
......
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