forked from qt-creator/qt-creator
Editor: unify assist processor handling
Define the run type of the processor by its implementation instead of a enum value of the provider. The execution of a processor inside the assist now follows a unified procedure. Change-Id: Ibe9fab324c6072e77702c2663946d7a9f562a085 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -46,7 +46,7 @@ public:
|
||||
unsigned completionOperator, CustomAssistMode mode);
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
||||
IAssistProposal *perform(AssistInterface *interface) override;
|
||||
|
||||
AssistProposalItemInterface *createItem(const QString &text, const QIcon &icon) const;
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
~ClangdCompletionAssistProcessor();
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
||||
IAssistProposal *perform(AssistInterface *interface) override;
|
||||
QList<AssistProposalItemInterface *> generateCompletionItems(
|
||||
const QList<LanguageServerProtocol::CompletionItem> &items) const override;
|
||||
|
||||
@@ -99,7 +99,7 @@ public:
|
||||
ClangdFunctionHintProcessor(ClangdClient *client);
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
||||
IAssistProposal *perform(AssistInterface *interface) override;
|
||||
|
||||
ClangdClient * const m_client;
|
||||
};
|
||||
@@ -152,7 +152,7 @@ IAssistProcessor *ClangdCompletionAssistProvider::createProcessor(
|
||||
if (contextAnalyzer.completionAction()
|
||||
!= ClangCompletionContextAnalyzer::CompleteIncludePath) {
|
||||
class NoOpProcessor : public IAssistProcessor {
|
||||
IAssistProposal *perform(const AssistInterface *) override { return nullptr; }
|
||||
IAssistProposal *perform(AssistInterface *) override { return nullptr; }
|
||||
};
|
||||
return new NoOpProcessor;
|
||||
}
|
||||
@@ -402,7 +402,7 @@ CustomAssistProcessor::CustomAssistProcessor(ClangdClient *client, int position,
|
||||
, m_mode(mode)
|
||||
{}
|
||||
|
||||
IAssistProposal *CustomAssistProcessor::perform(const AssistInterface *interface)
|
||||
IAssistProposal *CustomAssistProcessor::perform(AssistInterface *interface)
|
||||
{
|
||||
QList<AssistProposalItemInterface *> completions;
|
||||
switch (m_mode) {
|
||||
@@ -568,7 +568,7 @@ ClangdCompletionAssistProcessor::~ClangdCompletionAssistProcessor()
|
||||
<< "ClangdCompletionAssistProcessor took: " << m_timer.elapsed() << " ms";
|
||||
}
|
||||
|
||||
IAssistProposal *ClangdCompletionAssistProcessor::perform(const AssistInterface *interface)
|
||||
IAssistProposal *ClangdCompletionAssistProcessor::perform(AssistInterface *interface)
|
||||
{
|
||||
if (m_client->testingEnabled()) {
|
||||
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal) {
|
||||
@@ -614,7 +614,7 @@ ClangdFunctionHintProcessor::ClangdFunctionHintProcessor(ClangdClient *client)
|
||||
, m_client(client)
|
||||
{}
|
||||
|
||||
IAssistProposal *ClangdFunctionHintProcessor::perform(const AssistInterface *interface)
|
||||
IAssistProposal *ClangdFunctionHintProcessor::perform(AssistInterface *interface)
|
||||
{
|
||||
if (m_client->testingEnabled()) {
|
||||
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal) {
|
||||
|
||||
@@ -42,18 +42,12 @@ public:
|
||||
void resetData(bool resetFollowSymbolData);
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(const AssistInterface *interface) override
|
||||
IAssistProposal *perform(AssistInterface *interface) override
|
||||
{
|
||||
delete interface;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IAssistProposal *immediateProposal(const AssistInterface *) override
|
||||
{
|
||||
return createProposal(false);
|
||||
}
|
||||
|
||||
IAssistProposal *immediateProposalImpl() const;
|
||||
IAssistProposal *createProposal(bool final) const;
|
||||
VirtualFunctionProposalItem *createEntry(const QString &name, const Link &link) const;
|
||||
|
||||
@@ -67,7 +61,6 @@ public:
|
||||
: m_followSymbol(followSymbol) {}
|
||||
|
||||
private:
|
||||
RunType runType() const override { return Asynchronous; }
|
||||
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
||||
|
||||
const QPointer<ClangdFollowSymbol> m_followSymbol;
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
IAssistProposal *perform(const AssistInterface *interface) override
|
||||
IAssistProposal *perform(AssistInterface *interface) override
|
||||
{
|
||||
m_interface = interface;
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@ using namespace ProjectExplorer;
|
||||
|
||||
namespace CMakeProjectManager::Internal {
|
||||
|
||||
class CMakeFileCompletionAssist : public TextEditor::KeywordsCompletionAssistProcessor
|
||||
class CMakeFileCompletionAssist : public KeywordsCompletionAssistProcessor
|
||||
{
|
||||
public:
|
||||
CMakeFileCompletionAssist();
|
||||
|
||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) final;
|
||||
IAssistProposal *performAsync(AssistInterface *interface) final;
|
||||
};
|
||||
|
||||
CMakeFileCompletionAssist::CMakeFileCompletionAssist() :
|
||||
@@ -34,7 +34,7 @@ CMakeFileCompletionAssist::CMakeFileCompletionAssist() :
|
||||
setDynamicCompletionFunction(&TextEditor::pathComplete);
|
||||
}
|
||||
|
||||
IAssistProposal *CMakeFileCompletionAssist::perform(const AssistInterface *interface)
|
||||
IAssistProposal *CMakeFileCompletionAssist::performAsync(AssistInterface *interface)
|
||||
{
|
||||
Keywords kw;
|
||||
const Utils::FilePath &filePath = interface->filePath();
|
||||
@@ -48,7 +48,7 @@ IAssistProposal *CMakeFileCompletionAssist::perform(const AssistInterface *inter
|
||||
}
|
||||
|
||||
setKeywords(kw);
|
||||
return KeywordsCompletionAssistProcessor::perform(interface);
|
||||
return KeywordsCompletionAssistProcessor::performAsync(interface);
|
||||
}
|
||||
|
||||
IAssistProcessor *CMakeFileCompletionAssistProvider::createProcessor(const AssistInterface *) const
|
||||
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
ai->recreateTextDocument();
|
||||
InternalCppCompletionAssistProcessor processor;
|
||||
|
||||
const QScopedPointer<IAssistProposal> proposal(processor.perform(ai));
|
||||
const QScopedPointer<IAssistProposal> proposal(processor.performAsync(ai));
|
||||
if (!proposal)
|
||||
return completions;
|
||||
ProposalModelPtr model = proposal->model();
|
||||
|
||||
@@ -794,7 +794,7 @@ InternalCppCompletionAssistProcessor::InternalCppCompletionAssistProcessor()
|
||||
|
||||
InternalCppCompletionAssistProcessor::~InternalCppCompletionAssistProcessor() = default;
|
||||
|
||||
IAssistProposal * InternalCppCompletionAssistProcessor::perform(const AssistInterface *interface)
|
||||
IAssistProposal * InternalCppCompletionAssistProcessor::performAsync(AssistInterface *interface)
|
||||
{
|
||||
m_interface.reset(static_cast<const CppCompletionAssistInterface *>(interface));
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
InternalCppCompletionAssistProcessor();
|
||||
~InternalCppCompletionAssistProcessor() override;
|
||||
|
||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
||||
TextEditor::IAssistProposal *performAsync(TextEditor::AssistInterface *interface) override;
|
||||
|
||||
private:
|
||||
TextEditor::IAssistProposal *createContentProposal();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "cppeditor_global.h"
|
||||
|
||||
#include <texteditor/codeassist/iassistprocessor.h>
|
||||
#include <texteditor/codeassist/asyncprocessor.h>
|
||||
#include <texteditor/snippets/snippetassistcollector.h>
|
||||
|
||||
#include <functional>
|
||||
@@ -18,7 +18,7 @@ namespace CPlusPlus { struct LanguageFeatures; }
|
||||
|
||||
namespace CppEditor {
|
||||
|
||||
class CPPEDITOR_EXPORT CppCompletionAssistProcessor : public TextEditor::IAssistProcessor
|
||||
class CPPEDITOR_EXPORT CppCompletionAssistProcessor : public TextEditor::AsyncProcessor
|
||||
{
|
||||
public:
|
||||
explicit CppCompletionAssistProcessor(int snippetItemOrder = 0);
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Internal {
|
||||
// -------------------------
|
||||
class CppQuickFixAssistProcessor : public IAssistProcessor
|
||||
{
|
||||
IAssistProposal *perform(const AssistInterface *interface) override
|
||||
IAssistProposal *perform(AssistInterface *interface) override
|
||||
{
|
||||
QSharedPointer<const AssistInterface> dummy(interface); // FIXME: Surely this cannot be our way of doing memory management???
|
||||
return GenericProposal::createProposal(interface, quickFixOperations(interface));
|
||||
@@ -39,10 +39,6 @@ class CppQuickFixAssistProcessor : public IAssistProcessor
|
||||
// -------------------------
|
||||
// CppQuickFixAssistProvider
|
||||
// -------------------------
|
||||
IAssistProvider::RunType CppQuickFixAssistProvider::runType() const
|
||||
{
|
||||
return Synchronous;
|
||||
}
|
||||
|
||||
IAssistProcessor *CppQuickFixAssistProvider::createProcessor(const AssistInterface *) const
|
||||
{
|
||||
|
||||
@@ -50,7 +50,6 @@ class CppQuickFixAssistProvider : public TextEditor::IAssistProvider
|
||||
{
|
||||
public:
|
||||
CppQuickFixAssistProvider() = default;
|
||||
IAssistProvider::RunType runType() const override;
|
||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
|
||||
#include <texteditor/codeassist/assistinterface.h>
|
||||
#include <texteditor/codeassist/asyncprocessor.h>
|
||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||
#include <texteditor/codeassist/genericproposalwidget.h>
|
||||
#include <texteditor/codeassist/assistinterface.h>
|
||||
#include <texteditor/codeassist/iassistprocessor.h>
|
||||
#include <texteditor/codeassist/iassistproposal.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
@@ -79,14 +80,14 @@ private:
|
||||
|
||||
|
||||
|
||||
class VirtualFunctionAssistProcessor : public IAssistProcessor
|
||||
class VirtualFunctionAssistProcessor : public AsyncProcessor
|
||||
{
|
||||
public:
|
||||
VirtualFunctionAssistProcessor(const VirtualFunctionAssistProvider::Parameters ¶ms)
|
||||
: m_params(params)
|
||||
{}
|
||||
|
||||
IAssistProposal *immediateProposal(const AssistInterface *) override
|
||||
IAssistProposal *immediateProposal(AssistInterface *) override
|
||||
{
|
||||
QTC_ASSERT(m_params.function, return nullptr);
|
||||
|
||||
@@ -101,7 +102,7 @@ public:
|
||||
return new VirtualFunctionProposal(m_params.cursorPosition, items, m_params.openInNextSplit);
|
||||
}
|
||||
|
||||
IAssistProposal *perform(const AssistInterface *assistInterface) override
|
||||
IAssistProposal *performAsync(AssistInterface *assistInterface) override
|
||||
{
|
||||
delete assistInterface;
|
||||
|
||||
@@ -162,11 +163,6 @@ bool VirtualFunctionAssistProvider::configure(const Parameters ¶meters)
|
||||
return true;
|
||||
}
|
||||
|
||||
IAssistProvider::RunType VirtualFunctionAssistProvider::runType() const
|
||||
{
|
||||
return AsynchronousWithThread;
|
||||
}
|
||||
|
||||
IAssistProcessor *VirtualFunctionAssistProvider::createProcessor(const AssistInterface *) const
|
||||
{
|
||||
return new VirtualFunctionAssistProcessor(m_params);
|
||||
|
||||
@@ -54,7 +54,6 @@ public:
|
||||
Parameters params() const { return m_params; }
|
||||
void clearParams() { m_params = Parameters(); }
|
||||
|
||||
IAssistProvider::RunType runType() const override;
|
||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
|
||||
#include <texteditor/codeassist/asyncprocessor.h>
|
||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||
#include <texteditor/codeassist/iassistprocessor.h>
|
||||
#include <texteditor/codeassist/iassistproposal.h>
|
||||
@@ -120,11 +121,12 @@ public:
|
||||
|
||||
AssistInterface *assistInterface
|
||||
= m_editorWidget->createAssistInterface(FollowSymbol, ExplicitlyInvoked);
|
||||
const QScopedPointer<IAssistProcessor> processor(createProcessor(assistInterface));
|
||||
|
||||
const QScopedPointer<AsyncProcessor> processor(
|
||||
dynamic_cast<AsyncProcessor *>(createProcessor(assistInterface)));
|
||||
const QScopedPointer<IAssistProposal> immediateProposal(
|
||||
processor->immediateProposal(assistInterface));
|
||||
const QScopedPointer<IAssistProposal> finalProposal(processor->perform(assistInterface));
|
||||
const QScopedPointer<IAssistProposal> finalProposal(
|
||||
processor->performAsync(assistInterface));
|
||||
|
||||
VirtualFunctionAssistProvider::clearParams();
|
||||
|
||||
|
||||
@@ -27,22 +27,23 @@
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
|
||||
#include <texteditor/codeassist/assistinterface.h>
|
||||
#include <texteditor/codeassist/assistproposalitem.h>
|
||||
#include <texteditor/codeassist/asyncprocessor.h>
|
||||
#include <texteditor/codeassist/completionassistprovider.h>
|
||||
#include <texteditor/codeassist/genericproposal.h>
|
||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||
#include <texteditor/codeassist/iassistprocessor.h>
|
||||
#include <texteditor/displaysettings.h>
|
||||
#include <texteditor/icodestylepreferences.h>
|
||||
#include <texteditor/indenter.h>
|
||||
#include <texteditor/tabsettings.h>
|
||||
#include <texteditor/textdocumentlayout.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <texteditor/textmark.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/typingsettings.h>
|
||||
#include <texteditor/tabsettings.h>
|
||||
#include <texteditor/icodestylepreferences.h>
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
#include <texteditor/indenter.h>
|
||||
#include <texteditor/codeassist/assistproposalitem.h>
|
||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||
#include <texteditor/codeassist/completionassistprovider.h>
|
||||
#include <texteditor/codeassist/iassistprocessor.h>
|
||||
#include <texteditor/codeassist/assistinterface.h>
|
||||
#include <texteditor/codeassist/genericproposal.h>
|
||||
#include <texteditor/textmark.h>
|
||||
#include <texteditor/typingsettings.h>
|
||||
|
||||
#include <utils/aspects.h>
|
||||
#include <utils/fancylineedit.h>
|
||||
@@ -1037,14 +1038,14 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class FakeVimCompletionAssistProcessor : public IAssistProcessor
|
||||
class FakeVimCompletionAssistProcessor : public AsyncProcessor
|
||||
{
|
||||
public:
|
||||
FakeVimCompletionAssistProcessor(const IAssistProvider *provider)
|
||||
: m_provider(static_cast<const FakeVimCompletionAssistProvider *>(provider))
|
||||
{}
|
||||
|
||||
IAssistProposal *perform(const AssistInterface *interface) override
|
||||
IAssistProposal *performAsync(AssistInterface *interface) override
|
||||
{
|
||||
const QString &needle = m_provider->needle();
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ static AssistProposalItem *createCompletionItem(const QString &text, const QIcon
|
||||
return item;
|
||||
}
|
||||
|
||||
IAssistProposal *GlslCompletionAssistProcessor::perform(const AssistInterface *interface)
|
||||
IAssistProposal *GlslCompletionAssistProcessor::performAsync(AssistInterface *interface)
|
||||
{
|
||||
m_interface.reset(static_cast<const GlslCompletionAssistInterface *>(interface));
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
#include "glsleditor.h"
|
||||
|
||||
#include <texteditor/codeassist/assistinterface.h>
|
||||
#include <texteditor/codeassist/asyncprocessor.h>
|
||||
#include <texteditor/codeassist/completionassistprovider.h>
|
||||
#include <texteditor/codeassist/iassistprocessor.h>
|
||||
#include <texteditor/codeassist/assistinterface.h>
|
||||
#include <texteditor/codeassist/ifunctionhintproposalmodel.h>
|
||||
|
||||
|
||||
#include <QScopedPointer>
|
||||
#include <QSharedPointer>
|
||||
|
||||
@@ -67,12 +67,12 @@ public:
|
||||
bool isActivationCharSequence(const QString &sequence) const override;
|
||||
};
|
||||
|
||||
class GlslCompletionAssistProcessor : public TextEditor::IAssistProcessor
|
||||
class GlslCompletionAssistProcessor : public TextEditor::AsyncProcessor
|
||||
{
|
||||
public:
|
||||
~GlslCompletionAssistProcessor() override;
|
||||
|
||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
||||
TextEditor::IAssistProposal *performAsync(TextEditor::AssistInterface *interface) override;
|
||||
|
||||
private:
|
||||
TextEditor::IAssistProposal *createHintProposal(const QVector<GLSL::Function *> &symbols);
|
||||
|
||||
@@ -314,7 +314,7 @@ static QString assistReasonString(AssistReason reason)
|
||||
return QString("unknown reason");
|
||||
}
|
||||
|
||||
IAssistProposal *LanguageClientCompletionAssistProcessor::perform(const AssistInterface *interface)
|
||||
IAssistProposal *LanguageClientCompletionAssistProcessor::perform(AssistInterface *interface)
|
||||
{
|
||||
m_assistInterface.reset(interface);
|
||||
QTC_ASSERT(m_client, return nullptr);
|
||||
@@ -454,11 +454,6 @@ IAssistProcessor *LanguageClientCompletionAssistProvider::createProcessor(
|
||||
m_snippetsGroup);
|
||||
}
|
||||
|
||||
IAssistProvider::RunType LanguageClientCompletionAssistProvider::runType() const
|
||||
{
|
||||
return IAssistProvider::Asynchronous;
|
||||
}
|
||||
|
||||
int LanguageClientCompletionAssistProvider::activationCharSequenceLength() const
|
||||
{
|
||||
return m_activationCharSequenceLength;
|
||||
|
||||
@@ -34,7 +34,6 @@ public:
|
||||
LanguageClientCompletionAssistProvider(Client *client);
|
||||
|
||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||
RunType runType() const override;
|
||||
|
||||
int activationCharSequenceLength() const override;
|
||||
bool isActivationCharSequence(const QString &sequence) const override;
|
||||
@@ -60,7 +59,7 @@ class LANGUAGECLIENT_EXPORT LanguageClientCompletionAssistProcessor
|
||||
public:
|
||||
LanguageClientCompletionAssistProcessor(Client *client, const QString &snippetsGroup);
|
||||
~LanguageClientCompletionAssistProcessor() override;
|
||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
||||
TextEditor::IAssistProposal *perform(TextEditor::AssistInterface *interface) override;
|
||||
bool running() override;
|
||||
bool needsRestart() const override { return true; }
|
||||
void cancel() override;
|
||||
|
||||
@@ -66,7 +66,7 @@ FunctionHintProcessor::FunctionHintProcessor(Client *client)
|
||||
: m_client(client)
|
||||
{}
|
||||
|
||||
IAssistProposal *FunctionHintProcessor::perform(const AssistInterface *interface)
|
||||
IAssistProposal *FunctionHintProcessor::perform(AssistInterface *interface)
|
||||
{
|
||||
const QScopedPointer<const AssistInterface> deleter(interface);
|
||||
QTC_ASSERT(m_client, return nullptr);
|
||||
@@ -124,11 +124,6 @@ TextEditor::IAssistProcessor *FunctionHintAssistProvider::createProcessor(
|
||||
return new FunctionHintProcessor(m_client);
|
||||
}
|
||||
|
||||
IAssistProvider::RunType FunctionHintAssistProvider::runType() const
|
||||
{
|
||||
return Asynchronous;
|
||||
}
|
||||
|
||||
int FunctionHintAssistProvider::activationCharSequenceLength() const
|
||||
{
|
||||
return m_activationCharSequenceLength;
|
||||
|
||||
@@ -27,7 +27,6 @@ public:
|
||||
explicit FunctionHintAssistProvider(Client *client);
|
||||
|
||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||
RunType runType() const override;
|
||||
|
||||
int activationCharSequenceLength() const override;
|
||||
bool isActivationCharSequence(const QString &sequence) const override;
|
||||
@@ -45,7 +44,7 @@ class LANGUAGECLIENT_EXPORT FunctionHintProcessor : public TextEditor::IAssistPr
|
||||
{
|
||||
public:
|
||||
explicit FunctionHintProcessor(Client *client);
|
||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
||||
TextEditor::IAssistProposal *perform(TextEditor::AssistInterface *interface) override;
|
||||
bool running() override { return m_currentRequest.has_value(); }
|
||||
bool needsRestart() const override { return true; }
|
||||
void cancel() override;
|
||||
|
||||
@@ -45,7 +45,7 @@ void CommandQuickFixOperation::perform()
|
||||
m_client->executeCommand(m_command);
|
||||
}
|
||||
|
||||
IAssistProposal *LanguageClientQuickFixAssistProcessor::perform(const AssistInterface *interface)
|
||||
IAssistProposal *LanguageClientQuickFixAssistProcessor::perform(AssistInterface *interface)
|
||||
{
|
||||
m_assistInterface = QSharedPointer<const AssistInterface>(interface);
|
||||
|
||||
@@ -122,11 +122,6 @@ LanguageClientQuickFixProvider::LanguageClientQuickFixProvider(Client *client)
|
||||
QTC_CHECK(client);
|
||||
}
|
||||
|
||||
IAssistProvider::RunType LanguageClientQuickFixProvider::runType() const
|
||||
{
|
||||
return Asynchronous;
|
||||
}
|
||||
|
||||
IAssistProcessor *LanguageClientQuickFixProvider::createProcessor(const AssistInterface *) const
|
||||
{
|
||||
return new LanguageClientQuickFixAssistProcessor(m_client);
|
||||
|
||||
@@ -48,7 +48,6 @@ class LANGUAGECLIENT_EXPORT LanguageClientQuickFixProvider : public TextEditor::
|
||||
{
|
||||
public:
|
||||
explicit LanguageClientQuickFixProvider(Client *client);
|
||||
IAssistProvider::RunType runType() const override;
|
||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||
|
||||
protected:
|
||||
@@ -64,7 +63,7 @@ class LANGUAGECLIENT_EXPORT LanguageClientQuickFixAssistProcessor
|
||||
public:
|
||||
explicit LanguageClientQuickFixAssistProcessor(Client *client) : m_client(client) {}
|
||||
bool running() override { return m_currentRequest.has_value(); }
|
||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
||||
TextEditor::IAssistProposal *perform(TextEditor::AssistInterface *interface) override;
|
||||
void cancel() override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -43,7 +43,7 @@ class NimCompletionAssistProcessor : public QObject, public TextEditor::IAssistP
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) final
|
||||
TextEditor::IAssistProposal *perform(TextEditor::AssistInterface *interface) final
|
||||
{
|
||||
QTC_ASSERT(this->thread() == qApp->thread(), return nullptr);
|
||||
|
||||
@@ -250,11 +250,6 @@ bool NimCompletionAssistProvider::isActivationCharSequence(const QString &sequen
|
||||
return !sequence.isEmpty() && isActivationChar(sequence.at(0));
|
||||
}
|
||||
|
||||
IAssistProvider::RunType NimCompletionAssistProvider::runType() const
|
||||
{
|
||||
return RunType::Asynchronous;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "nimcompletionassistprovider.moc"
|
||||
|
||||
@@ -15,7 +15,6 @@ public:
|
||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const final;
|
||||
int activationCharSequenceLength() const final;
|
||||
bool isActivationCharSequence(const QString &sequence) const final;
|
||||
RunType runType() const final;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -525,7 +525,7 @@ IAssistProposal *QmlJSCompletionAssistProcessor::createHintProposal(
|
||||
return new FunctionHintProposal(m_startPosition, model);
|
||||
}
|
||||
|
||||
IAssistProposal *QmlJSCompletionAssistProcessor::perform(const AssistInterface *assistInterface)
|
||||
IAssistProposal *QmlJSCompletionAssistProcessor::performAsync(AssistInterface *assistInterface)
|
||||
{
|
||||
m_interface.reset(static_cast<const QmlJSCompletionAssistInterface *>(assistInterface));
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
#include "qmljseditor_global.h"
|
||||
|
||||
#include <qmljstools/qmljssemanticinfo.h>
|
||||
#include <texteditor/codeassist/assistinterface.h>
|
||||
#include <texteditor/codeassist/assistproposalitem.h>
|
||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||
#include <texteditor/codeassist/asyncprocessor.h>
|
||||
#include <texteditor/codeassist/completionassistprovider.h>
|
||||
#include <texteditor/codeassist/genericproposalmodel.h>
|
||||
#include <texteditor/codeassist/iassistprocessor.h>
|
||||
#include <texteditor/snippets/snippetassistcollector.h>
|
||||
#include <texteditor/codeassist/assistinterface.h>
|
||||
|
||||
|
||||
#include <QStringList>
|
||||
#include <QScopedPointer>
|
||||
@@ -51,13 +51,13 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class QmlJSCompletionAssistProcessor : public TextEditor::IAssistProcessor
|
||||
class QmlJSCompletionAssistProcessor : public TextEditor::AsyncProcessor
|
||||
{
|
||||
public:
|
||||
QmlJSCompletionAssistProcessor();
|
||||
~QmlJSCompletionAssistProcessor() override;
|
||||
|
||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
||||
TextEditor::IAssistProposal *performAsync(TextEditor::AssistInterface *interface) override;
|
||||
|
||||
private:
|
||||
TextEditor::IAssistProposal *createContentProposal() const;
|
||||
|
||||
@@ -48,7 +48,7 @@ QmlJSRefactoringFilePtr QmlJSQuickFixAssistInterface::currentFile() const
|
||||
// ---------------------------
|
||||
class QmlJSQuickFixAssistProcessor : public IAssistProcessor
|
||||
{
|
||||
IAssistProposal *perform(const AssistInterface *interface) override
|
||||
IAssistProposal *perform(AssistInterface *interface) override
|
||||
{
|
||||
return GenericProposal::createProposal(interface, findQmlJSQuickFixes(interface));
|
||||
}
|
||||
@@ -58,11 +58,6 @@ class QmlJSQuickFixAssistProcessor : public IAssistProcessor
|
||||
// QmlJSQuickFixAssistProvider
|
||||
// ---------------------------
|
||||
|
||||
IAssistProvider::RunType QmlJSQuickFixAssistProvider::runType() const
|
||||
{
|
||||
return Synchronous;
|
||||
}
|
||||
|
||||
IAssistProcessor *QmlJSQuickFixAssistProvider::createProcessor(const AssistInterface *) const
|
||||
{
|
||||
return new QmlJSQuickFixAssistProcessor;
|
||||
|
||||
@@ -37,7 +37,6 @@ public:
|
||||
QmlJSQuickFixAssistProvider() = default;
|
||||
~QmlJSQuickFixAssistProvider() override = default;
|
||||
|
||||
IAssistProvider::RunType runType() const override;
|
||||
TextEditor::IAssistProcessor *createProcessor(const TextEditor::AssistInterface *) const override;
|
||||
};
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ add_qtc_plugin(TextEditor
|
||||
codeassist/assistinterface.cpp codeassist/assistinterface.h
|
||||
codeassist/assistproposalitem.cpp codeassist/assistproposalitem.h
|
||||
codeassist/assistproposaliteminterface.h
|
||||
codeassist/asyncprocessor.cpp codeassist/asyncprocessor.h
|
||||
codeassist/codeassistant.cpp codeassist/codeassistant.h
|
||||
codeassist/completionassistprovider.cpp codeassist/completionassistprovider.h
|
||||
codeassist/documentcontentcompletion.cpp codeassist/documentcontentcompletion.h
|
||||
@@ -37,7 +38,6 @@ add_qtc_plugin(TextEditor
|
||||
codeassist/iassistprovider.cpp codeassist/iassistprovider.h
|
||||
codeassist/ifunctionhintproposalmodel.cpp codeassist/ifunctionhintproposalmodel.h
|
||||
codeassist/keywordscompletionassist.cpp codeassist/keywordscompletionassist.h
|
||||
codeassist/runner.cpp codeassist/runner.h
|
||||
codeassist/textdocumentmanipulator.cpp codeassist/textdocumentmanipulator.h
|
||||
codeassist/textdocumentmanipulatorinterface.h
|
||||
codecchooser.cpp codecchooser.h
|
||||
|
||||
@@ -63,7 +63,7 @@ private:
|
||||
class ClipboardAssistProcessor: public IAssistProcessor
|
||||
{
|
||||
public:
|
||||
IAssistProposal *perform(const AssistInterface *interface) override
|
||||
IAssistProposal *perform(AssistInterface *interface) override
|
||||
{
|
||||
if (!interface)
|
||||
return nullptr;
|
||||
@@ -86,11 +86,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
IAssistProvider::RunType ClipboardAssistProvider::runType() const
|
||||
{
|
||||
return Synchronous;
|
||||
}
|
||||
|
||||
IAssistProcessor *ClipboardAssistProvider::createProcessor(const AssistInterface *) const
|
||||
{
|
||||
return new ClipboardAssistProcessor;
|
||||
|
||||
@@ -13,7 +13,6 @@ class ClipboardAssistProvider: public IAssistProvider
|
||||
{
|
||||
public:
|
||||
ClipboardAssistProvider(QObject *parent = nullptr) : IAssistProvider(parent) {}
|
||||
IAssistProvider::RunType runType() const override;
|
||||
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
||||
};
|
||||
|
||||
|
||||
58
src/plugins/texteditor/codeassist/asyncprocessor.cpp
Normal file
58
src/plugins/texteditor/codeassist/asyncprocessor.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "asyncprocessor.h"
|
||||
|
||||
#include "assistinterface.h"
|
||||
#include "iassistproposal.h"
|
||||
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
AsyncProcessor::AsyncProcessor()
|
||||
{
|
||||
QObject::connect(&m_watcher, &QFutureWatcher<IAssistProposal *>::finished, [this]() {
|
||||
setAsyncProposalAvailable(m_watcher.result());
|
||||
});
|
||||
}
|
||||
|
||||
IAssistProposal *AsyncProcessor::perform(AssistInterface *interface)
|
||||
{
|
||||
IAssistProposal *result = immediateProposal(interface);
|
||||
m_interface = interface;
|
||||
m_interface->prepareForAsyncUse();
|
||||
m_watcher.setFuture(Utils::runAsync([this]() {
|
||||
m_interface->recreateTextDocument();
|
||||
return performAsync(m_interface);
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
|
||||
bool AsyncProcessor::running()
|
||||
{
|
||||
return m_watcher.isRunning();
|
||||
}
|
||||
|
||||
void AsyncProcessor::cancel()
|
||||
{
|
||||
setAsyncCompletionAvailableHandler([this](IAssistProposal *proposal){
|
||||
delete proposal;
|
||||
QMetaObject::invokeMethod(QCoreApplication::instance(), [this] {
|
||||
delete this;
|
||||
}, Qt::QueuedConnection);
|
||||
});
|
||||
}
|
||||
|
||||
IAssistProposal *AsyncProcessor::immediateProposal(AssistInterface *interface)
|
||||
{
|
||||
Q_UNUSED(interface)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool AsyncProcessor::isCanceled() const
|
||||
{
|
||||
return m_watcher.isCanceled();
|
||||
}
|
||||
|
||||
} // namespace TextEditor
|
||||
32
src/plugins/texteditor/codeassist/asyncprocessor.h
Normal file
32
src/plugins/texteditor/codeassist/asyncprocessor.h
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "iassistprocessor.h"
|
||||
|
||||
#include <QFutureWatcher>
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
class TEXTEDITOR_EXPORT AsyncProcessor : public TextEditor::IAssistProcessor
|
||||
{
|
||||
public:
|
||||
AsyncProcessor();
|
||||
|
||||
IAssistProposal *perform(AssistInterface *interface) final;
|
||||
bool running() override;
|
||||
void cancel() override;
|
||||
|
||||
virtual IAssistProposal *performAsync(AssistInterface *interface) = 0;
|
||||
virtual IAssistProposal *immediateProposal(AssistInterface *interface);
|
||||
|
||||
protected:
|
||||
bool isCanceled() const;
|
||||
|
||||
private:
|
||||
AssistInterface *m_interface = nullptr;
|
||||
QFutureWatcher<IAssistProposal *> m_watcher;
|
||||
};
|
||||
|
||||
} // namespace TextEditor
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "iassistproposalwidget.h"
|
||||
#include "assistinterface.h"
|
||||
#include "assistproposalitem.h"
|
||||
#include "runner.h"
|
||||
#include "textdocumentmanipulator.h"
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
@@ -81,10 +80,9 @@ private:
|
||||
private:
|
||||
CodeAssistant *q = nullptr;
|
||||
TextEditorWidget *m_editorWidget = nullptr;
|
||||
Internal::ProcessorRunner *m_requestRunner = nullptr;
|
||||
QMetaObject::Connection m_runnerConnection;
|
||||
IAssistProvider *m_requestProvider = nullptr;
|
||||
IAssistProcessor *m_asyncProcessor = nullptr;
|
||||
IAssistProcessor *m_processor = nullptr;
|
||||
AssistKind m_assistKind = TextEditor::Completion;
|
||||
IAssistProposalWidget *m_proposalWidget = nullptr;
|
||||
QScopedPointer<IAssistProposal> m_proposal;
|
||||
@@ -207,39 +205,6 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
|
||||
m_requestProvider = provider;
|
||||
IAssistProcessor *processor = provider->createProcessor(assistInterface);
|
||||
|
||||
switch (provider->runType()) {
|
||||
case IAssistProvider::Synchronous: {
|
||||
if (IAssistProposal *newProposal = processor->perform(assistInterface))
|
||||
displayProposal(newProposal, reason);
|
||||
delete processor;
|
||||
break;
|
||||
}
|
||||
case IAssistProvider::AsynchronousWithThread: {
|
||||
if (IAssistProposal *newProposal = processor->immediateProposal(assistInterface))
|
||||
displayProposal(newProposal, reason);
|
||||
|
||||
m_requestRunner = new ProcessorRunner;
|
||||
m_runnerConnection = connect(m_requestRunner, &ProcessorRunner::finished,
|
||||
this, [this, reason, sender = m_requestRunner] {
|
||||
// Since the request runner is a different thread, there's still a gap in which the
|
||||
// queued signal could be processed after an invalidation of the current request.
|
||||
if (!m_requestRunner || m_requestRunner != sender)
|
||||
return;
|
||||
|
||||
IAssistProposal *proposal = m_requestRunner->proposal();
|
||||
invalidateCurrentRequestData();
|
||||
displayProposal(proposal, reason);
|
||||
emit q->finished();
|
||||
});
|
||||
connect(m_requestRunner, &ProcessorRunner::finished,
|
||||
m_requestRunner, &ProcessorRunner::deleteLater);
|
||||
assistInterface->prepareForAsyncUse();
|
||||
m_requestRunner->setProcessor(processor);
|
||||
m_requestRunner->setAssistInterface(assistInterface);
|
||||
m_requestRunner->start();
|
||||
break;
|
||||
}
|
||||
case IAssistProvider::Asynchronous: {
|
||||
processor->setAsyncCompletionAvailableHandler([this, reason, processor](
|
||||
IAssistProposal *newProposal) {
|
||||
if (!processor->running()) {
|
||||
@@ -248,7 +213,7 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
|
||||
delete processor;
|
||||
}, Qt::QueuedConnection);
|
||||
}
|
||||
if (processor != m_asyncProcessor)
|
||||
if (processor != m_processor)
|
||||
return;
|
||||
invalidateCurrentRequestData();
|
||||
if (processor->needsRestart() && m_receivedContentWhileWaiting) {
|
||||
@@ -258,41 +223,30 @@ void CodeAssistantPrivate::requestProposal(AssistReason reason,
|
||||
} else {
|
||||
displayProposal(newProposal, reason);
|
||||
if (processor->running())
|
||||
m_asyncProcessor = processor;
|
||||
m_processor = processor;
|
||||
else
|
||||
emit q->finished();
|
||||
}
|
||||
});
|
||||
|
||||
// If there is a proposal, nothing asynchronous happened...
|
||||
if (IAssistProposal *newProposal = processor->perform(assistInterface)) {
|
||||
if (IAssistProposal *newProposal = processor->perform(assistInterface))
|
||||
displayProposal(newProposal, reason);
|
||||
delete processor;
|
||||
} else if (!processor->running()) {
|
||||
if (!processor->running()) {
|
||||
if (isUpdate)
|
||||
destroyContext();
|
||||
delete processor;
|
||||
} else { // ...async request was triggered
|
||||
if (IAssistProposal *newProposal = processor->immediateProposal(assistInterface))
|
||||
displayProposal(newProposal, reason);
|
||||
QTC_CHECK(!m_asyncProcessor);
|
||||
m_asyncProcessor = processor;
|
||||
} else {
|
||||
QTC_CHECK(!m_processor);
|
||||
m_processor = processor;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
} // switch
|
||||
}
|
||||
|
||||
void CodeAssistantPrivate::cancelCurrentRequest()
|
||||
{
|
||||
if (m_requestRunner) {
|
||||
m_requestRunner->setDiscardProposal(true);
|
||||
disconnect(m_runnerConnection);
|
||||
}
|
||||
if (m_asyncProcessor) {
|
||||
m_asyncProcessor->cancel();
|
||||
delete m_asyncProcessor;
|
||||
if (m_processor) {
|
||||
m_processor->cancel();
|
||||
if (!m_processor->running())
|
||||
delete m_processor;
|
||||
}
|
||||
invalidateCurrentRequestData();
|
||||
}
|
||||
@@ -424,7 +378,7 @@ bool CodeAssistantPrivate::isDisplayingProposal() const
|
||||
|
||||
bool CodeAssistantPrivate::isWaitingForProposal() const
|
||||
{
|
||||
return m_requestRunner != nullptr || m_asyncProcessor != nullptr;
|
||||
return m_processor != nullptr;
|
||||
}
|
||||
|
||||
QString CodeAssistantPrivate::proposalPrefix() const
|
||||
@@ -437,8 +391,7 @@ QString CodeAssistantPrivate::proposalPrefix() const
|
||||
|
||||
void CodeAssistantPrivate::invalidateCurrentRequestData()
|
||||
{
|
||||
m_asyncProcessor = nullptr;
|
||||
m_requestRunner = nullptr;
|
||||
m_processor = nullptr;
|
||||
m_requestProvider = nullptr;
|
||||
m_receivedContentWhileWaiting = false;
|
||||
}
|
||||
@@ -492,7 +445,7 @@ void CodeAssistantPrivate::notifyChange()
|
||||
|
||||
bool CodeAssistantPrivate::hasContext() const
|
||||
{
|
||||
return m_requestRunner || m_asyncProcessor || m_proposalWidget;
|
||||
return m_processor || m_proposalWidget;
|
||||
}
|
||||
|
||||
void CodeAssistantPrivate::destroyContext()
|
||||
|
||||
@@ -13,11 +13,6 @@ CompletionAssistProvider::CompletionAssistProvider(QObject *parent)
|
||||
|
||||
CompletionAssistProvider::~CompletionAssistProvider() = default;
|
||||
|
||||
IAssistProvider::RunType CompletionAssistProvider::runType() const
|
||||
{
|
||||
return AsynchronousWithThread;
|
||||
}
|
||||
|
||||
int CompletionAssistProvider::activationCharSequenceLength() const
|
||||
{
|
||||
return 0;
|
||||
|
||||
@@ -16,7 +16,6 @@ public:
|
||||
CompletionAssistProvider(QObject *parent = nullptr);
|
||||
~CompletionAssistProvider() override;
|
||||
|
||||
IAssistProvider::RunType runType() const override;
|
||||
virtual int activationCharSequenceLength() const;
|
||||
virtual bool isActivationCharSequence(const QString &sequence) const;
|
||||
virtual bool isContinuationChar(const QChar &c) const;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
#include "assistinterface.h"
|
||||
#include "assistproposalitem.h"
|
||||
#include "asyncprocessor.h"
|
||||
#include "genericproposal.h"
|
||||
#include "genericproposalmodel.h"
|
||||
#include "iassistprocessor.h"
|
||||
#include "../snippets/snippetassistcollector.h"
|
||||
#include "../completionsettings.h"
|
||||
@@ -23,30 +23,22 @@
|
||||
|
||||
using namespace TextEditor;
|
||||
|
||||
class DocumentContentCompletionProcessor final : public IAssistProcessor
|
||||
class DocumentContentCompletionProcessor final : public AsyncProcessor
|
||||
{
|
||||
public:
|
||||
DocumentContentCompletionProcessor(const QString &snippetGroupId);
|
||||
~DocumentContentCompletionProcessor() final;
|
||||
|
||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
||||
bool running() final { return m_watcher.isRunning(); }
|
||||
void cancel() final;
|
||||
IAssistProposal *performAsync(AssistInterface *interface) override;
|
||||
|
||||
private:
|
||||
QString m_snippetGroup;
|
||||
QFutureWatcher<QStringList> m_watcher;
|
||||
};
|
||||
|
||||
DocumentContentCompletionProvider::DocumentContentCompletionProvider(const QString &snippetGroup)
|
||||
: m_snippetGroup(snippetGroup)
|
||||
{ }
|
||||
|
||||
IAssistProvider::RunType DocumentContentCompletionProvider::runType() const
|
||||
{
|
||||
return Asynchronous;
|
||||
}
|
||||
|
||||
IAssistProcessor *DocumentContentCompletionProvider::createProcessor(const AssistInterface *) const
|
||||
{
|
||||
return new DocumentContentCompletionProcessor(m_snippetGroup);
|
||||
@@ -61,38 +53,9 @@ DocumentContentCompletionProcessor::~DocumentContentCompletionProcessor()
|
||||
cancel();
|
||||
}
|
||||
|
||||
static void createProposal(QFutureInterface<QStringList> &future, const QString &text,
|
||||
const QString &wordUnderCursor)
|
||||
IAssistProposal *DocumentContentCompletionProcessor::performAsync(AssistInterface *interface)
|
||||
{
|
||||
const QRegularExpression wordRE("([\\p{L}_][\\p{L}0-9_]{2,})");
|
||||
|
||||
QSet<QString> words;
|
||||
QRegularExpressionMatchIterator it = wordRE.globalMatch(text);
|
||||
int wordUnderCursorFound = 0;
|
||||
while (it.hasNext()) {
|
||||
if (future.isCanceled())
|
||||
return;
|
||||
QRegularExpressionMatch match = it.next();
|
||||
const QString &word = match.captured();
|
||||
if (word == wordUnderCursor) {
|
||||
// Only add the word under cursor if it
|
||||
// already appears elsewhere in the text
|
||||
if (++wordUnderCursorFound < 2)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!words.contains(word))
|
||||
words.insert(word);
|
||||
}
|
||||
|
||||
future.reportResult(Utils::toList(words));
|
||||
}
|
||||
|
||||
IAssistProposal *DocumentContentCompletionProcessor::perform(const AssistInterface *interface)
|
||||
{
|
||||
QScopedPointer<const AssistInterface> assistInterface(interface);
|
||||
if (running())
|
||||
return nullptr;
|
||||
QScopedPointer<AssistInterface> interfaceDeleter(interface);
|
||||
|
||||
int pos = interface->position();
|
||||
|
||||
@@ -113,27 +76,36 @@ IAssistProposal *DocumentContentCompletionProcessor::perform(const AssistInterfa
|
||||
}
|
||||
}
|
||||
|
||||
const QString wordUnderCursor = interface->textAt(pos, length);
|
||||
const QString text = interface->textDocument()->toPlainText();
|
||||
|
||||
m_watcher.setFuture(Utils::runAsync(&createProposal, text, wordUnderCursor));
|
||||
QObject::connect(&m_watcher, &QFutureWatcher<QStringList>::resultReadyAt,
|
||||
&m_watcher, [this, pos](int index){
|
||||
const TextEditor::SnippetAssistCollector snippetCollector(
|
||||
m_snippetGroup, QIcon(":/texteditor/images/snippet.png"));
|
||||
QList<AssistProposalItemInterface *> items = snippetCollector.collect();
|
||||
for (const QString &word : m_watcher.resultAt(index)) {
|
||||
|
||||
const QString wordUnderCursor = interface->textAt(pos, length);
|
||||
const QString text = interface->textDocument()->toPlainText();
|
||||
|
||||
const QRegularExpression wordRE("([\\p{L}_][\\p{L}0-9_]{2,})");
|
||||
QSet<QString> words;
|
||||
QRegularExpressionMatchIterator it = wordRE.globalMatch(text);
|
||||
int wordUnderCursorFound = 0;
|
||||
while (it.hasNext()) {
|
||||
if (isCanceled())
|
||||
return nullptr;
|
||||
QRegularExpressionMatch match = it.next();
|
||||
const QString &word = match.captured();
|
||||
if (word == wordUnderCursor) {
|
||||
// Only add the word under cursor if it
|
||||
// already appears elsewhere in the text
|
||||
if (++wordUnderCursorFound < 2)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!words.contains(word)) {
|
||||
auto item = new AssistProposalItem();
|
||||
item->setText(word);
|
||||
items.append(item);
|
||||
words.insert(word);
|
||||
}
|
||||
setAsyncProposalAvailable(new GenericProposal(pos, items));
|
||||
});
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void DocumentContentCompletionProcessor::cancel()
|
||||
{
|
||||
if (running())
|
||||
m_watcher.cancel();
|
||||
return new GenericProposal(pos, items);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ public:
|
||||
DocumentContentCompletionProvider(
|
||||
const QString &snippetGroup = QString(Constants::TEXT_SNIPPET_GROUP_ID));
|
||||
|
||||
RunType runType() const override;
|
||||
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -18,8 +18,7 @@ public:
|
||||
IAssistProcessor();
|
||||
virtual ~IAssistProcessor();
|
||||
|
||||
virtual IAssistProposal *immediateProposal(const AssistInterface *) { return nullptr; }
|
||||
virtual IAssistProposal *perform(const AssistInterface *interface) = 0; // takes ownership
|
||||
virtual IAssistProposal *perform(AssistInterface *interface) = 0; // takes ownership
|
||||
|
||||
void setAsyncProposalAvailable(IAssistProposal *proposal);
|
||||
|
||||
|
||||
@@ -18,14 +18,6 @@ class TEXTEDITOR_EXPORT IAssistProvider : public QObject
|
||||
|
||||
public:
|
||||
IAssistProvider(QObject *parent = nullptr) : QObject(parent) {}
|
||||
|
||||
enum RunType {
|
||||
Synchronous,
|
||||
Asynchronous,
|
||||
AsynchronousWithThread
|
||||
};
|
||||
|
||||
virtual RunType runType() const = 0;
|
||||
virtual IAssistProcessor *createProcessor(const AssistInterface *assistInterface) const = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ KeywordsCompletionAssistProcessor::KeywordsCompletionAssistProcessor(const Keywo
|
||||
, m_keywords(keywords)
|
||||
{}
|
||||
|
||||
IAssistProposal *KeywordsCompletionAssistProcessor::perform(const AssistInterface *interface)
|
||||
IAssistProposal *KeywordsCompletionAssistProcessor::performAsync(AssistInterface *interface)
|
||||
{
|
||||
QScopedPointer<const AssistInterface> assistInterface(interface);
|
||||
if (isInComment(interface))
|
||||
@@ -257,11 +257,6 @@ void KeywordsCompletionAssistProvider::setDynamicCompletionFunction(
|
||||
m_completionFunc = func;
|
||||
}
|
||||
|
||||
IAssistProvider::RunType KeywordsCompletionAssistProvider::runType() const
|
||||
{
|
||||
return Synchronous;
|
||||
}
|
||||
|
||||
IAssistProcessor *KeywordsCompletionAssistProvider::createProcessor(const AssistInterface *) const
|
||||
{
|
||||
auto processor = new KeywordsCompletionAssistProcessor(m_keyWords);
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "iassistprocessor.h"
|
||||
#include "assistproposalitem.h"
|
||||
#include "ifunctionhintproposalmodel.h"
|
||||
#include "asyncprocessor.h"
|
||||
#include "completionassistprovider.h"
|
||||
#include "ifunctionhintproposalmodel.h"
|
||||
#include "../snippets/snippetassistcollector.h"
|
||||
|
||||
#include "texteditor/texteditorconstants.h"
|
||||
@@ -71,8 +71,6 @@ public:
|
||||
|
||||
void setDynamicCompletionFunction(const DynamicCompletionFunction &func);
|
||||
|
||||
// IAssistProvider interface
|
||||
RunType runType() const override;
|
||||
IAssistProcessor *createProcessor(const AssistInterface *) const override;
|
||||
|
||||
private:
|
||||
@@ -81,13 +79,13 @@ private:
|
||||
DynamicCompletionFunction m_completionFunc;
|
||||
};
|
||||
|
||||
class TEXTEDITOR_EXPORT KeywordsCompletionAssistProcessor : public IAssistProcessor
|
||||
class TEXTEDITOR_EXPORT KeywordsCompletionAssistProcessor : public AsyncProcessor
|
||||
{
|
||||
public:
|
||||
KeywordsCompletionAssistProcessor(const Keywords &keywords);
|
||||
~KeywordsCompletionAssistProcessor() override = default;
|
||||
|
||||
IAssistProposal *perform(const AssistInterface *interface) override;
|
||||
IAssistProposal *performAsync(AssistInterface *interface) override;
|
||||
|
||||
void setSnippetGroup(const QString &id);
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "runner.h"
|
||||
#include "iassistprocessor.h"
|
||||
#include "iassistproposal.h"
|
||||
#include "assistinterface.h"
|
||||
#include "iassistproposalmodel.h"
|
||||
|
||||
using namespace TextEditor;
|
||||
using namespace Internal;
|
||||
|
||||
ProcessorRunner::ProcessorRunner() = default;
|
||||
|
||||
ProcessorRunner::~ProcessorRunner()
|
||||
{
|
||||
delete m_processor;
|
||||
if (m_discardProposal && m_proposal)
|
||||
delete m_proposal;
|
||||
}
|
||||
|
||||
void ProcessorRunner::setProcessor(IAssistProcessor *computer)
|
||||
{
|
||||
m_processor = computer;
|
||||
}
|
||||
|
||||
void ProcessorRunner::run()
|
||||
{
|
||||
m_interface->recreateTextDocument();
|
||||
m_proposal = m_processor->perform(m_interface);
|
||||
}
|
||||
|
||||
IAssistProposal *ProcessorRunner::proposal() const
|
||||
{
|
||||
return m_proposal;
|
||||
}
|
||||
|
||||
void ProcessorRunner::setDiscardProposal(bool discard)
|
||||
{
|
||||
m_discardProposal = discard;
|
||||
}
|
||||
|
||||
void ProcessorRunner::setAssistInterface(AssistInterface *interface)
|
||||
{
|
||||
m_interface = interface;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "iassistproposalwidget.h"
|
||||
|
||||
#include <QThread>
|
||||
|
||||
namespace TextEditor {
|
||||
|
||||
class IAssistProcessor;
|
||||
class IAssistProposal;
|
||||
class AssistInterface;
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class ProcessorRunner : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ProcessorRunner();
|
||||
~ProcessorRunner() override;
|
||||
|
||||
void setProcessor(IAssistProcessor *processor); // Takes ownership of the processor.
|
||||
void setAssistInterface(AssistInterface *interface);
|
||||
void setDiscardProposal(bool discard);
|
||||
|
||||
void run() override;
|
||||
|
||||
IAssistProposal *proposal() const;
|
||||
|
||||
private:
|
||||
IAssistProcessor *m_processor = nullptr;
|
||||
AssistInterface *m_interface = nullptr;
|
||||
bool m_discardProposal = false;
|
||||
IAssistProposal *m_proposal = nullptr;
|
||||
AssistReason m_reason = IdleEditor;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
} // TextEditor
|
||||
@@ -156,6 +156,8 @@ Project {
|
||||
"assistproposalitem.cpp",
|
||||
"assistproposalitem.h",
|
||||
"assistproposaliteminterface.h",
|
||||
"asyncprocessor.cpp",
|
||||
"asyncprocessor.h",
|
||||
"codeassistant.cpp",
|
||||
"codeassistant.h",
|
||||
"completionassistprovider.cpp",
|
||||
@@ -186,8 +188,6 @@ Project {
|
||||
"ifunctionhintproposalmodel.h",
|
||||
"keywordscompletionassist.cpp",
|
||||
"keywordscompletionassist.h",
|
||||
"runner.cpp",
|
||||
"runner.h",
|
||||
"textdocumentmanipulator.cpp",
|
||||
"textdocumentmanipulator.h",
|
||||
"textdocumentmanipulatorinterface.h",
|
||||
|
||||
Reference in New Issue
Block a user