Commit 7516ef49 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

TextEditor: get CompletionAssistProvider from editor.



And not from the global object pool. This way, the editors that have
different highlighters for various language dialects, or editors that
support multiple languages in a single editor, can decide themselves on
what CompletionAssistProvider to provide.

Change-Id: Ieebc4a8e7b3de6470fdb8103035aa3b8b2ba6598
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 33fd157b
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "cmakeeditor.h" #include "cmakeeditor.h"
#include "cmakefilecompletionassist.h"
#include "cmakehighlighter.h" #include "cmakehighlighter.h"
#include "cmakeeditorfactory.h" #include "cmakeeditorfactory.h"
#include "cmakeprojectconstants.h" #include "cmakeprojectconstants.h"
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
#include <coreplugin/infobar.h> #include <coreplugin/infobar.h>
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actionmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h> #include <projectexplorer/session.h>
#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditoractionhandler.h>
...@@ -77,6 +79,11 @@ Core::Id CMakeEditor::id() const ...@@ -77,6 +79,11 @@ Core::Id CMakeEditor::id() const
return Core::Id(CMakeProjectManager::Constants::CMAKE_EDITOR_ID); return Core::Id(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
} }
TextEditor::CompletionAssistProvider *CMakeEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>();
}
void CMakeEditor::markAsChanged() void CMakeEditor::markAsChanged()
{ {
if (!document()->isModified()) if (!document()->isModified())
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <texteditor/basetextdocument.h> #include <texteditor/basetextdocument.h>
#include <texteditor/basetexteditor.h> #include <texteditor/basetexteditor.h>
#include <texteditor/codeassist/completionassistprovider.h>
#include <utils/uncommentselection.h> #include <utils/uncommentselection.h>
...@@ -58,6 +59,7 @@ public: ...@@ -58,6 +59,7 @@ public:
bool duplicateSupported() const { return true; } bool duplicateSupported() const { return true; }
Core::IEditor *duplicate(QWidget *parent); Core::IEditor *duplicate(QWidget *parent);
Core::Id id() const; Core::Id id() const;
TextEditor::CompletionAssistProvider *completionAssistProvider();
private slots: private slots:
void markAsChanged(); void markAsChanged();
......
...@@ -39,6 +39,8 @@ class CMakeSettingsPage; ...@@ -39,6 +39,8 @@ class CMakeSettingsPage;
class CMakeFileCompletionAssistProvider : public TextEditor::CompletionAssistProvider class CMakeFileCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{ {
Q_OBJECT
public: public:
CMakeFileCompletionAssistProvider(CMakeSettingsPage *settingsPage); CMakeFileCompletionAssistProvider(CMakeSettingsPage *settingsPage);
~CMakeFileCompletionAssistProvider(); ~CMakeFileCompletionAssistProvider();
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <cpptools/cppchecksymbols.h> #include <cpptools/cppchecksymbols.h>
#include <cpptools/cppcodeformatter.h> #include <cpptools/cppcodeformatter.h>
#include <cpptools/cppcompletionsupport.h> #include <cpptools/cppcompletionsupport.h>
#include <cpptools/cppcompletionassistprovider.h>
#include <cpptools/cpphighlightingsupport.h> #include <cpptools/cpphighlightingsupport.h>
#include <cpptools/cpplocalsymbols.h> #include <cpptools/cpplocalsymbols.h>
#include <cpptools/cppqtstyleindenter.h> #include <cpptools/cppqtstyleindenter.h>
...@@ -1879,6 +1880,11 @@ const Utils::CommentDefinition *CPPEditor::commentDefinition() const ...@@ -1879,6 +1880,11 @@ const Utils::CommentDefinition *CPPEditor::commentDefinition() const
return &m_commentDefinition; return &m_commentDefinition;
} }
TextEditor::CompletionAssistProvider *CPPEditor::completionAssistProvider()
{
return CppModelManagerInterface::instance()->cppEditorSupport(this)->completionAssistProvider();
}
void CPPEditorWidget::setFontSettings(const TextEditor::FontSettings &fs) void CPPEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
{ {
TextEditor::BaseTextEditorWidget::setFontSettings(fs); TextEditor::BaseTextEditorWidget::setFontSettings(fs);
......
...@@ -82,6 +82,8 @@ public: ...@@ -82,6 +82,8 @@ public:
bool open(QString *errorString, const QString &fileName, const QString &realFileName); bool open(QString *errorString, const QString &fileName, const QString &realFileName);
const Utils::CommentDefinition *commentDefinition() const; const Utils::CommentDefinition *commentDefinition() const;
TextEditor::CompletionAssistProvider *completionAssistProvider();
private: private:
Utils::CommentDefinition m_commentDefinition; Utils::CommentDefinition m_commentDefinition;
}; };
......
...@@ -907,6 +907,13 @@ CppCompletionSupport *CppModelManager::completionSupport(Core::IEditor *editor) ...@@ -907,6 +907,13 @@ CppCompletionSupport *CppModelManager::completionSupport(Core::IEditor *editor)
return 0; return 0;
} }
CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEditor *editor) const
{
Q_UNUSED(editor);
return m_completionAssistProvider;
}
void CppModelManager::setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider) void CppModelManager::setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider)
{ {
ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider); ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider);
......
...@@ -105,6 +105,7 @@ public: ...@@ -105,6 +105,7 @@ public:
void finishedRefreshingSourceFiles(const QStringList &files); void finishedRefreshingSourceFiles(const QStringList &files);
virtual CppCompletionSupport *completionSupport(Core::IEditor *editor) const; virtual CppCompletionSupport *completionSupport(Core::IEditor *editor) const;
virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const;
virtual void setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider); virtual void setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider);
virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const; virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const;
......
...@@ -242,6 +242,7 @@ public: ...@@ -242,6 +242,7 @@ public:
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0; const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 0;
virtual CppTools::CppCompletionSupport *completionSupport(Core::IEditor *editor) const = 0; virtual CppTools::CppCompletionSupport *completionSupport(Core::IEditor *editor) const = 0;
virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const = 0;
virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0; virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0;
virtual CppTools::CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0; virtual CppTools::CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "cppcompletionassistprovider.h"
#include "cpptoolseditorsupport.h" #include "cpptoolseditorsupport.h"
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include "cpplocalsymbols.h" #include "cpplocalsymbols.h"
...@@ -229,6 +230,11 @@ void CppEditorSupport::recalculateSemanticInfoDetached(bool force) ...@@ -229,6 +230,11 @@ void CppEditorSupport::recalculateSemanticInfoDetached(bool force)
startHighlighting(); startHighlighting();
} }
CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const
{
return m_completionAssistProvider.data();
}
void CppEditorSupport::updateDocument() void CppEditorSupport::updateDocument()
{ {
m_revision = editorRevision(); m_revision = editorRevision();
......
...@@ -50,6 +50,8 @@ class ITextMark; ...@@ -50,6 +50,8 @@ class ITextMark;
namespace CppTools { namespace CppTools {
class CppCompletionAssistProvider;
/** /**
* \brief The CppEditorSupport class oversees the actions that happen when a C++ text editor updates * \brief The CppEditorSupport class oversees the actions that happen when a C++ text editor updates
* its document. * its document.
...@@ -115,6 +117,8 @@ public: ...@@ -115,6 +117,8 @@ public:
/// \param force do not check if the old semantic info is still valid /// \param force do not check if the old semantic info is still valid
void recalculateSemanticInfoDetached(bool force = false); void recalculateSemanticInfoDetached(bool force = false);
CppCompletionAssistProvider *completionAssistProvider() const;
signals: signals:
void documentUpdated(); void documentUpdated();
void diagnosticsChanged(); void diagnosticsChanged();
...@@ -189,6 +193,9 @@ private: ...@@ -189,6 +193,9 @@ private:
unsigned m_lastHighlightRevision; unsigned m_lastHighlightRevision;
QFuture<TextEditor::HighlightingResult> m_highlighter; QFuture<TextEditor::HighlightingResult> m_highlighter;
QScopedPointer<CppTools::CppHighlightingSupport> m_highlightingSupport; QScopedPointer<CppTools::CppHighlightingSupport> m_highlightingSupport;
// Completion:
QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider;
}; };
} // namespace CppTools } // namespace CppTools
......
...@@ -55,6 +55,8 @@ class GLSLCompletionAssistInterface; ...@@ -55,6 +55,8 @@ class GLSLCompletionAssistInterface;
class GLSLCompletionAssistProvider : public TextEditor::CompletionAssistProvider class GLSLCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{ {
Q_OBJECT
public: public:
virtual bool supportsEditor(const Core::Id &editorId) const; virtual bool supportsEditor(const Core::Id &editorId) const;
virtual TextEditor::IAssistProcessor *createProcessor() const; virtual TextEditor::IAssistProcessor *createProcessor() const;
......
...@@ -207,6 +207,11 @@ bool GLSLEditorEditable::open(QString *errorString, const QString &fileName, con ...@@ -207,6 +207,11 @@ bool GLSLEditorEditable::open(QString *errorString, const QString &fileName, con
return b; return b;
} }
TextEditor::CompletionAssistProvider *GLSLEditorEditable::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<GLSLCompletionAssistProvider>();
}
QString GLSLTextEditorWidget::wordUnderCursor() const QString GLSLTextEditorWidget::wordUnderCursor() const
{ {
QTextCursor tc = textCursor(); QTextCursor tc = textCursor();
......
...@@ -48,6 +48,7 @@ public: ...@@ -48,6 +48,7 @@ public:
Core::IEditor *duplicate(QWidget *parent); Core::IEditor *duplicate(QWidget *parent);
Core::Id id() const; Core::Id id() const;
bool open(QString *errorString, const QString &fileName, const QString &realFileName); bool open(QString *errorString, const QString &fileName, const QString &realFileName);
TextEditor::CompletionAssistProvider *completionAssistProvider();
}; };
} // namespace Internal } // namespace Internal
......
...@@ -77,6 +77,8 @@ public: ...@@ -77,6 +77,8 @@ public:
class QmlJSCompletionAssistProvider : public TextEditor::CompletionAssistProvider class QmlJSCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{ {
Q_OBJECT
public: public:
virtual bool supportsEditor(const Core::Id &editorId) const; virtual bool supportsEditor(const Core::Id &editorId) const;
virtual TextEditor::IAssistProcessor *createProcessor() const; virtual TextEditor::IAssistProcessor *createProcessor() const;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "qmljseditoreditable.h" #include "qmljseditoreditable.h"
#include "qmljseditor.h" #include "qmljseditor.h"
#include "qmljseditorconstants.h" #include "qmljseditorconstants.h"
#include "qmljscompletionassist.h"
#include <qmljstools/qmljstoolsconstants.h> #include <qmljstools/qmljstoolsconstants.h>
#include <texteditor/texteditorconstants.h> #include <texteditor/texteditorconstants.h>
...@@ -41,6 +42,8 @@ ...@@ -41,6 +42,8 @@
#include <coreplugin/modemanager.h> #include <coreplugin/modemanager.h>
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <extensionsystem/pluginmanager.h>
namespace QmlJSEditor { namespace QmlJSEditor {
QmlJSEditor::QmlJSEditor(QmlJSTextEditorWidget *editor) QmlJSEditor::QmlJSEditor(QmlJSTextEditorWidget *editor)
...@@ -65,4 +68,9 @@ const Utils::CommentDefinition *QmlJSEditor::commentDefinition() const ...@@ -65,4 +68,9 @@ const Utils::CommentDefinition *QmlJSEditor::commentDefinition() const
return &m_commentDefinition; return &m_commentDefinition;
} }
TextEditor::CompletionAssistProvider *QmlJSEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>();
}
} // namespace QmlJSEditor } // namespace QmlJSEditor
...@@ -51,6 +51,8 @@ public: ...@@ -51,6 +51,8 @@ public:
bool isDesignModePreferred() const; bool isDesignModePreferred() const;
const Utils::CommentDefinition *commentDefinition() const; const Utils::CommentDefinition *commentDefinition() const;
TextEditor::CompletionAssistProvider *completionAssistProvider();
private: private:
Utils::CommentDefinition m_commentDefinition; Utils::CommentDefinition m_commentDefinition;
}; };
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
#include "profilehighlighter.h" #include "profilehighlighter.h"
#include "qt4projectmanagerconstants.h" #include "qt4projectmanagerconstants.h"
#include "profileeditorfactory.h" #include "profileeditorfactory.h"
#include "profilecompletionassist.h"
#include <extensionsystem/pluginmanager.h>
#include <texteditor/fontsettings.h> #include <texteditor/fontsettings.h>
#include <texteditor/texteditoractionhandler.h> #include <texteditor/texteditoractionhandler.h>
...@@ -70,6 +73,11 @@ Core::Id ProFileEditor::id() const ...@@ -70,6 +73,11 @@ Core::Id ProFileEditor::id() const
return Core::Id(Constants::PROFILE_EDITOR_ID); return Core::Id(Constants::PROFILE_EDITOR_ID);
} }
TextEditor::CompletionAssistProvider *ProFileEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>();
}
// //
// ProFileEditorWidget // ProFileEditorWidget
// //
......
...@@ -55,6 +55,7 @@ public: ...@@ -55,6 +55,7 @@ public:
bool duplicateSupported() const { return true; } bool duplicateSupported() const { return true; }
Core::IEditor *duplicate(QWidget *parent); Core::IEditor *duplicate(QWidget *parent);
Core::Id id() const; Core::Id id() const;
TextEditor::CompletionAssistProvider *completionAssistProvider();
}; };
class ProFileEditorWidget : public TextEditor::BaseTextEditorWidget class ProFileEditorWidget : public TextEditor::BaseTextEditorWidget
......
...@@ -500,6 +500,8 @@ BaseTextEditor *BaseTextEditorWidget::editor() const ...@@ -500,6 +500,8 @@ BaseTextEditor *BaseTextEditorWidget::editor() const
d->m_editor, SIGNAL(contentsChanged())); d->m_editor, SIGNAL(contentsChanged()));
connect(this, SIGNAL(changed()), connect(this, SIGNAL(changed()),
d->m_editor->document(), SIGNAL(changed())); d->m_editor->document(), SIGNAL(changed()));
connect(qobject_cast<BaseTextDocument *>(d->m_editor->document()),SIGNAL(mimeTypeChanged()),
d->m_codeAssistant.data(), SLOT(reconfigure()));
} }
return d->m_editor; return d->m_editor;
} }
...@@ -6311,6 +6313,11 @@ const CommentDefinition *BaseTextEditor::commentDefinition() const ...@@ -6311,6 +6313,11 @@ const CommentDefinition *BaseTextEditor::commentDefinition() const
return 0; return 0;
} }
CompletionAssistProvider *BaseTextEditor::completionAssistProvider()
{
return 0;
}
void BaseTextEditor::updateCursorPosition() void BaseTextEditor::updateCursorPosition()
{ {
const QTextCursor cursor = m_editorWidget->textCursor(); const QTextCursor cursor = m_editorWidget->textCursor();
......
...@@ -58,6 +58,7 @@ class IAssistMonitorInterface; ...@@ -58,6 +58,7 @@ class IAssistMonitorInterface;
class IAssistInterface; class IAssistInterface;
class IAssistProvider; class IAssistProvider;
class ICodeStylePreferences; class ICodeStylePreferences;
class CompletionAssistProvider;
typedef QList<RefactorMarker> RefactorMarkers; typedef QList<RefactorMarker> RefactorMarkers;
namespace Internal { namespace Internal {
...@@ -633,6 +634,8 @@ public: ...@@ -633,6 +634,8 @@ public:
void select(int toPos); void select(int toPos);
const Utils::CommentDefinition *commentDefinition() const; const Utils::CommentDefinition *commentDefinition() const;
virtual CompletionAssistProvider *completionAssistProvider();
private slots: private slots:
void updateCursorPosition(); void updateCursorPosition();
void openGotoLocator(); void openGotoLocator();
......
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