Commit 898968b1 authored by David Schulz's avatar David Schulz

CodeAssist: Support only one quickfix assistant per editor class.

Currently we are just using the first that is found. Which could lead
to unexpected behavior. Adjust the API to make clear just one assistant
is supported per editor type.

Change-Id: I711e66b4c5c5f347118357a8bafa0ffc6d650f7e
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent 16aeecea
......@@ -26,7 +26,9 @@
#include "cppeditordocument.h"
#include "cppeditorconstants.h"
#include "cppeditorplugin.h"
#include "cpphighlighter.h"
#include "cppquickfixassistant.h"
#include <cpptools/baseeditordocumentparser.h>
#include <cpptools/builtineditordocumentprocessor.h>
......@@ -121,6 +123,11 @@ TextEditor::CompletionAssistProvider *CppEditorDocument::completionAssistProvide
return m_completionAssistProvider;
}
TextEditor::QuickFixAssistProvider *CppEditorDocument::quickFixAssistProvider() const
{
return CppEditorPlugin::instance()->quickFixProvider();
}
void CppEditorDocument::recalculateSemanticInfoDetached()
{
CppTools::BaseEditorDocumentProcessor *p = processor();
......
......@@ -50,6 +50,7 @@ public:
bool isObjCEnabled() const;
TextEditor::CompletionAssistProvider *completionAssistProvider() const override;
TextEditor::QuickFixAssistProvider *quickFixAssistProvider() const override;
void recalculateSemanticInfoDetached();
CppTools::SemanticInfo recalculateSemanticInfo(); // TODO: Remove me
......
......@@ -149,8 +149,7 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
addAutoReleasedObject(new CppIncludeHierarchyFactory);
addAutoReleasedObject(new CppSnippetProvider);
m_quickFixProvider = new CppQuickFixAssistProvider;
addAutoReleasedObject(m_quickFixProvider);
m_quickFixProvider = new CppQuickFixAssistProvider(this);
registerQuickFixes(this);
Context context(Constants::CPPEDITOR_ID);
......
......@@ -71,6 +71,7 @@ private:
class CppQuickFixAssistProvider : public TextEditor::QuickFixAssistProvider
{
public:
CppQuickFixAssistProvider(QObject *parent = 0) : TextEditor::QuickFixAssistProvider(parent) {}
IAssistProvider::RunType runType() const override;
bool supportsEditor(Core::Id editorId) const override;
TextEditor::IAssistProcessor *createProcessor() const override;
......
......@@ -37,6 +37,10 @@ using namespace CppTools;
// ---------------------------
// CppCompletionAssistProvider
// ---------------------------
CppCompletionAssistProvider::CppCompletionAssistProvider(QObject *parent)
: TextEditor::CompletionAssistProvider(parent)
{}
bool CppCompletionAssistProvider::supportsEditor(Core::Id editorId) const
{
return editorId == CppEditor::Constants::CPPEDITOR_ID;
......
......@@ -48,6 +48,7 @@ class CPPTOOLS_EXPORT CppCompletionAssistProvider : public TextEditor::Completio
Q_OBJECT
public:
CppCompletionAssistProvider(QObject *parent = 0);
bool supportsEditor(Core::Id editorId) const override;
int activationCharSequenceLength() const override;
bool isActivationCharSequence(const QString &sequence) const override;
......
......@@ -27,7 +27,9 @@
#include "qmljseditorconstants.h"
#include "qmljseditordocument_p.h"
#include "qmljseditorplugin.h"
#include "qmljshighlighter.h"
#include "qmljsquickfixassist.h"
#include "qmljssemantichighlighter.h"
#include "qmljssemanticinfoupdater.h"
#include "qmloutlinemodel.h"
......@@ -580,6 +582,11 @@ Internal::QmlOutlineModel *QmlJSEditorDocument::outlineModel() const
return d->m_outlineModel;
}
TextEditor::QuickFixAssistProvider *QmlJSEditorDocument::quickFixAssistProvider() const
{
return Internal::QmlJSEditorPlugin::instance()->quickFixAssistProvider();
}
void QmlJSEditorDocument::setDiagnosticRanges(const QVector<QTextLayout::FormatRange> &ranges)
{
d->m_diagnosticRanges = ranges;
......
......@@ -52,6 +52,8 @@ public:
void setDiagnosticRanges(const QVector<QTextLayout::FormatRange> &ranges);
Internal::QmlOutlineModel *outlineModel() const;
TextEditor::QuickFixAssistProvider *quickFixAssistProvider() const override;
signals:
void updateCodeWarnings(QmlJS::Document::Ptr doc);
void semanticInfoUpdated(const QmlJSTools::SemanticInfo &semanticInfo);
......
......@@ -182,8 +182,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
cmd = ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
contextMenu->addAction(cmd);
m_quickFixAssistProvider = new QmlJSQuickFixAssistProvider;
addAutoReleasedObject(m_quickFixAssistProvider);
m_quickFixAssistProvider = new QmlJSQuickFixAssistProvider(this);
errorMessage->clear();
......
......@@ -66,7 +66,8 @@ QmlJSRefactoringFilePtr QmlJSQuickFixAssistInterface::currentFile() const
// ---------------------------
// QmlJSQuickFixAssistProvider
// ---------------------------
QmlJSQuickFixAssistProvider::QmlJSQuickFixAssistProvider()
QmlJSQuickFixAssistProvider::QmlJSQuickFixAssistProvider(QObject *parent)
: TextEditor::QuickFixAssistProvider(parent)
{}
QmlJSQuickFixAssistProvider::~QmlJSQuickFixAssistProvider()
......
......@@ -55,7 +55,7 @@ private:
class QmlJSQuickFixAssistProvider : public TextEditor::QuickFixAssistProvider
{
public:
QmlJSQuickFixAssistProvider();
QmlJSQuickFixAssistProvider(QObject *parent = 0);
~QmlJSQuickFixAssistProvider();
IAssistProvider::RunType runType() const override;
......
......@@ -34,6 +34,7 @@ namespace Internal {
class ClipboardAssistProvider: public IAssistProvider
{
public:
ClipboardAssistProvider(QObject *parent = 0) : IAssistProvider(parent) {}
IAssistProvider::RunType runType() const override;
bool supportsEditor(Core::Id editorId) const override;
IAssistProcessor *createProcessor() const override;
......
......@@ -94,7 +94,6 @@ private:
private:
CodeAssistant *q;
TextEditorWidget *m_editorWidget;
QList<QuickFixAssistProvider *> m_quickFixProviders;
Internal::ProcessorRunner *m_requestRunner;
IAssistProvider *m_requestProvider;
IAssistProcessor *m_asyncProcessor;
......@@ -137,23 +136,7 @@ CodeAssistantPrivate::CodeAssistantPrivate(CodeAssistant *assistant)
void CodeAssistantPrivate::configure(TextEditorWidget *editorWidget)
{
// @TODO: There's a list of providers but currently only the first one is used. Perhaps we
// should implement a truly mechanism to support multiple providers for an editor (either
// merging or not proposals) or just leave it as not extensible and store directly the one
// completion and quick-fix provider (getting rid of the list).
m_editorWidget = editorWidget;
m_quickFixProviders = ExtensionSystem::PluginManager::getObjects<QuickFixAssistProvider>();
Core::Id editorId = m_editorWidget->textDocument()->id();
auto it = m_quickFixProviders.begin();
while (it != m_quickFixProviders.end()) {
if ((*it)->supportsEditor(editorId))
++it;
else
it = m_quickFixProviders.erase(it);
}
m_editorWidget->installEventFilter(this);
}
......@@ -216,8 +199,8 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
if (!provider) {
if (kind == Completion)
provider = m_editorWidget->textDocument()->completionAssistProvider();
else if (!m_quickFixProviders.isEmpty())
provider = m_quickFixProviders.at(0);
else
provider = m_editorWidget->textDocument()->quickFixAssistProvider();
if (!provider)
return;
......
......@@ -29,7 +29,8 @@
using namespace TextEditor;
CompletionAssistProvider::CompletionAssistProvider()
CompletionAssistProvider::CompletionAssistProvider(QObject *parent)
: IAssistProvider(parent)
{}
CompletionAssistProvider::~CompletionAssistProvider()
......
......@@ -35,7 +35,7 @@ class TEXTEDITOR_EXPORT CompletionAssistProvider : public IAssistProvider
Q_OBJECT
public:
CompletionAssistProvider();
CompletionAssistProvider(QObject *parent = 0);
~CompletionAssistProvider();
IAssistProvider::RunType runType() const override;
......
......@@ -39,7 +39,7 @@ class TEXTEDITOR_EXPORT IAssistProvider : public QObject
Q_OBJECT
public:
IAssistProvider() {}
IAssistProvider(QObject *parent = 0) : QObject(parent) {}
enum RunType {
Synchronous,
......
......@@ -27,7 +27,8 @@
using namespace TextEditor;
QuickFixAssistProvider::QuickFixAssistProvider()
QuickFixAssistProvider::QuickFixAssistProvider(QObject *parent)
: IAssistProvider(parent)
{}
QuickFixAssistProvider::~QuickFixAssistProvider()
......
......@@ -38,7 +38,7 @@ class TEXTEDITOR_EXPORT QuickFixAssistProvider : public IAssistProvider
Q_OBJECT
public:
QuickFixAssistProvider();
QuickFixAssistProvider(QObject *parent = 0);
~QuickFixAssistProvider();
virtual QList<QuickFixFactory *> quickFixFactories() const;
......
......@@ -370,6 +370,11 @@ CompletionAssistProvider *TextDocument::completionAssistProvider() const
return d->m_completionAssistProvider;
}
QuickFixAssistProvider *TextDocument::quickFixAssistProvider() const
{
return 0;
}
void TextDocument::applyFontSettings()
{
d->m_fontSettingsNeedsApply = false;
......
......@@ -45,6 +45,7 @@ class CompletionAssistProvider;
class ExtraEncodingSettings;
class FontSettings;
class Indenter;
class QuickFixAssistProvider;
class StorageSettings;
class SyntaxHighlighter;
class TabSettings;
......@@ -130,6 +131,7 @@ public:
void setCompletionAssistProvider(CompletionAssistProvider *provider);
virtual CompletionAssistProvider *completionAssistProvider() const;
virtual QuickFixAssistProvider *quickFixAssistProvider() const;
void setTabSettings(const TextEditor::TabSettings &tabSettings);
void setFontSettings(const TextEditor::FontSettings &fontSettings);
......
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