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

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 @@
#include "cmakeeditor.h"
#include "cmakefilecompletionassist.h"
#include "cmakehighlighter.h"
#include "cmakeeditorfactory.h"
#include "cmakeprojectconstants.h"
......@@ -38,6 +39,7 @@
#include <coreplugin/infobar.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <extensionsystem/pluginmanager.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <texteditor/texteditoractionhandler.h>
......@@ -77,6 +79,11 @@ Core::Id CMakeEditor::id() const
return Core::Id(CMakeProjectManager::Constants::CMAKE_EDITOR_ID);
}
TextEditor::CompletionAssistProvider *CMakeEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<CMakeFileCompletionAssistProvider>();
}
void CMakeEditor::markAsChanged()
{
if (!document()->isModified())
......
......@@ -34,6 +34,7 @@
#include <texteditor/basetextdocument.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/codeassist/completionassistprovider.h>
#include <utils/uncommentselection.h>
......@@ -58,6 +59,7 @@ public:
bool duplicateSupported() const { return true; }
Core::IEditor *duplicate(QWidget *parent);
Core::Id id() const;
TextEditor::CompletionAssistProvider *completionAssistProvider();
private slots:
void markAsChanged();
......
......@@ -39,6 +39,8 @@ class CMakeSettingsPage;
class CMakeFileCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{
Q_OBJECT
public:
CMakeFileCompletionAssistProvider(CMakeSettingsPage *settingsPage);
~CMakeFileCompletionAssistProvider();
......
......@@ -44,6 +44,7 @@
#include <cpptools/cppchecksymbols.h>
#include <cpptools/cppcodeformatter.h>
#include <cpptools/cppcompletionsupport.h>
#include <cpptools/cppcompletionassistprovider.h>
#include <cpptools/cpphighlightingsupport.h>
#include <cpptools/cpplocalsymbols.h>
#include <cpptools/cppqtstyleindenter.h>
......@@ -1879,6 +1880,11 @@ const Utils::CommentDefinition *CPPEditor::commentDefinition() const
return &m_commentDefinition;
}
TextEditor::CompletionAssistProvider *CPPEditor::completionAssistProvider()
{
return CppModelManagerInterface::instance()->cppEditorSupport(this)->completionAssistProvider();
}
void CPPEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
{
TextEditor::BaseTextEditorWidget::setFontSettings(fs);
......
......@@ -82,6 +82,8 @@ public:
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
const Utils::CommentDefinition *commentDefinition() const;
TextEditor::CompletionAssistProvider *completionAssistProvider();
private:
Utils::CommentDefinition m_commentDefinition;
};
......
......@@ -907,6 +907,13 @@ CppCompletionSupport *CppModelManager::completionSupport(Core::IEditor *editor)
return 0;
}
CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEditor *editor) const
{
Q_UNUSED(editor);
return m_completionAssistProvider;
}
void CppModelManager::setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider)
{
ExtensionSystem::PluginManager::removeObject(m_completionAssistProvider);
......
......@@ -105,6 +105,7 @@ public:
void finishedRefreshingSourceFiles(const QStringList &files);
virtual CppCompletionSupport *completionSupport(Core::IEditor *editor) const;
virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const;
virtual void setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider);
virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const;
......
......@@ -242,6 +242,7 @@ public:
const QList<TextEditor::BlockRange> &ifdeffedOutBlocks) = 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 CppTools::CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0;
......
......@@ -27,6 +27,7 @@
**
****************************************************************************/
#include "cppcompletionassistprovider.h"
#include "cpptoolseditorsupport.h"
#include "cppmodelmanager.h"
#include "cpplocalsymbols.h"
......@@ -229,6 +230,11 @@ void CppEditorSupport::recalculateSemanticInfoDetached(bool force)
startHighlighting();
}
CppCompletionAssistProvider *CppEditorSupport::completionAssistProvider() const
{
return m_completionAssistProvider.data();
}
void CppEditorSupport::updateDocument()
{
m_revision = editorRevision();
......
......@@ -50,6 +50,8 @@ class ITextMark;
namespace CppTools {
class CppCompletionAssistProvider;
/**
* \brief The CppEditorSupport class oversees the actions that happen when a C++ text editor updates
* its document.
......@@ -115,6 +117,8 @@ public:
/// \param force do not check if the old semantic info is still valid
void recalculateSemanticInfoDetached(bool force = false);
CppCompletionAssistProvider *completionAssistProvider() const;
signals:
void documentUpdated();
void diagnosticsChanged();
......@@ -189,6 +193,9 @@ private:
unsigned m_lastHighlightRevision;
QFuture<TextEditor::HighlightingResult> m_highlighter;
QScopedPointer<CppTools::CppHighlightingSupport> m_highlightingSupport;
// Completion:
QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider;
};
} // namespace CppTools
......
......@@ -55,6 +55,8 @@ class GLSLCompletionAssistInterface;
class GLSLCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{
Q_OBJECT
public:
virtual bool supportsEditor(const Core::Id &editorId) const;
virtual TextEditor::IAssistProcessor *createProcessor() const;
......
......@@ -207,6 +207,11 @@ bool GLSLEditorEditable::open(QString *errorString, const QString &fileName, con
return b;
}
TextEditor::CompletionAssistProvider *GLSLEditorEditable::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<GLSLCompletionAssistProvider>();
}
QString GLSLTextEditorWidget::wordUnderCursor() const
{
QTextCursor tc = textCursor();
......
......@@ -48,6 +48,7 @@ public:
Core::IEditor *duplicate(QWidget *parent);
Core::Id id() const;
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
TextEditor::CompletionAssistProvider *completionAssistProvider();
};
} // namespace Internal
......
......@@ -77,6 +77,8 @@ public:
class QmlJSCompletionAssistProvider : public TextEditor::CompletionAssistProvider
{
Q_OBJECT
public:
virtual bool supportsEditor(const Core::Id &editorId) const;
virtual TextEditor::IAssistProcessor *createProcessor() const;
......
......@@ -30,6 +30,7 @@
#include "qmljseditoreditable.h"
#include "qmljseditor.h"
#include "qmljseditorconstants.h"
#include "qmljscompletionassist.h"
#include <qmljstools/qmljstoolsconstants.h>
#include <texteditor/texteditorconstants.h>
......@@ -41,6 +42,8 @@
#include <coreplugin/modemanager.h>
#include <coreplugin/coreconstants.h>
#include <extensionsystem/pluginmanager.h>
namespace QmlJSEditor {
QmlJSEditor::QmlJSEditor(QmlJSTextEditorWidget *editor)
......@@ -65,4 +68,9 @@ const Utils::CommentDefinition *QmlJSEditor::commentDefinition() const
return &m_commentDefinition;
}
TextEditor::CompletionAssistProvider *QmlJSEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>();
}
} // namespace QmlJSEditor
......@@ -51,6 +51,8 @@ public:
bool isDesignModePreferred() const;
const Utils::CommentDefinition *commentDefinition() const;
TextEditor::CompletionAssistProvider *completionAssistProvider();
private:
Utils::CommentDefinition m_commentDefinition;
};
......
......@@ -32,6 +32,9 @@
#include "profilehighlighter.h"
#include "qt4projectmanagerconstants.h"
#include "profileeditorfactory.h"
#include "profilecompletionassist.h"
#include <extensionsystem/pluginmanager.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditoractionhandler.h>
......@@ -70,6 +73,11 @@ Core::Id ProFileEditor::id() const
return Core::Id(Constants::PROFILE_EDITOR_ID);
}
TextEditor::CompletionAssistProvider *ProFileEditor::completionAssistProvider()
{
return ExtensionSystem::PluginManager::getObject<ProFileCompletionAssistProvider>();
}
//
// ProFileEditorWidget
//
......
......@@ -55,6 +55,7 @@ public:
bool duplicateSupported() const { return true; }
Core::IEditor *duplicate(QWidget *parent);
Core::Id id() const;
TextEditor::CompletionAssistProvider *completionAssistProvider();
};
class ProFileEditorWidget : public TextEditor::BaseTextEditorWidget
......
......@@ -500,6 +500,8 @@ BaseTextEditor *BaseTextEditorWidget::editor() const
d->m_editor, SIGNAL(contentsChanged()));
connect(this, 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;
}
......@@ -6311,6 +6313,11 @@ const CommentDefinition *BaseTextEditor::commentDefinition() const
return 0;
}
CompletionAssistProvider *BaseTextEditor::completionAssistProvider()
{
return 0;
}
void BaseTextEditor::updateCursorPosition()
{
const QTextCursor cursor = m_editorWidget->textCursor();
......
......@@ -58,6 +58,7 @@ class IAssistMonitorInterface;
class IAssistInterface;
class IAssistProvider;
class ICodeStylePreferences;
class CompletionAssistProvider;
typedef QList<RefactorMarker> RefactorMarkers;
namespace Internal {
......@@ -633,6 +634,8 @@ public:
void select(int toPos);
const Utils::CommentDefinition *commentDefinition() const;
virtual CompletionAssistProvider *completionAssistProvider();
private slots:
void updateCursorPosition();
void openGotoLocator();
......
......@@ -79,6 +79,7 @@ public:
virtual ~CodeAssistantPrivate();
void configure(BaseTextEditor *textEditor);
void reconfigure();
bool isConfigured() const;
void invoke(AssistKind kind, IAssistProvider *provider = 0);
......@@ -116,7 +117,7 @@ private slots:
private:
CodeAssistant *m_q;
BaseTextEditor *m_textEditor;
QList<CompletionAssistProvider *> m_completionProviders;
CompletionAssistProvider *m_completionProvider;
QList<QuickFixAssistProvider *> m_quickFixProviders;
Internal::ProcessorRunner *m_requestRunner;
CompletionAssistProvider *m_requestProvider;
......@@ -169,9 +170,7 @@ void CodeAssistantPrivate::configure(BaseTextEditor *textEditor)
// completion and quick-fix provider (getting rid of the list).
m_textEditor = textEditor;
m_completionProviders =
ExtensionSystem::PluginManager::getObjects<CompletionAssistProvider>();
filterEditorSpecificProviders(&m_completionProviders, m_textEditor->id());
m_completionProvider = textEditor->completionAssistProvider();
m_quickFixProviders =
ExtensionSystem::PluginManager::getObjects<QuickFixAssistProvider>();
filterEditorSpecificProviders(&m_quickFixProviders, m_textEditor->id());
......@@ -179,6 +178,12 @@ void CodeAssistantPrivate::configure(BaseTextEditor *textEditor)
m_textEditor->editorWidget()->installEventFilter(this);
}
void CodeAssistantPrivate::reconfigure()
{
if (isConfigured())
m_completionProvider = m_textEditor->completionAssistProvider();
}
bool CodeAssistantPrivate::isConfigured() const
{
return m_textEditor != 0;
......@@ -229,12 +234,10 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
QTC_ASSERT(!isWaitingForProposal(), return);
if (!provider) {
if (kind == Completion) {
if (!m_completionProviders.isEmpty())
provider = m_completionProviders.at(0);
} else if (!m_quickFixProviders.isEmpty()) {
if (kind == Completion)
provider = m_completionProvider;
else if (!m_quickFixProviders.isEmpty())
provider = m_quickFixProviders.at(0);
}
if (!provider)
return;
......@@ -382,23 +385,22 @@ void CodeAssistantPrivate::invalidateCurrentRequestData()
CompletionAssistProvider *CodeAssistantPrivate::identifyActivationSequence()
{
for (int i = 0; i < m_completionProviders.size(); ++i) {
CompletionAssistProvider *provider = m_completionProviders.at(i);
const int length = provider->activationCharSequenceLength();
if (length == 0)
continue;
QString sequence = m_textEditor->textDocument()->textAt(m_textEditor->position() - length, length);
// In pretty much all cases the sequence will have the appropriate length. Only in the
// case of typing the very first characters in the document for providers that request a
// length greater than 1 (currently only C++, which specifies 3), the sequence needs to
// be preprended so it has the expected length.
const int lengthDiff = length - sequence.length();
for (int j = 0; j < lengthDiff; ++j)
sequence.prepend(m_null);
if (provider->isActivationCharSequence(sequence))
return provider;
}
return 0;
if (!m_completionProvider)
return 0;
const int length = m_completionProvider->activationCharSequenceLength();
if (length == 0)
return 0;
QString sequence = m_textEditor->textDocument()->textAt(m_textEditor->position() - length,
length);
// In pretty much all cases the sequence will have the appropriate length. Only in the
// case of typing the very first characters in the document for providers that request a
// length greater than 1 (currently only C++, which specifies 3), the sequence needs to
// be preprended so it has the expected length.
const int lengthDiff = length - sequence.length();
for (int j = 0; j < lengthDiff; ++j)
sequence.prepend(m_null);
return m_completionProvider->isActivationCharSequence(sequence) ? m_completionProvider : 0;
}
void CodeAssistantPrivate::notifyChange()
......@@ -532,4 +534,9 @@ void CodeAssistant::invoke(AssistKind kind, IAssistProvider *provider)
d->invoke(kind, provider);
}
void CodeAssistant::reconfigure()
{
d->reconfigure();
}
#include "codeassistant.moc"
......@@ -62,6 +62,9 @@ public:
signals:
void finished();
public slots:
void reconfigure();
private:
CodeAssistantPrivate *d;
};
......
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